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

Commit 18f6024

Browse files
committed
make checks more readable
1 parent 8b3a056 commit 18f6024

2 files changed

Lines changed: 25 additions & 18 deletions

File tree

gax/src/main/java/com/google/api/gax/batching/DynamicFlowControlSettings.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ public DynamicFlowControlSettings build() {
115115
}
116116

117117
private void verifyElementCountSettings(DynamicFlowControlSettings settings) {
118-
boolean isEnabled =
119-
settings.getLimitExceededBehavior() != LimitExceededBehavior.Ignore
120-
&& (settings.getInitialOutstandingElementCount() != null
121-
|| settings.getMinOutstandingElementCount() != null
122-
|| settings.getMaxOutstandingElementCount() != null);
123-
if (!isEnabled) {
118+
// If LimitExceededBehavior is Ignore, dynamic flow control is disabled, there's no need to
119+
// check element count limit settings
120+
if (settings.getLimitExceededBehavior() == LimitExceededBehavior.Ignore) {
121+
return;
122+
}
123+
if (settings.getInitialOutstandingElementCount() == null
124+
&& settings.getMinOutstandingElementCount() == null
125+
&& settings.getMaxOutstandingElementCount() == null) {
124126
return;
125127
}
126128
Preconditions.checkState(
@@ -142,12 +144,14 @@ private void verifyElementCountSettings(DynamicFlowControlSettings settings) {
142144
}
143145

144146
private void verifyRequestBytesSettings(DynamicFlowControlSettings settings) {
145-
boolean isEnabled =
146-
settings.getLimitExceededBehavior() != LimitExceededBehavior.Ignore
147-
&& (settings.getInitialOutstandingRequestBytes() != null
148-
|| settings.getMinOutstandingRequestBytes() != null
149-
|| settings.getMaxOutstandingRequestBytes() != null);
150-
if (!isEnabled) {
147+
// If LimitExceededBehavior is Ignore, dynamic flow control is disabled, there's no need to
148+
// check request bytes limit settings
149+
if (settings.getLimitExceededBehavior() == LimitExceededBehavior.Ignore) {
150+
return;
151+
}
152+
if (settings.getInitialOutstandingRequestBytes() == null
153+
&& settings.getMinOutstandingRequestBytes() == null
154+
&& settings.getMaxOutstandingRequestBytes() == null) {
151155
return;
152156
}
153157
Preconditions.checkState(

gax/src/test/java/com/google/api/gax/batching/DynamicFlowControlSettingsTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,18 @@ public void testEmptyBuilder() {
5656
}
5757

5858
@Test
59-
public void testSettingsIgnored() {
60-
DynamicFlowControlSettings.Builder builder = DynamicFlowControlSettings.newBuilder();
59+
public void testPartialSettingsIgnored() {
6160
// If behavior is ignore, build shouldn't throw exceptions even when only one of the bytes or
6261
// element limits is set
63-
builder
64-
.setLimitExceededBehavior(LimitExceededBehavior.Ignore)
65-
.setMaxOutstandingRequestBytes(1L);
62+
DynamicFlowControlSettings.Builder builder =
63+
DynamicFlowControlSettings.newBuilder()
64+
.setLimitExceededBehavior(LimitExceededBehavior.Ignore)
65+
.setMaxOutstandingElementCount(1L);
6666
builder.build();
67-
builder.setMinOutstandingElementCount(1L);
67+
builder =
68+
DynamicFlowControlSettings.newBuilder()
69+
.setLimitExceededBehavior(LimitExceededBehavior.Ignore)
70+
.setMinOutstandingRequestBytes(1L);
6871
builder.build();
6972
}
7073

0 commit comments

Comments
 (0)