use of com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptor in project gax-java by googleapis.
the class BatcherFactoryTest method testGetPushingBatcher.
@Test
public void testGetPushingBatcher() {
BatchingSettings batchingSettings = BatchingSettings.newBuilder().setDelayThreshold(Duration.ofSeconds(1)).setElementCountThreshold(2L).setRequestByteThreshold(1000L).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);
Truth.assertThat(batcherFactory.getBatchingSettings()).isSameInstanceAs(batchingSettings);
ThresholdBatcher<Batch<LabeledIntList, List<Integer>>> batcherFoo = batcherFactory.getPushingBatcher(new PartitionKey("foo"));
ThresholdBatcher<Batch<LabeledIntList, List<Integer>>> batcherFoo2 = batcherFactory.getPushingBatcher(new PartitionKey("foo"));
ThresholdBatcher<Batch<LabeledIntList, List<Integer>>> batcherBar = batcherFactory.getPushingBatcher(new PartitionKey("bar"));
Truth.assertThat(batcherFoo).isSameInstanceAs(batcherFoo2);
Truth.assertThat(batcherFoo).isNotSameInstanceAs(batcherBar);
}
use of com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptor in project gax-java by googleapis.
the class BatchingCallableTest method testUnbatchedCall.
@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);
}
use of com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptor in project gax-java by googleapis.
the class BatchingCallableTest method testBatchedCall.
@Test
public void testBatchedCall() throws Exception {
BatchingSettings batchingSettings = BatchingSettings.newBuilder().setDelayThreshold(Duration.ofSeconds(10)).setElementCountThreshold(2L).setRequestByteThreshold(1000L).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());
// Assume it won't take 10 seconds (the batching delay threshold) to check the first future
Truth.assertThat(future1.isDone()).isFalse();
LabeledIntList request2 = new LabeledIntList("label", 3);
ApiFuture<List<Integer>> future2 = batchingCallable.futureCall(request2, FakeCallContext.createDefault());
List<Integer> response1 = future1.get();
List<Integer> response2 = future2.get();
Truth.assertThat(response1.size()).isEqualTo(1);
Truth.assertThat(response1.get(0)).isEqualTo(2 * 2);
Truth.assertThat(response2.size()).isEqualTo(1);
Truth.assertThat(response2.get(0)).isEqualTo(3 * 3);
}
Aggregations