private static RetrySettings retrySettings() { return RetrySettings.newBuilder() .setMaxRetryDelay(Duration.ofMillis(30000L)) .setTotalTimeout(Duration.ofMillis(120000L)) .setInitialRetryDelay(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.0) .setInitialRpcTimeout(Duration.ofMillis(120000L)) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(Duration.ofMillis(120000L)) .build(); }
private static RetrySettings retryParams() { return RetrySettings.newBuilder() .setMaxAttempts(10) .setMaxRetryDelay(Duration.ofMillis(30000L)) .setTotalTimeout(Duration.ofMillis(120000L)) .setInitialRetryDelay(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.0) .setInitialRpcTimeout(Duration.ofMillis(120000L)) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(Duration.ofMillis(120000L)) .build(); }
private static RetrySettings retrySettings() { return RetrySettings.newBuilder() .setMaxAttempts(10) .setMaxRetryDelay(Duration.ofMillis(30000L)) .setTotalTimeout(Duration.ofMillis(120000L)) .setInitialRetryDelay(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.0) .setInitialRpcTimeout(Duration.ofMillis(120000L)) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(Duration.ofMillis(120000L)) .build(); }
private static RetrySettings retrySettings() { return RetrySettings.newBuilder() .setMaxAttempts(10) .setMaxRetryDelay(Duration.ofMillis(30000L)) .setTotalTimeout(Duration.ofMillis(120000L)) .setInitialRetryDelay(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.0) .setInitialRpcTimeout(Duration.ofMillis(120000L)) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(Duration.ofMillis(120000L)) .build(); }
private static RetrySettings retrySettings() { return RetrySettings.newBuilder() .setMaxAttempts(10) .setMaxRetryDelay(Duration.ofMillis(30000L)) .setTotalTimeout(Duration.ofMillis(120000L)) .setInitialRetryDelay(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.0) .setInitialRpcTimeout(Duration.ofMillis(120000L)) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(Duration.ofMillis(120000L)) .build(); } }
private static RetrySettings retrySettings() { double retryDelayMultiplier = 1.0; int maxAttempts = 10; long initialRetryDelay = 250L; long maxRetryDelay = 30000L; long totalTimeOut = 120000L; return RetrySettings.newBuilder() .setMaxAttempts(maxAttempts) .setMaxRetryDelay(Duration.ofMillis(maxRetryDelay)) .setTotalTimeout(Duration.ofMillis(totalTimeOut)) .setInitialRetryDelay(Duration.ofMillis(initialRetryDelay)) .setRetryDelayMultiplier(retryDelayMultiplier) .setInitialRpcTimeout(Duration.ofMillis(totalTimeOut)) .setRpcTimeoutMultiplier(retryDelayMultiplier) .setMaxRpcTimeout(Duration.ofMillis(totalTimeOut)) .build(); }
@Override public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { return schedulePendingCallable( new PendingCallable<>( Duration.ofMillis(unit.toMillis(delay)), callable, PendingCallableType.NORMAL)); }
@Override public ScheduledFuture<?> scheduleWithFixedDelay( Runnable command, long initialDelay, long delay, TimeUnit unit) { return schedulePendingCallable( new PendingCallable<>( Duration.ofMillis(unit.toMillis(initialDelay)), command, PendingCallableType.FIXED_DELAY)); }
@Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { return schedulePendingCallable( new PendingCallable<>( Duration.ofMillis(unit.toMillis(delay)), command, PendingCallableType.NORMAL)); }
@Override public ScheduledFuture<?> scheduleAtFixedRate( Runnable command, long initialDelay, long period, TimeUnit unit) { return schedulePendingCallable( new PendingCallable<>( Duration.ofMillis(unit.toMillis(initialDelay)), command, PendingCallableType.FIXED_RATE)); }
@Test public void testWaitForCheckingPeriod_Null() throws InterruptedException { initializeExpectedOperation(4); Compute.OperationOption[] expectedOptions = { Compute.OperationOption.fields(Compute.OperationField.STATUS) }; Operation runningOperation = Operation.fromPb( serviceMockReturnsOptions, globalOperation.toPb().setError(null).setStatus("RUNNING")); expect(compute.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(runningOperation); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(null); replay(compute, mockOptions); initializeOperation(); assertNull(operation.waitFor(RetryOption.initialRetryDelay(Duration.ofMillis(1L)))); verify(compute, mockOptions); }
public Publisher getPublisherWithCustomBatchSettings(ProjectTopicName topicName) throws Exception { // [START pubsub_publisher_batch_settings] // Batch settings control how the publisher batches messages long requestBytesThreshold = 5000L; // default : 1 byte long messageCountBatchSize = 10L; // default : 1 message Duration publishDelayThreshold = Duration.ofMillis(100); // default : 1 ms // Publish request get triggered based on request size, messages count & time since last publish BatchingSettings batchingSettings = BatchingSettings.newBuilder() .setElementCountThreshold(messageCountBatchSize) .setRequestByteThreshold(requestBytesThreshold) .setDelayThreshold(publishDelayThreshold) .build(); Publisher publisher = Publisher.newBuilder(topicName).setBatchingSettings(batchingSettings).build(); // [END pubsub_publisher_batch_settings] return publisher; }
@Test public void bulkMutationsBatchingCloseTest() throws Exception { BulkMutationBatcher batcher = bigtableDataClient.newBulkMutationBatcher(); RowMutation request = RowMutation.create("fake-table", "some-key") .setCell("some-family", "fake-qualifier", "fake-value"); SettableApiFuture<Void> innerResult = SettableApiFuture.create(); Mockito.when(mockBulkMutateRowsBatchingCallable.futureCall(request)).thenReturn(innerResult); batcher.add(request); // Close will timeout while the request is outstanding. Throwable error = null; try { batcher.close(Duration.ofMillis(20)); } catch (Throwable t) { error = t; } assertThat(error).isInstanceOf(TimeoutException.class); // Resolve the request innerResult.set(null); // Now, close will promptly finish batcher.close(Duration.ofMillis(20)); }
@Test public void testReadRowsSettings() { ServerStreamingCallSettings.Builder<ReadRowsRequest, ReadRowsResponse> builder = EnhancedBigQueryStorageStubSettings.newBuilder().readRowsSettings(); assertThat(builder.getRetryableCodes()).containsAllOf(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); RetrySettings retrySettings = builder.getRetrySettings(); assertThat(retrySettings.getInitialRetryDelay()).isEqualTo(Duration.ofMillis(100L)); assertThat(retrySettings.getRetryDelayMultiplier()).isWithin(1e-6).of(1.3); assertThat(retrySettings.getMaxRetryDelay()).isEqualTo(Duration.ofMinutes(1L)); assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(Duration.ofDays(1L)); assertThat(retrySettings.getRpcTimeoutMultiplier()).isWithin(1e-6).of(1.0); assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(Duration.ofDays(1L)); assertThat(retrySettings.getTotalTimeout()).isEqualTo(Duration.ofDays(1L)); assertThat(builder.getIdleTimeout()).isEqualTo(Duration.ZERO); }
@Test public void bulkMutationsBatchingFailureTest() throws Exception { BulkMutationBatcher batcher = bigtableDataClient.newBulkMutationBatcher(); RowMutation request = RowMutation.create("fake-table", "some-key") .setCell("some-family", "fake-qualifier", "fake-value"); SettableApiFuture<Void> innerResult = SettableApiFuture.create(); Mockito.when(mockBulkMutateRowsBatchingCallable.futureCall(request)).thenReturn(innerResult); ApiException innerError = new ApiException(null, GrpcStatusCode.of(Code.INTERNAL), false); batcher.add(request); innerResult.setException(innerError); Throwable outerError = null; try { batcher.close(Duration.ofMillis(10)); } catch (Throwable t) { outerError = t; } assertThat(outerError).isInstanceOf(BulkMutationFailure.class); }
@Before public void setUp() { ClientContext clientContext = ClientContext.newBuilder().setDefaultCallContext(CALL_CONTEXT).build(); RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(Duration.ofMillis(100)) // Delay settings: 1 ms const .setInitialRetryDelay(Duration.ofMillis(1)) .setMaxRetryDelay(Duration.ofMillis(1)) .setRetryDelayMultiplier(1.0) // RPC timeout: ignored const 1 s .setInitialRpcTimeout(Duration.ofSeconds(1)) .setMaxRpcTimeout(Duration.ofSeconds(1)) .setRpcTimeoutMultiplier(1.0) .build(); callable = AwaitReplicationCallable.create( mockGenerateConsistencyTokenCallable, mockCheckConsistencyCallable, clientContext, retrySettings); }
@Test public void testCreateFromStream() { RemoteComputeHelper helper = RemoteComputeHelper.create(PROJECT_ID, JSON_KEY_STREAM); ComputeOptions options = helper.getOptions(); assertEquals(PROJECT_ID, options.getProjectId()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout()); assertEquals(10, options.getRetrySettings().getMaxAttempts()); assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay()); assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout()); assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay()); }
@Test public void testCreateFromStream() { RemoteStorageHelper helper = RemoteStorageHelper.create(PROJECT_ID, JSON_KEY_STREAM); StorageOptions options = helper.getOptions(); assertEquals(PROJECT_ID, options.getProjectId()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout()); assertEquals(10, options.getRetrySettings().getMaxAttempts()); assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay()); assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout()); assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay()); } }
@Test public void testCreateFromStream() { RemoteBigQueryHelper helper = RemoteBigQueryHelper.create(PROJECT_ID, JSON_KEY_STREAM); BigQueryOptions options = helper.getOptions(); assertEquals(PROJECT_ID, options.getProjectId()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout()); assertEquals(10, options.getRetrySettings().getMaxAttempts()); assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay()); assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout()); assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay()); } }
@Test public void testPublisherGetters() throws Exception { Publisher.Builder builder = Publisher.newBuilder(TEST_TOPIC); builder.setChannelProvider(TEST_CHANNEL_PROVIDER); builder.setExecutorProvider(SINGLE_THREAD_EXECUTOR); builder.setBatchingSettings( BatchingSettings.newBuilder() .setRequestByteThreshold(10L) .setDelayThreshold(Duration.ofMillis(11)) .setElementCountThreshold(12L) .build()); builder.setCredentialsProvider(NoCredentialsProvider.create()); Publisher publisher = builder.build(); assertEquals(TEST_TOPIC, publisher.getTopicName()); assertEquals(10, (long) publisher.getBatchingSettings().getRequestByteThreshold()); assertEquals(Duration.ofMillis(11), publisher.getBatchingSettings().getDelayThreshold()); assertEquals(12, (long) publisher.getBatchingSettings().getElementCountThreshold()); publisher.shutdown(); publisher.awaitTermination(1, TimeUnit.MINUTES); }