use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method copy.
@Override
public CopyWriter copy(final CopyRequest copyRequest) {
final StorageObject source = copyRequest.getSource().toPb();
final Map<StorageRpc.Option, ?> sourceOptions = optionMap(copyRequest.getSource().getGeneration(), null, copyRequest.getSourceOptions(), true);
final StorageObject targetObject = copyRequest.getTarget().toPb();
final Map<StorageRpc.Option, ?> targetOptions = optionMap(copyRequest.getTarget().getGeneration(), copyRequest.getTarget().getMetageneration(), copyRequest.getTargetOptions());
try {
RewriteResponse rewriteResponse = runWithRetries(new Callable<RewriteResponse>() {
@Override
public RewriteResponse call() {
return storageRpc.openRewrite(new StorageRpc.RewriteRequest(source, sourceOptions, copyRequest.overrideInfo(), targetObject, targetOptions, copyRequest.getMegabytesCopiedPerChunk()));
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
return new CopyWriter(getOptions(), rewriteResponse);
} 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 compose.
@Override
public Blob compose(final ComposeRequest composeRequest) {
final List<StorageObject> sources = Lists.newArrayListWithCapacity(composeRequest.getSourceBlobs().size());
for (ComposeRequest.SourceBlob sourceBlob : composeRequest.getSourceBlobs()) {
sources.add(BlobInfo.newBuilder(BlobId.of(composeRequest.getTarget().getBucket(), sourceBlob.getName(), sourceBlob.getGeneration())).build().toPb());
}
final StorageObject target = composeRequest.getTarget().toPb();
final Map<StorageRpc.Option, ?> targetOptions = optionMap(composeRequest.getTarget().getGeneration(), composeRequest.getTarget().getMetageneration(), composeRequest.getTargetOptions());
try {
return Blob.fromPb(this, runWithRetries(new Callable<StorageObject>() {
@Override
public StorageObject call() {
return storageRpc.compose(sources, target, targetOptions);
}
}, 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 update.
@Override
public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
final StorageObject storageObject = blobInfo.toPb();
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blobInfo, options);
try {
return Blob.fromPb(this, runWithRetries(new Callable<StorageObject>() {
@Override
public StorageObject call() {
return storageRpc.patch(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 BigQueryExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
Exception cause = new BigQueryException(503, "message");
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
BigQueryException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(503, 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 {
BigQueryException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(BigQueryException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
Aggregations