Search in sources :

Example 26 with LabeledIntList

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

the class BatchingCallSettingsTest method testBuilderFromSettings.

@Test
public void testBuilderFromSettings() {
    BatchingCallSettings.Builder<Integer, Integer, LabeledIntList, List<Integer>> builder = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC_V2);
    RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build();
    builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED).setRetrySettings(retrySettings);
    BatchingCallSettings settings = builder.build();
    BatchingCallSettings.Builder newBuilder = settings.toBuilder();
    assertThat(newBuilder.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
    assertThat(newBuilder.getRetryableCodes()).containsExactly(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED);
    assertThat(newBuilder.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) Test(org.junit.Test)

Example 27 with LabeledIntList

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

the class BatcherImplTest method testCloseAsyncNonblocking.

@Test
public void testCloseAsyncNonblocking() throws ExecutionException, InterruptedException {
    final SettableApiFuture<List<Integer>> innerFuture = SettableApiFuture.create();
    UnaryCallable<LabeledIntList, List<Integer>> unaryCallable = new UnaryCallable<LabeledIntList, List<Integer>>() {

        @Override
        public ApiFuture<List<Integer>> futureCall(LabeledIntList request, ApiCallContext context) {
            return innerFuture;
        }
    };
    underTest = new BatcherImpl<>(SQUARER_BATCHING_DESC_V2, unaryCallable, labeledIntList, batchingSettings, EXECUTOR);
    ApiFuture<Integer> elementFuture = underTest.add(1);
    Stopwatch stopwatch = Stopwatch.createStarted();
    ApiFuture<Void> closeFuture = underTest.closeAsync();
    assertThat(stopwatch.elapsed(TimeUnit.MILLISECONDS)).isAtMost(100);
    assertThat(closeFuture.isDone()).isFalse();
    assertThat(elementFuture.isDone()).isFalse();
    innerFuture.set(ImmutableList.of(1));
    closeFuture.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LabeledIntList(com.google.api.gax.rpc.testing.FakeBatchableApi.LabeledIntList) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Stopwatch(com.google.common.base.Stopwatch) 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)

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