/** * Some services may have different backoff requirements listed in their SLAs. Be sure to override * this method in options subclasses when the service's backoff requirement differs from the * default parameters listed in {@link RetrySettings}. */ protected RetrySettings defaultRetrySettings() { return getDefaultRetrySettings(); }
retrySettings = firstNonNull(builder.retrySettings, getDefaultRetrySettings()); serviceFactory = firstNonNull(
@Test public void testRetryableException() { EasyMock.expect(translateRpcMock.listSupportedLanguages(EMPTY_RPC_OPTIONS)) .andThrow(new TranslateException(500, "internalError")) .andReturn(ImmutableList.of(LANGUAGE1_PB, LANGUAGE2_PB)); EasyMock.replay(translateRpcMock); translate = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); assertEquals(LANGUAGES1, translate.listSupportedLanguages()); verify(); }
@Test public void testRuntimeException() { String exceptionMessage = "Artificial runtime exception"; EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) .andThrow(new RuntimeException(exceptionMessage)); EasyMock.replay(bigqueryRpcMock); bigquery = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(BigQueryException.class); thrown.expectMessage(exceptionMessage); bigquery.getDataset(DATASET); }
@Test public void testRuntimeException() { String exceptionMessage = "Artificial runtime exception"; EasyMock.expect(translateRpcMock.listSupportedLanguages(EMPTY_RPC_OPTIONS)) .andThrow(new RuntimeException(exceptionMessage)); EasyMock.replay(translateRpcMock); translate = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(TranslateException.class); thrown.expectMessage(exceptionMessage); translate.listSupportedLanguages(); verify(); }
@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(); }
@Test public void testRuntimeException() { BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1); String exceptionMessage = "Artificial runtime exception"; EasyMock.expect(storageRpcMock.get(blob.toPb(), EMPTY_RPC_OPTIONS)) .andThrow(new RuntimeException(exceptionMessage)); EasyMock.replay(storageRpcMock); storage = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(StorageException.class); thrown.expectMessage(exceptionMessage); storage.get(blob); } }
@Test public void testRuntimeException() { String exceptionMessage = "Artificial runtime exception"; EasyMock.expect( computeRpcMock.getDiskType( DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andThrow(new RuntimeException(exceptionMessage)); EasyMock.replay(computeRpcMock); compute = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(ComputeException.class); thrown.expectMessage(exceptionMessage); compute.getDiskType(DISK_TYPE_ID); } }
@Test public void testQueryDryRun() throws Exception { // https://github.com/googleapis/google-cloud-java/issues/2479 EasyMock.replay(bigqueryRpcMock); thrown.expect(UnsupportedOperationException.class); options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService() .query(QueryJobConfiguration.newBuilder("foo").setDryRun(true).build()); } }
@Test public void testRetryableException() { EasyMock.expect( computeRpcMock.getDiskType( DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andThrow(new ComputeException(500, "InternalError")) .andReturn(DISK_TYPE.toPb()); EasyMock.replay(computeRpcMock); compute = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); DiskType diskType = compute.getDiskType(DISK_TYPE_ID); assertEquals(DISK_TYPE, diskType); }
@Test public void testRetryableException() { BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1); EasyMock.expect(storageRpcMock.get(blob.toPb(), EMPTY_RPC_OPTIONS)) .andThrow(new StorageException(500, "internalError")) .andReturn(BLOB_INFO1.toPb()); EasyMock.replay(storageRpcMock); storage = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); initializeServiceDependentObjects(); Blob readBlob = storage.get(blob); assertEquals(expectedBlob1, readBlob); }
@Test public void testRetryableException() { EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) .andThrow(new BigQueryException(500, "InternalError")) .andReturn(DATASET_INFO_WITH_PROJECT.toPb()); EasyMock.replay(bigqueryRpcMock); bigquery = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); Dataset dataset = bigquery.getDataset(DATASET); assertEquals( new Dataset(bigquery, new DatasetInfo.BuilderImpl(DATASET_INFO_WITH_PROJECT)), dataset); }
@Test public void testNonRetryableException() { String exceptionMessage = "Not Implemented"; EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) .andThrow(new BigQueryException(501, exceptionMessage)); EasyMock.replay(bigqueryRpcMock); bigquery = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(BigQueryException.class); thrown.expectMessage(exceptionMessage); bigquery.getDataset(DatasetId.of(DATASET)); }
@Test public void testNonRetryableException() { String exceptionMessage = "Not Implemented"; EasyMock.expect(translateRpcMock.listSupportedLanguages(EMPTY_RPC_OPTIONS)) .andThrow(new TranslateException(501, exceptionMessage)); EasyMock.replay(translateRpcMock); translate = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(TranslateException.class); thrown.expectMessage(exceptionMessage); translate.listSupportedLanguages(); verify(); }
@Test public void testNonRetryableException() { String exceptionMessage = "Not Implemented"; EasyMock.expect( computeRpcMock.getDiskType( DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andThrow(new ComputeException(501, exceptionMessage)); EasyMock.replay(computeRpcMock); compute = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(ComputeException.class); thrown.expectMessage(exceptionMessage); compute.getDiskType(DISK_TYPE_ID); }
@Before public void setUp() { rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class); rpcMock = EasyMock.createStrictMock(DatastoreRpc.class); rpcMockOptions = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .setServiceRpcFactory(rpcFactoryMock) .build(); EasyMock.expect(rpcFactoryMock.create(rpcMockOptions)).andReturn(rpcMock); StructuredQuery<Key> query = Query.newKeyQueryBuilder().build(); QueryResults<Key> result = datastore.run(query); datastore.delete(Iterators.toArray(result, Key.class)); datastore.add(ENTITY1, ENTITY2); }
@Test public void testNonRetryableException() { BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1); String exceptionMessage = "Not Implemented"; EasyMock.expect(storageRpcMock.get(blob.toPb(), EMPTY_RPC_OPTIONS)) .andThrow(new StorageException(501, exceptionMessage)); EasyMock.replay(storageRpcMock); storage = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); initializeServiceDependentObjects(); thrown.expect(StorageException.class); thrown.expectMessage(exceptionMessage); storage.get(blob); }
options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService();
@Test public void testCreateBlobFromStreamRetryableException() throws IOException { Capture<ByteArrayInputStream> capturedStream = Capture.newInstance(); ByteArrayInputStream fileStream = new ByteArrayInputStream(BLOB_CONTENT); BlobInfo.Builder infoBuilder = BLOB_INFO1.toBuilder(); BlobInfo infoWithHashes = infoBuilder.setMd5(CONTENT_MD5).setCrc32c(CONTENT_CRC32C).build(); BlobInfo infoWithoutHashes = infoBuilder.setMd5(null).setCrc32c(null).build(); EasyMock.expect( storageRpcMock.create( EasyMock.eq(infoWithoutHashes.toPb()), EasyMock.capture(capturedStream), EasyMock.eq(EMPTY_RPC_OPTIONS))) .andThrow(new StorageException(500, "internalError")) .once(); EasyMock.replay(storageRpcMock); storage = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); // Even though this exception is retryable, storage.create(BlobInfo, InputStream) // shouldn't retry. thrown.expect(StorageException.class); thrown.expectMessage("internalError"); storage.create(infoWithHashes, fileStream); }
@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()); }