Skip to content

Commit

Permalink
fix: if a flow control setting is not provided use zero (#292)
Browse files Browse the repository at this point in the history
* fix: use default zero value if a flow control setting is not provided

* fix lint issues
  • Loading branch information
hannahrogers-google committed Jul 24, 2020
1 parent f54ed02 commit d56155b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Expand Up @@ -216,8 +216,10 @@ private void initialize() {
.setSubscription(subscription)
.setStreamAckDeadlineSeconds(60)
.setClientId(clientId)
.setMaxOutstandingMessages(flowControlSettings.getMaxOutstandingElementCount())
.setMaxOutstandingBytes(flowControlSettings.getMaxOutstandingRequestBytes())
.setMaxOutstandingMessages(
valueOrZero(flowControlSettings.getMaxOutstandingElementCount()))
.setMaxOutstandingBytes(
valueOrZero(flowControlSettings.getMaxOutstandingRequestBytes()))
.build());

/**
Expand Down Expand Up @@ -281,6 +283,10 @@ public void run() {
MoreExecutors.directExecutor());
}

private Long valueOrZero(Long value) {
return value != null ? value : 0;
}

private boolean isAlive() {
State state = state(); // Read the state only once.
return state == State.RUNNING || state == State.STARTING;
Expand Down
Expand Up @@ -19,6 +19,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.google.api.gax.batching.FlowControlSettings;
import com.google.api.gax.core.ExecutorProvider;
import com.google.api.gax.core.FixedExecutorProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
Expand Down Expand Up @@ -238,6 +239,8 @@ private Builder getTestSubscriberBuilder(MessageReceiver receiver) {
.setCredentialsProvider(NoCredentialsProvider.create())
.setClock(fakeExecutor.getClock())
.setParallelPullCount(1)
.setMaxDurationPerAckExtension(Duration.ofSeconds(5));
.setMaxDurationPerAckExtension(Duration.ofSeconds(5))
.setFlowControlSettings(
FlowControlSettings.newBuilder().setMaxOutstandingElementCount(1000L).build());
}
}

0 comments on commit d56155b

Please sign in to comment.