static <RequestT, ResponseT, MetadataT> OperationCallableImpl<RequestT, ResponseT, MetadataT> longRunningOperationImpl( UnaryCallable<RequestT, OperationSnapshot> initialCallable, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, LongRunningClient longRunningClient) { RetryAlgorithm<OperationSnapshot> pollingAlgorithm = new RetryAlgorithm<>( new OperationResponsePollAlgorithm(), operationCallSettings.getPollingAlgorithm()); ScheduledRetryingExecutor<OperationSnapshot> scheduler = new ScheduledRetryingExecutor<>(pollingAlgorithm, clientContext.getExecutor()); return new OperationCallableImpl<>( initialCallable, scheduler, longRunningClient, operationCallSettings); } }
static <RequestT, ResponseT, MetadataT> OperationCallableImpl<RequestT, ResponseT, MetadataT> longRunningOperationImpl( UnaryCallable<RequestT, OperationSnapshot> initialCallable, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, LongRunningClient longRunningClient) { RetryAlgorithm<OperationSnapshot> pollingAlgorithm = new RetryAlgorithm<>( new OperationResponsePollAlgorithm(), operationCallSettings.getPollingAlgorithm()); ScheduledRetryingExecutor<OperationSnapshot> scheduler = new ScheduledRetryingExecutor<>(pollingAlgorithm, clientContext.getExecutor()); return new OperationCallableImpl<>( initialCallable, scheduler, longRunningClient, operationCallSettings); } }
@Test public void testBuilder() { OperationCallSettings.Builder<Integer, String, Long> builder = OperationCallSettings.newBuilder(); UnaryCallSettings<Integer, OperationSnapshot> initialCallSettings = UnaryCallSettings.<Integer, OperationSnapshot>newUnaryCallSettingsBuilder() .setRetryableCodes(Code.UNAVAILABLE) .build(); TimedRetryAlgorithm pollingAlgorithm = Mockito.mock(TimedRetryAlgorithm.class); ResponseTransformer responseTransformer = new ResponseTransformer(); MetadataTransformer metadataTransformer = new MetadataTransformer(); builder.setPollingAlgorithm(pollingAlgorithm); builder.setResponseTransformer(responseTransformer); builder.setMetadataTransformer(metadataTransformer); builder.setInitialCallSettings(initialCallSettings); Truth.assertThat(builder.getInitialCallSettings()).isSameAs(initialCallSettings); OperationCallSettings settings = builder.build(); Truth.assertThat(settings.getPollingAlgorithm()).isSameAs(pollingAlgorithm); Truth.assertThat(settings.getResponseTransformer()).isSameAs(responseTransformer); Truth.assertThat(settings.getMetadataTransformer()).isSameAs(metadataTransformer); Truth.assertThat(settings.getInitialCallSettings()).isNotNull(); Truth.assertThat(settings.getInitialCallSettings().getRetryableCodes().size()).isEqualTo(1); }