Skip to content
Permalink
Browse files
fix: fix dynamic flow control setting checks (#1347)
* fix: fix dynamic flow control setting checks

* make checks more readable
  • Loading branch information
mutianf committed Apr 21, 2021
1 parent 06dbf12 commit 69458b4deefe5b9c2c33a3b51389face968ff52f
@@ -115,11 +115,14 @@ public DynamicFlowControlSettings build() {
}

private void verifyElementCountSettings(DynamicFlowControlSettings settings) {
boolean isEnabled =
settings.getInitialOutstandingElementCount() != null
|| settings.getMinOutstandingElementCount() != null
|| settings.getMaxOutstandingElementCount() != null;
if (!isEnabled) {
// If LimitExceededBehavior is Ignore, dynamic flow control is disabled, there's no need to
// check element count limit settings
if (settings.getLimitExceededBehavior() == LimitExceededBehavior.Ignore) {
return;
}
if (settings.getInitialOutstandingElementCount() == null
&& settings.getMinOutstandingElementCount() == null
&& settings.getMaxOutstandingElementCount() == null) {
return;
}
Preconditions.checkState(
@@ -141,11 +144,14 @@ private void verifyElementCountSettings(DynamicFlowControlSettings settings) {
}

private void verifyRequestBytesSettings(DynamicFlowControlSettings settings) {
boolean isEnabled =
settings.getInitialOutstandingRequestBytes() != null
|| settings.getMinOutstandingRequestBytes() != null
|| settings.getMaxOutstandingRequestBytes() != null;
if (!isEnabled) {
// If LimitExceededBehavior is Ignore, dynamic flow control is disabled, there's no need to
// check request bytes limit settings
if (settings.getLimitExceededBehavior() == LimitExceededBehavior.Ignore) {
return;
}
if (settings.getInitialOutstandingRequestBytes() == null
&& settings.getMinOutstandingRequestBytes() == null
&& settings.getMaxOutstandingRequestBytes() == null) {
return;
}
Preconditions.checkState(
@@ -55,6 +55,22 @@ public void testEmptyBuilder() {
assertEquals(LimitExceededBehavior.Block, settings.getLimitExceededBehavior());
}

@Test
public void testPartialSettingsIgnored() {
// If behavior is ignore, build shouldn't throw exceptions even when only one of the bytes or
// element limits is set
DynamicFlowControlSettings.Builder builder =
DynamicFlowControlSettings.newBuilder()
.setLimitExceededBehavior(LimitExceededBehavior.Ignore)
.setMaxOutstandingElementCount(1L);
builder.build();
builder =
DynamicFlowControlSettings.newBuilder()
.setLimitExceededBehavior(LimitExceededBehavior.Ignore)
.setMinOutstandingRequestBytes(1L);
builder.build();
}

@Test
public void testBuilder() {
DynamicFlowControlSettings.Builder builder =

0 comments on commit 69458b4

Please sign in to comment.