Refine search
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(); }
public Publisher getPublisherWithCustomRetrySettings(ProjectTopicName topicName) throws Exception { // [START pubsub_publisher_retry_settings] // Retry settings control how the publisher handles retryable failures Duration retryDelay = Duration.ofMillis(100); // default : 1 ms double retryDelayMultiplier = 2.0; // back off for repeated failures Duration maxRetryDelay = Duration.ofSeconds(5); // default : 10 seconds Duration totalTimeout = Duration.ofSeconds(1); // default: 0 Duration initialRpcTimeout = Duration.ofSeconds(1); // default: 0 Duration maxRpcTimeout = Duration.ofSeconds(10); // default: 0 RetrySettings retrySettings = RetrySettings.newBuilder() .setInitialRetryDelay(retryDelay) .setRetryDelayMultiplier(retryDelayMultiplier) .setMaxRetryDelay(maxRetryDelay) .setTotalTimeout(totalTimeout) .setInitialRpcTimeout(initialRpcTimeout) .setMaxRpcTimeout(maxRpcTimeout) .build(); Publisher publisher = Publisher.newBuilder(topicName).setRetrySettings(retrySettings).build(); // [END pubsub_publisher_retry_settings] return publisher; }
/** * Set the maximum period a message ack deadline will be extended. Defaults to one hour. * * <p>It is recommended to set this value to a reasonable upper bound of the subscriber time to * process any message. This maximum period avoids messages to be <i>locked</i> by a subscriber * in cases when the ack reply is lost. * * <p>A zero duration effectively disables auto deadline extensions. */ public Builder setMaxAckExtensionPeriod(Duration maxAckExtensionPeriod) { Preconditions.checkArgument(maxAckExtensionPeriod.toMillis() >= 0); this.maxAckExtensionPeriod = maxAckExtensionPeriod; return this; }
private DurationRule(Duration duration) { this.builder = com.google.protobuf.Duration.newBuilder() .setSeconds(duration.getSeconds()) .setNanos(duration.getNano()); }
@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 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); }
/** Example of partitioning data to a list of Google Cloud Storage files. */ // [TARGET extract(String, List, JobOption...)] // [VARIABLE "CSV"] // [VARIABLE "gs://my_bucket/PartitionA_*.csv"] // [VARIABLE "gs://my_bucket/PartitionB_*.csv"] public Job extractList(String format, String gcsUrl1, String gcsUrl2) { // [START ] List<String> destinationUris = new ArrayList<>(); destinationUris.add(gcsUrl1); destinationUris.add(gcsUrl2); Job job = table.extract(format, destinationUris); // Wait for the job to complete try { Job completedJob = job.waitFor( RetryOption.initialRetryDelay(Duration.ofSeconds(1)), RetryOption.totalTimeout(Duration.ofMinutes(3))); if (completedJob != null && completedJob.getStatus().getError() == null) { // Job completed successfully } else { // Handle error case } } catch (InterruptedException e) { // Handle interrupted wait } // [END ] return job; }
@Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { return schedulePendingCallable( new PendingCallable<>( Duration.ofMillis(unit.toMillis(delay)), command, PendingCallableType.NORMAL)); }
private AwaitReplicationCallable createAwaitReplicationCallable() { // TODO(igorbernstein2): expose polling settings RetrySettings pollingSettings = RetrySettings.newBuilder() // use overall timeout from checkConsistencyCallable // NOTE: The overall timeout might exceed this value due to underlying retries .setTotalTimeout( settings.checkConsistencySettings().getRetrySettings().getTotalTimeout()) // Use constant polling with jitter .setInitialRetryDelay(Duration.ofSeconds(10)) .setRetryDelayMultiplier(1.0) .setMaxRetryDelay(Duration.ofSeconds(10)) .setJittered(true) // These rpc timeouts are ignored, instead the rpc timeouts defined for // generateConsistencyToken and checkConsistency callables will be used. .setInitialRpcTimeout(Duration.ZERO) .setMaxRpcTimeout(Duration.ZERO) .setRpcTimeoutMultiplier(1.0) .build(); return AwaitReplicationCallable.create( generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings); }
RetrySettings.newBuilder() .setMaxAttempts(10) .setTotalTimeout(Duration.ofHours(1)) .setInitialRpcTimeout(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) .setMaxRpcTimeout(Duration.ofSeconds(10)) .setJittered(true) .build(); .setIdleTimeout(Duration.ofMinutes(5)) .setRetryableCodes(Code.ABORTED, Code.DEADLINE_EXCEEDED) .setRetrySettings(retrySettings) assertThat(builder.readRowsSettings().getIdleTimeout()).isEqualTo(Duration.ofMinutes(5)); assertThat(builder.readRowsSettings().getRetryableCodes()) .containsAllOf(Code.ABORTED, Code.DEADLINE_EXCEEDED); .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.build().readRowsSettings().getRetryableCodes()) .containsAllOf(Code.ABORTED, Code.DEADLINE_EXCEEDED); .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.build().toBuilder().readRowsSettings().getRetryableCodes()) .containsAllOf(Code.ABORTED, Code.DEADLINE_EXCEEDED);
private static Duration systemProperty(String name, int defaultValue) { String stringValue = System.getProperty(name, ""); return Duration.ofSeconds(stringValue.isEmpty() ? defaultValue : Integer.parseInt(stringValue)); } }
@Test(expected = ExecutionException.class) public void testPublishFailureRetries_retriesDisabled() throws Exception { Publisher publisher = getTestPublisherBuilder() .setExecutorProvider(SINGLE_THREAD_EXECUTOR) .setRetrySettings( Publisher.Builder.DEFAULT_RETRY_SETTINGS .toBuilder() .setTotalTimeout(Duration.ofSeconds(10)) .setMaxAttempts(1) .build()) .build(); testPublisherServiceImpl.addPublishError(new Throwable("Transiently failing")); ApiFuture<String> publishFuture1 = sendTestMessage(publisher, "A"); try { publishFuture1.get(); } finally { assertSame(testPublisherServiceImpl.getCapturedRequests().size(), 1); publisher.shutdown(); publisher.awaitTermination(1, TimeUnit.MINUTES); } }
MockRetryingFuture(Duration totalTimeout) { this.timedAttemptSettings = TimedAttemptSettings.newBuilder() .setRpcTimeout(Duration.ofSeconds(1)) .setRetryDelay(Duration.ZERO) .setRandomizedRetryDelay(Duration.ZERO) .setAttemptCount(0) .setFirstAttemptStartTimeNanos(0) .setGlobalSettings(RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build()) .build(); }
@Override public HttpJsonCallContext withTimeout(Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; } // Prevent expanding deadlines if (timeout != null && this.timeout != null && this.timeout.compareTo(timeout) <= 0) { return this; } return new HttpJsonCallContext( this.channel, timeout, this.deadline, this.credentials, this.extraHeaders, this.tracer); }
@Test public void testTimeoutToDeadlineConversion() { MethodDescriptor<Color, Money> descriptor = FakeServiceGrpc.METHOD_RECOGNIZE; @SuppressWarnings("unchecked") ClientCall<Color, Money> mockClientCall = Mockito.mock(ClientCall.class); @SuppressWarnings("unchecked") ClientCall.Listener<Money> mockListener = Mockito.mock(ClientCall.Listener.class); @SuppressWarnings("unchecked") Channel mockChannel = Mockito.mock(ManagedChannel.class); ArgumentCaptor<CallOptions> capturedCallOptions = ArgumentCaptor.forClass(CallOptions.class); Mockito.when(mockChannel.newCall(Mockito.eq(descriptor), capturedCallOptions.capture())) .thenReturn(mockClientCall); Duration timeout = Duration.ofSeconds(10); Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS); GrpcCallContext context = GrpcCallContext.createDefault().withChannel(mockChannel).withTimeout(timeout); GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata()); Deadline maxExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS); Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline); Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline); }
/** * This method simply calls {@link Thread#sleep(long)}. * * @param delay time to sleep * @throws InterruptedException if any thread has interrupted the current thread */ protected void sleep(Duration delay) throws InterruptedException { if (Duration.ZERO.compareTo(delay) < 0) { Thread.sleep(delay.toMillis()); } } }
@SuppressWarnings("ConstantConditions") @Nullable @Override public Watchdog getWatchdog() { Preconditions.checkState(!needsClock(), "A clock is needed"); Preconditions.checkState(!needsCheckInterval(), "A check interval is needed"); Preconditions.checkState(!needsExecutor(), "An executor is needed"); // Watchdog is disabled if (checkInterval.isZero()) { return null; } Watchdog watchdog = new Watchdog(clock); executor.scheduleAtFixedRate( watchdog, checkInterval.toMillis(), checkInterval.toMillis(), TimeUnit.MILLISECONDS); return watchdog; } }
.addFamily("mf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000))) .updateFamily( "mf1", GCRULES .union() .rule(GCRULES.maxAge(Duration.ofSeconds(100))) .rule(GCRULES.maxVersions(1))) .addFamily( GCRULES .intersection() .rule(GCRULES.maxAge(Duration.ofSeconds(2000))) .rule(GCRULES.maxVersions(10))) .addFamily("mf4", GCRULES.intersection().rule(GCRULES.maxAge(Duration.ofSeconds(360)))) .addFamily("mf5") .addFamily("mf6") assertEquals(2, ((UnionRule) columnFamilyById.get("mf1").getGCRule()).getRulesList().size()); assertEquals( 1000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getSeconds()); assertEquals( 20000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getNano()); assertEquals( 2, ((IntersectionRule) columnFamilyById.get("mf3").getGCRule()).getRulesList().size()); assertEquals( 360, ((DurationRule) columnFamilyById.get("mf4").getGCRule()).getMaxAge().getSeconds()); assertNotNull(columnFamilyById.get("mf7")); } finally {
/** Configures the Publisher's retry parameters. */ public Builder setRetrySettings(RetrySettings retrySettings) { Preconditions.checkArgument( retrySettings.getTotalTimeout().compareTo(MIN_TOTAL_TIMEOUT) >= 0); Preconditions.checkArgument( retrySettings.getInitialRpcTimeout().compareTo(MIN_RPC_TIMEOUT) >= 0); this.retrySettings = retrySettings; return this; }