Skip to content
Permalink
Browse files
fix: if a flow control setting is not provided use zero (#292)
* 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 d56155b640d13fa78d28031862aabe4814ce201d
@@ -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());

/**
@@ -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;
@@ -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;
@@ -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.