Search in sources :

Example 1 with SquarerBatchingDescriptor

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);
}
Also used : FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) SquarerBatchingDescriptor(com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptor) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) PartitionKey(com.google.api.gax.batching.PartitionKey) List(java.util.List) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) FlowController(com.google.api.gax.batching.FlowController) BatchingSettings(com.google.api.gax.batching.BatchingSettings) Test(org.junit.Test)

Example 2 with SquarerBatchingDescriptor

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);
}
Also used : FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) SquarerBatchingDescriptor(com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptor) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) List(java.util.List) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) FlowController(com.google.api.gax.batching.FlowController) BatchingSettings(com.google.api.gax.batching.BatchingSettings) Test(org.junit.Test)

Example 3 with SquarerBatchingDescriptor

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);
}
Also used : FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) SquarerBatchingDescriptor(com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptor) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) List(java.util.List) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) FlowController(com.google.api.gax.batching.FlowController) BatchingSettings(com.google.api.gax.batching.BatchingSettings) Test(org.junit.Test)

Aggregations

BatchingSettings (com.google.api.gax.batching.BatchingSettings)3 FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)3 FlowController (com.google.api.gax.batching.FlowController)3 LabeledIntList (com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList)3 SquarerBatchingDescriptor (com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptor)3 List (java.util.List)3 Test (org.junit.Test)3 PartitionKey (com.google.api.gax.batching.PartitionKey)1