Search in sources :

Example 21 with LabeledIntList

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

the class BatchTest method testBatchMergerImpl.

@Test
public void testBatchMergerImpl() {
    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);
    BatchMergerImpl<LabeledIntList, List<Integer>> batchMerger = new BatchMergerImpl<>();
    batchMerger.merge(batch1, batch2);
    Truth.assertThat(batch1.getByteCount()).isEqualTo(3);
}
Also used : BatchMergerImpl(com.google.api.gax.rpc.Batch.BatchMergerImpl) 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 22 with LabeledIntList

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

the class BatchTest method testMergeStartEmpty.

@Test
public void testMergeStartEmpty() {
    LabeledIntList request1 = new LabeledIntList("lable", new ArrayList<Integer>());
    Batch<LabeledIntList, List<Integer>> batch1 = createBatch(request1, null);
    Truth.assertThat(batch1.getCallable()).isNull();
    LabeledIntList request2 = new LabeledIntList("lable", 2);
    Batch<LabeledIntList, List<Integer>> batch2 = createBatch(request2);
    batch1.merge(batch2);
    Truth.assertThat(batch1.getByteCount()).isEqualTo(2);
    Truth.assertThat(batch1.getCallable()).isNotNull();
    Truth.assertThat(batch1.getCallable()).isSameInstanceAs(batch2.getCallable());
}
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 23 with LabeledIntList

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

the class BatcherImplTest method testSendOutstanding.

@Test
public void testSendOutstanding() {
    final AtomicInteger callableCounter = new AtomicInteger();
    underTest = new BatcherImpl<>(SQUARER_BATCHING_DESC_V2, new LabeledIntSquarerCallable() {

        @Override
        public ApiFuture<List<Integer>> futureCall(LabeledIntList request, ApiCallContext context) {
            callableCounter.incrementAndGet();
            return super.futureCall(request, context);
        }
    }, labeledIntList, batchingSettings, EXECUTOR);
    // Empty Batcher
    underTest.sendOutstanding();
    assertThat(callableCounter.get()).isEqualTo(0);
    underTest.add(2);
    underTest.add(3);
    underTest.add(4);
    underTest.sendOutstanding();
    assertThat(callableCounter.get()).isEqualTo(1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LabeledIntSquarerCallable(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntSquarerCallable) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) Test(org.junit.Test)

Example 24 with LabeledIntList

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

the class BatcherImplTest method testPartialFailureWithSplitResponse.

/**
 * To confirm the partial failures in Batching does not mark whole batch failed
 */
@Test
public void testPartialFailureWithSplitResponse() throws Exception {
    SquarerBatchingDescriptorV2 descriptor = new SquarerBatchingDescriptorV2() {

        @Override
        public void splitResponse(List<Integer> batchResponse, List<BatchEntry<Integer, Integer>> batch) {
            for (int i = 0; i < batchResponse.size(); i++) {
                if (batchResponse.get(i) > 10_000) {
                    batch.get(i).getResultFuture().setException(new ArithmeticException());
                } else {
                    batch.get(i).getResultFuture().set(batchResponse.get(i));
                }
            }
        }
    };
    underTest = new BatcherImpl<>(descriptor, callLabeledIntSquarer, labeledIntList, batchingSettings, EXECUTOR);
    underTest.add(10);
    // This will cause partial failure
    underTest.add(200);
    underTest.flush();
    underTest.add(40);
    underTest.add(50);
    underTest.flush();
    // These will cause partial failure
    underTest.add(500);
    underTest.add(600);
    Exception actualError = null;
    try {
        underTest.close();
    } catch (Exception e) {
        actualError = e;
    }
    assertThat(actualError).isInstanceOf(BatchingException.class);
    assertThat(actualError).hasMessageThat().contains("Batching finished with 2 partial failures. The 2 partial failures contained " + "3 entries that failed with: 3 ArithmeticException.");
}
Also used : SquarerBatchingDescriptorV2(com.google.api.gax.rpc.testing.FakeBatchableApi.SquarerBatchingDescriptorV2) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) TimeoutException(java.util.concurrent.TimeoutException) FlowControlRuntimeException(com.google.api.gax.batching.FlowController.FlowControlRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 25 with LabeledIntList

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

the class BatchingCallSettingsTest method testBuilder.

@Test
public void testBuilder() {
    BatchingCallSettings.Builder<Integer, Integer, LabeledIntList, List<Integer>> builder = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC_V2);
    Set<StatusCode.Code> retryCodes = ImmutableSet.of(StatusCode.Code.UNAVAILABLE);
    RetrySettings retrySettings = RetrySettings.newBuilder().build();
    builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(retryCodes).setRetrySettings(retrySettings);
    BatchingCallSettings settings = builder.build();
    assertThat(settings.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
    assertThat(settings.getRetryableCodes()).isEqualTo(retryCodes);
    assertThat(settings.getRetrySettings()).isEqualTo(retrySettings);
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) List(java.util.List) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) StatusCode(com.google.api.gax.rpc.StatusCode) 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