Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

fix: fix dynamic flow control setting checks #1347

Merged
merged 2 commits into from Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
Expand Up @@ -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 =
Expand Down