static <R, M> Operation<R, M> create( SpannerRpc rpc, com.google.longrunning.Operation proto, Parser<R, M> parser) { return Operation.<R, M>create(rpc, proto, parser, CurrentMillisClock.getDefaultClock()); }
getFromServiceLoader(rpcFactoryClass, serviceDefaults.getDefaultRpcFactory())); serviceRpcFactoryClassName = serviceRpcFactory.getClass().getName(); clock = firstNonNull(builder.clock, CurrentMillisClock.getDefaultClock()); transportOptions = firstNonNull(builder.transportOptions, serviceDefaults.getDefaultTransportOptions());
/** * @param firestore The Firestore Database client. * @param query The query that is used to order the document snapshots returned by this watch. * @param target A Firestore 'Target' proto denoting the target to listen on. */ private Watch(FirestoreImpl firestore, Query query, Target target) { this.firestore = firestore; this.target = target; this.query = query; this.comparator = query.comparator(); this.backoff = new ExponentialRetryAlgorithm(RETRY_SETTINGS, CurrentMillisClock.getDefaultClock()); this.firestoreExecutor = firestore.getClient().getExecutor(); this.isActive = new AtomicBoolean(); this.nextAttempt = backoff.createFirstAttempt(); }
@Test public void testWaitFor_Null() throws InterruptedException { initializeExpectedOperation(3); Compute.OperationOption[] expectedOptions = { Compute.OperationOption.fields(Compute.OperationField.STATUS) }; expect(compute.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(null); expect(compute.getOperation(GLOBAL_OPERATION_ID)).andReturn(null); replay(compute, mockOptions); initializeOperation(); assertNull(operation.waitFor()); verify(mockOptions); }
@Test public void testWaitFor_Null() throws InterruptedException { initializeExpectedJob(1); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(null); replay(bigquery, mockOptions); initializeJob(); assertNull(job.waitFor(TEST_RETRY_OPTIONS)); verify(mockOptions); }
@Test public void testWaitFor() throws InterruptedException { initializeExpectedOperation(4); Compute.OperationOption[] expectedOptions = { Compute.OperationOption.fields(Compute.OperationField.STATUS) }; Operation successOperation = Operation.fromPb(serviceMockReturnsOptions, globalOperation.toPb().setError(null)); expect(compute.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(successOperation); expect(compute.getOperation(GLOBAL_OPERATION_ID)).andReturn(successOperation); replay(compute, mockOptions); initializeOperation(); assertSame(successOperation, operation.waitFor()); verify(mockOptions); }
@Test public void testWaitForWithCheckingPeriod_Null() throws InterruptedException { initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); Job runningJob = expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build(); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(runningJob); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(null); replay(bigquery, mockOptions); initializeJob(); assertNull(job.waitFor(TEST_RETRY_OPTIONS)); verify(bigquery, mockOptions); }
@Test public void testWaitFor() throws InterruptedException { initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; JobStatus status = createStrictMock(JobStatus.class); expect(status.getState()).andReturn(JobStatus.State.DONE); // caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry() expect(status.getState()).andReturn(JobStatus.State.DONE); expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); Job completedJob = expectedJob.toBuilder().setStatus(status).build(); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(completedJob); expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob); replay(status, bigquery, mockOptions); initializeJob(); assertSame(completedJob, job.waitFor(TEST_RETRY_OPTIONS)); verify(status, mockOptions); }
@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); }
@Test public void testWaitForWithCheckingPeriod() throws InterruptedException { initializeExpectedJob(3); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; JobStatus status = createStrictMock(JobStatus.class); expect(status.getState()).andReturn(JobStatus.State.RUNNING); // caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry() expect(status.getState()).andReturn(JobStatus.State.RUNNING); expect(status.getState()).andReturn(JobStatus.State.DONE); // caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry() expect(status.getState()).andReturn(JobStatus.State.DONE); expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); Job runningJob = expectedJob.toBuilder().setStatus(status).build(); Job completedJob = expectedJob.toBuilder().setStatus(status).build(); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(runningJob); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(completedJob); expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob); replay(status, bigquery, mockOptions); initializeJob(); assertSame(completedJob, job.waitFor(TEST_RETRY_OPTIONS)); verify(status, mockOptions); }
ackExpirationPadding = builder.ackExpirationPadding; maxAckExtensionPeriod = builder.maxAckExtensionPeriod; clock = builder.clock.isPresent() ? builder.clock.get() : CurrentMillisClock.getDefaultClock();
@Test public void testWaitForCheckingPeriod() throws InterruptedException { initializeExpectedOperation(5); Compute.OperationOption[] expectedOptions = { Compute.OperationOption.fields(Compute.OperationField.STATUS) }; Operation runningOperation = Operation.fromPb( serviceMockReturnsOptions, globalOperation.toPb().setError(null).setStatus("RUNNING")); Operation completedOperation = Operation.fromPb(serviceMockReturnsOptions, globalOperation.toPb().setError(null)); 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(completedOperation); expect(compute.getOperation(GLOBAL_OPERATION_ID)).andReturn(completedOperation); replay(compute, mockOptions); initializeOperation(); assertSame( completedOperation, operation.waitFor(RetryOption.initialRetryDelay(Duration.ofMillis(1)))); verify(mockOptions); }
@Override public void start() throws IOException { ExceptionHandler retryOnAnythingExceptionHandler = ExceptionHandler.newBuilder().retryOn(Exception.class).build(); Path emulatorPath = RetryHelper.runWithRetries( new Callable<Path>() { @Override public Path call() throws IOException { return downloadEmulator(); } }, ServiceOptions.getDefaultRetrySettings(), retryOnAnythingExceptionHandler, CurrentMillisClock.getDefaultClock()); process = CommandWrapper.create() .setCommand(commandText) .setDirectory(emulatorPath) // gcloud redirects all output to stderr while emulators' executables use either // stdout // or stderr with no apparent convention. To be able to properly intercept and block // waiting for emulators to be ready we redirect everything to stdout .setRedirectErrorStream() .start(); }
JobStatus status = createStrictMock(JobStatus.class); expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2); Job completedJob = expectedJob.toBuilder().setStatus(status).build();
JobStatus status = createStrictMock(JobStatus.class); expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2); Job completedJob = expectedJob.toBuilder().setStatus(status).build();
@Test public void testBuilder() { assertSame(credentials, OPTIONS.getCredentials()); assertSame(TEST_CLOCK, OPTIONS.getClock()); assertEquals("host", OPTIONS.getHost()); assertEquals("project-id", OPTIONS.getProjectId()); assertSame(ServiceOptions.getNoRetrySettings(), OPTIONS.getRetrySettings()); assertSame(CurrentMillisClock.getDefaultClock(), DEFAULT_OPTIONS.getClock()); assertEquals("https://www.googleapis.com", DEFAULT_OPTIONS.getHost()); assertSame(ServiceOptions.getDefaultRetrySettings(), DEFAULT_OPTIONS.getRetrySettings()); }
static <R, M> Operation<R, M> create( SpannerRpc rpc, com.google.longrunning.Operation proto, Parser<R, M> parser) { return Operation.<R, M>create(rpc, proto, parser, CurrentMillisClock.getDefaultClock()); }
/** * @param firestore The Firestore Database client. * @param query The query that is used to order the document snapshots returned by this watch. * @param target A Firestore 'Target' proto denoting the target to listen on. */ private Watch(FirestoreImpl firestore, Query query, Target target) { this.firestore = firestore; this.target = target; this.query = query; this.comparator = query.comparator(); this.backoff = new ExponentialRetryAlgorithm(RETRY_SETTINGS, CurrentMillisClock.getDefaultClock()); this.firestoreExecutor = firestore.getClient().getExecutor(); this.isActive = new AtomicBoolean(); this.nextAttempt = backoff.createFirstAttempt(); }
getFromServiceLoader(rpcFactoryClass, serviceDefaults.getDefaultRpcFactory())); serviceRpcFactoryClassName = serviceRpcFactory.getClass().getName(); clock = firstNonNull(builder.clock, CurrentMillisClock.getDefaultClock()); transportOptions = firstNonNull(builder.transportOptions, serviceDefaults.getDefaultTransportOptions());
@Override protected RetryAlgorithm<String> getAlgorithm( RetrySettings retrySettings, int apocalypseCountDown, RuntimeException apocalypseException) { return new RetryAlgorithm<>( new TestResultRetryAlgorithm<String>(apocalypseCountDown, apocalypseException), new ExponentialRetryAlgorithm(retrySettings, CurrentMillisClock.getDefaultClock())); } }