use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class ResourceManagerExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
Exception cause = new ResourceManagerException(503, "message");
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
ResourceManagerException.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 {
ResourceManagerException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(ResourceManagerException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class DnsExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
IOException timeoutException = new SocketTimeoutException("message");
Exception cause = new DnsException(timeoutException, true);
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
DnsException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(DnsException.UNKNOWN_CODE, ex.getCode());
assertNull(ex.getReason());
assertEquals("message", ex.getMessage());
assertEquals(timeoutException, ex.getCause());
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 {
DnsException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(DnsException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class StorageExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
Exception cause = new StorageException(503, "message");
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
StorageException.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 {
StorageException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(StorageException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class TranslateExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
Exception cause = new TranslateException(500, "message");
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
TranslateException.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 {
TranslateException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(TranslateException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
use of com.google.cloud.RetryHelper.RetryHelperException in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method testIamPermissions.
@Override
public List<Boolean> testIamPermissions(final String bucket, final List<String> permissions) {
try {
TestIamPermissionsResponse response = runWithRetries(new Callable<TestIamPermissionsResponse>() {
@Override
public TestIamPermissionsResponse call() {
return storageRpc.testIamPermissions(bucket, permissions);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
final Set<String> heldPermissions = response.getPermissions() != null ? ImmutableSet.copyOf(response.getPermissions()) : ImmutableSet.<String>of();
return Lists.transform(permissions, new Function<String, Boolean>() {
@Override
public Boolean apply(String permission) {
return heldPermissions.contains(permission);
}
});
} catch (RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
}
Aggregations