use of com.google.api.gax.batching.PartitionKey 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.batching.PartitionKey in project gax-java by googleapis.
the class BatchExecutorTest method testValidateFailure.
@Test(expected = IllegalArgumentException.class)
public void testValidateFailure() {
BatchExecutor<List<Integer>, Integer> executor = new BatchExecutor<List<Integer>, Integer>(integerDescriptor, new PartitionKey(0));
List<Integer> request = new ArrayList<>();
request.add(3);
Batch<List<Integer>, Integer> batchingContextOk = new Batch<>(integerDescriptor, request, null, null);
executor.validateBatch(batchingContextOk);
}
use of com.google.api.gax.batching.PartitionKey in project gax-java by googleapis.
the class BatchExecutorTest method testValidate.
@Test
public void testValidate() {
BatchExecutor<List<Integer>, Integer> executor = new BatchExecutor<List<Integer>, Integer>(integerDescriptor, new PartitionKey(0));
List<Integer> request = new ArrayList<Integer>();
request.add(2);
Batch<List<Integer>, Integer> batchingContextOk = new Batch<>(integerDescriptor, request, null, null);
executor.validateBatch(batchingContextOk);
}
use of com.google.api.gax.batching.PartitionKey in project gax-java by googleapis.
the class BatchingCallable method futureCall.
@Override
public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext context) {
if (batcherFactory.getBatchingSettings().getIsEnabled()) {
BatchedFuture<ResponseT> result = BatchedFuture.<ResponseT>create();
UnaryCallable<RequestT, ResponseT> unaryCallable = callable.withDefaultCallContext(context);
Batch<RequestT, ResponseT> batchableMessage = new Batch<RequestT, ResponseT>(batchingDescriptor, request, unaryCallable, result);
PartitionKey partitionKey = batchingDescriptor.getBatchPartitionKey(request);
ThresholdBatcher<Batch<RequestT, ResponseT>> batcher = batcherFactory.getPushingBatcher(partitionKey);
try {
batcher.add(batchableMessage);
return result;
} catch (FlowControlException e) {
throw FlowControlRuntimeException.fromFlowControlException(e);
}
} else {
return callable.futureCall(request, context);
}
}
Aggregations