Search in sources :

Example 1 with LabeledIntList

use of com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList in project gax-java by googleapis.

the class BatchTest method testBatchElementCounter.

@Test
public void testBatchElementCounter() {
    ElementCounter<Batch<LabeledIntList, List<Integer>>> counter = new BatchElementCounter<>(SQUARER_BATCHING_DESC);
    LabeledIntList request = new LabeledIntList("lable", 3);
    Batch<LabeledIntList, List<Integer>> batch = createBatch(request);
    Truth.assertThat(counter.count(batch)).isEqualTo(1);
}
Also used : LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) ArrayList(java.util.ArrayList) List(java.util.List) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) BatchElementCounter(com.google.api.gax.rpc.Batch.BatchElementCounter) Test(org.junit.Test)

Example 2 with LabeledIntList

use of com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList in project gax-java by googleapis.

the class BatchTest method testBatchByteCounter.

@Test
public void testBatchByteCounter() {
    ElementCounter<Batch<LabeledIntList, List<Integer>>> counter = new BatchByteCounter<>();
    LabeledIntList request = new LabeledIntList("lable", 3);
    Batch<LabeledIntList, List<Integer>> batch = createBatch(request);
    Truth.assertThat(counter.count(batch)).isEqualTo(3);
}
Also used : BatchByteCounter(com.google.api.gax.rpc.Batch.BatchByteCounter) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) ArrayList(java.util.ArrayList) List(java.util.List) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) Test(org.junit.Test)

Example 3 with LabeledIntList

use of com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList in project gax-java by googleapis.

the class BatchTest method testConstructor.

@Test
public void testConstructor() {
    LabeledIntList request = new LabeledIntList("lable", 2);
    Batch<LabeledIntList, List<Integer>> batch = createBatch(request);
    Truth.assertThat(batch.getRequest()).isEqualTo(request);
    Truth.assertThat(batch.getCallable()).isSameInstanceAs(batch.getCallable());
    Truth.assertThat(batch.getRequestIssuerList().size()).isEqualTo(1);
    Truth.assertThat(batch.getByteCount()).isEqualTo(2);
}
Also used : LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) ArrayList(java.util.ArrayList) List(java.util.List) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) Test(org.junit.Test)

Example 4 with LabeledIntList

use of com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList in project gax-java by googleapis.

the class BatchTest method testMerge.

@Test
public void testMerge() {
    LabeledIntList request1 = new LabeledIntList("lable", 1);
    Batch<LabeledIntList, List<Integer>> batch1 = createBatch(request1);
    LabeledIntList request2 = new LabeledIntList("lable", 2);
    Batch<LabeledIntList, List<Integer>> batch2 = createBatch(request2);
    batch1.merge(batch2);
    Truth.assertThat(batch1.getByteCount()).isEqualTo(3);
}
Also used : LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) ArrayList(java.util.ArrayList) List(java.util.List) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) Test(org.junit.Test)

Example 5 with LabeledIntList

use of com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList 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)

Aggregations

LabeledIntList (com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList)27 List (java.util.List)27 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)16 ImmutableList (com.google.common.collect.ImmutableList)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 BatchingSettings (com.google.api.gax.batching.BatchingSettings)8 FlowControlRuntimeException (com.google.api.gax.batching.FlowController.FlowControlRuntimeException)6 ExecutionException (java.util.concurrent.ExecutionException)6 TimeoutException (java.util.concurrent.TimeoutException)6 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)5 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)4 SquarerBatchingDescriptorV2 (com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptorV2)4 FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)3 FlowController (com.google.api.gax.batching.FlowController)3 RetrySettings (com.google.api.gax.retrying.RetrySettings)3 SquarerBatchingDescriptor (com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptor)3 StatusCode (com.google.api.gax.rpc.StatusCode)2 LabeledIntSquarerCallable (com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntSquarerCallable)2 ExecutorService (java.util.concurrent.ExecutorService)2