.getFlowControlSettings() .toBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Block) .build()) .build());
new FlowController( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(1L) .setLimitExceededBehavior(FlowController.LimitExceededBehavior.ThrowException) .build());
.setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100000L) .setMaxOutstandingRequestBytes(10485760L) .setLimitExceededBehavior(LimitExceededBehavior.ThrowException) .build()) .build()); builder
.getFlowControlSettings() .toBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Block) .build()) .build());
.setFlowControlSettings( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Block) .setMaxOutstandingElementCount(10L) .setMaxOutstandingRequestBytes(10L) .build()) .build(); TrackedFlowController trackedFlowController =
FlowControlSettings flowControlSettings = FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build(); FlowController flowController = new FlowController(flowControlSettings); BatcherFactory<LabeledIntList, List<Integer>> batcherFactory =
.setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100000L) .setMaxOutstandingRequestBytes(10485760L) .setLimitExceededBehavior(LimitExceededBehavior.ThrowException) .build()) .build()); builder
FlowControlSettings flowControlSettings = FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build(); FlowController flowController = new FlowController(flowControlSettings); BatcherFactory<LabeledIntList, List<Integer>> batcherFactory =
private static BatchingFlowController<SimpleBatch> getTrackedIntegerBatchingFlowController( Long elementCount, Long byteCount, LimitExceededBehavior limitExceededBehaviour) { trackedFlowController = new TrackedFlowController( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(elementCount) .setMaxOutstandingRequestBytes(byteCount) .setLimitExceededBehavior(limitExceededBehaviour) .build()); return new BatchingFlowController<>( trackedFlowController, new ElementCounter<SimpleBatch>() { @Override public long count(SimpleBatch t) { return t.getIntegers().size(); } }, new ElementCounter<SimpleBatch>() { @Override public long count(SimpleBatch t) { long counter = 0; for (Integer i : t.integers) { counter += i; } return counter; } }); }
@Test public void testUnbatchedCall() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder().setIsEnabled(false).build(); FlowControlSettings flowControlSettings = FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build(); FlowController flowController = new FlowController(flowControlSettings); BatcherFactory<LabeledIntList, List<Integer>> batcherFactory = new BatcherFactory<>( new SquarerBatchingDescriptor(), batchingSettings, batchingExecutor, flowController); BatchingCallable<LabeledIntList, List<Integer>> batchingCallable = new BatchingCallable<>( FakeBatchableApi.callLabeledIntSquarer, FakeBatchableApi.SQUARER_BATCHING_DESC, batcherFactory); LabeledIntList request1 = new LabeledIntList("label", 2); ApiFuture<List<Integer>> future1 = batchingCallable.futureCall(request1, FakeCallContext.createDefault()); List<Integer> response1 = future1.get(); Truth.assertThat(response1.size()).isEqualTo(1); Truth.assertThat(response1.get(0)).isEqualTo(2 * 2); } }
@Test public void testInvalidArguments() throws Exception { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(10L) .setMaxOutstandingRequestBytes(10L) .setLimitExceededBehavior(LimitExceededBehavior.Block) .build()); flowController.reserve(0, 0); try { flowController.reserve(-1, 1); fail("Must have thrown an illegal argument error"); } catch (IllegalArgumentException expected) { // Expected } try { flowController.reserve(1, -1); fail("Must have thrown an illegal argument error"); } catch (IllegalArgumentException expected) { // Expected } }
@Test public void testRestoreAfterFail() throws FlowController.FlowControlException { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(2L) .setMaxOutstandingRequestBytes(1L) .setLimitExceededBehavior(LimitExceededBehavior.ThrowException) .build()); flowController.reserve(1, 1); try { flowController.reserve(1, 1); throw new IllegalStateException("flowController should not have any bytes left"); } catch (FlowController.MaxOutstandingRequestBytesReachedException e) { // Ignore. } flowController.reserve(1, 0); }
public static FlowControlSettings getDefaultInstance() { return FlowControlSettings.newBuilder().build(); }
public FlowControlSettings build() { FlowControlSettings settings = autoBuild(); Preconditions.checkArgument( settings.getMaxOutstandingElementCount() == null || settings.getMaxOutstandingElementCount() > 0, "maxOutstandingElementCount limit is disabled by default, but if set it must be set to a value greater than 0."); Preconditions.checkArgument( settings.getMaxOutstandingRequestBytes() == null || settings.getMaxOutstandingRequestBytes() > 0, "maxOutstandingRequestBytes limit is disabled by default, but if set it must be set to a value greater than 0."); return settings; } }
public static FlowControlSettings getDefaultInstance() { return FlowControlSettings.newBuilder().build(); }
private static FlowController getDisabledFlowController() { return new FlowController( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build()); }
@Test public void testReserveRelease_rejectedByElementCount_noBytesLimit() throws Exception { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(10L) .setLimitExceededBehavior(LimitExceededBehavior.ThrowException) .build()); testRejectedReserveRelease( flowController, 10, 10, FlowController.MaxOutstandingElementCountReachedException.class); }
public FlowControlSettings build() { FlowControlSettings settings = autoBuild(); Preconditions.checkArgument( settings.getMaxOutstandingElementCount() == null || settings.getMaxOutstandingElementCount() > 0, "maxOutstandingElementCount limit is disabled by default, but if set it must be set to a value greater than 0."); Preconditions.checkArgument( settings.getMaxOutstandingRequestBytes() == null || settings.getMaxOutstandingRequestBytes() > 0, "maxOutstandingRequestBytes limit is disabled by default, but if set it must be set to a value greater than 0."); return settings; } }
private FlowControlSettings buildFlowControlSettings( GcpPubSubProperties.FlowControl flowControl) { FlowControlSettings.Builder builder = FlowControlSettings.newBuilder(); return ifNotNull(flowControl.getLimitExceededBehavior(), builder::setLimitExceededBehavior) .apply(ifNotNull(flowControl.getMaxOutstandingElementCount(), builder::setMaxOutstandingElementCount) .apply(ifNotNull(flowControl.getMaxOutstandingRequestBytes(), builder::setMaxOutstandingRequestBytes) .apply(false))) ? builder.build() : null; }
@Test public void testReserveRelease_noLimits_ok() throws Exception { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Block) .build()); flowController.reserve(1, 1); flowController.release(1, 1); }