use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method get.
@Override
public Blob get(BlobId blob, BlobGetOption... options) {
final StorageObject storedObject = blob.toPb();
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, options);
try {
StorageObject storageObject = runWithRetries(new Callable<StorageObject>() {
@Override
public StorageObject call() {
return storageRpc.get(storedObject, optionsMap);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
return storageObject == null ? null : Blob.fromPb(this, storageObject);
} catch (RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
}
use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method create.
private Blob create(BlobInfo info, final InputStream content, BlobTargetOption... options) {
final StorageObject blobPb = info.toPb();
final Map<StorageRpc.Option, ?> optionsMap = optionMap(info, options);
try {
return Blob.fromPb(this, runWithRetries(new Callable<StorageObject>() {
@Override
public StorageObject call() {
return storageRpc.create(blobPb, firstNonNull(content, new ByteArrayInputStream(EMPTY_BYTE_ARRAY)), optionsMap);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
} catch (RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
}
use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method delete.
@Override
public boolean delete(BlobId blob, BlobSourceOption... options) {
final StorageObject storageObject = blob.toPb();
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, options);
try {
return runWithRetries(new Callable<Boolean>() {
@Override
public Boolean call() {
return storageRpc.delete(storageObject, optionsMap);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
} catch (RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
}
use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method readAllBytes.
@Override
public byte[] readAllBytes(BlobId blob, BlobSourceOption... options) {
final StorageObject storageObject = blob.toPb();
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, options);
try {
return runWithRetries(new Callable<byte[]>() {
@Override
public byte[] call() {
return storageRpc.load(storageObject, optionsMap);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
} catch (RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
}
use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class ComputeExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
Exception cause = new ComputeException(500, "message");
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
ComputeException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(500, ex.getCode());
assertEquals("message", ex.getMessage());
assertTrue(ex.isRetryable());
} finally {
verify(exceptionMock);
}
cause = new IllegalArgumentException("message");
exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getMessage()).andReturn("message").times(1);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
ComputeException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(ComputeException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
Aggregations