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);
}
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());
}
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);
}
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.");
}
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);
}
Aggregations