use of com.google.cloud.BaseServiceException 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.BaseServiceException 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);
}
}
use of com.google.cloud.BaseServiceException in project google-cloud-java by GoogleCloudPlatform.
the class BaseGrpcServiceExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
IOException exception = new SocketTimeoutException();
BaseGrpcServiceException cause = new BaseGrpcServiceException(exception, IDEMPOTENT);
RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
BaseServiceException.translate(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(0, ex.getCode());
assertNull(ex.getMessage());
assertTrue(ex.isRetryable());
} finally {
verify(exceptionMock);
}
}
use of com.google.cloud.BaseServiceException in project google-cloud-java by GoogleCloudPlatform.
the class BaseHttpServiceExceptionTest method testBaseServiceException.
@Test
public void testBaseServiceException() {
BaseServiceException serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS);
assertEquals(CODE, serviceException.getCode());
assertEquals(MESSAGE, serviceException.getMessage());
assertEquals(REASON, serviceException.getReason());
assertFalse(serviceException.isRetryable());
assertNull(serviceException.getCause());
serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS);
assertEquals(CODE, serviceException.getCode());
assertEquals(MESSAGE, serviceException.getMessage());
assertEquals(REASON, serviceException.getReason());
assertFalse(serviceException.isRetryable());
assertNull(serviceException.getCause());
Exception cause = new RuntimeException();
serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS, cause);
assertEquals(CODE, serviceException.getCode());
assertEquals(MESSAGE, serviceException.getMessage());
assertEquals(REASON, serviceException.getReason());
assertFalse(serviceException.isRetryable());
assertEquals(cause, serviceException.getCause());
serviceException = new BaseHttpServiceException(CODE, MESSAGE, REASON, NOT_IDEMPOTENT, EMPTY_RETRYABLE_ERRORS, cause);
assertEquals(CODE, serviceException.getCode());
assertEquals(MESSAGE, serviceException.getMessage());
assertEquals(REASON, serviceException.getReason());
assertFalse(serviceException.isRetryable());
assertEquals(cause, serviceException.getCause());
IOException exception = new SocketTimeoutException();
serviceException = new BaseHttpServiceException(exception, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS);
assertTrue(serviceException.isRetryable());
assertNull(serviceException.getMessage());
assertEquals(exception, serviceException.getCause());
exception = new SocketException();
serviceException = new BaseHttpServiceException(exception, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS);
assertTrue(serviceException.isRetryable());
assertNull(serviceException.getMessage());
assertEquals(exception, serviceException.getCause());
exception = new IOException("insufficient data written");
serviceException = new BaseHttpServiceException(exception, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS);
assertTrue(serviceException.isRetryable());
assertEquals("insufficient data written", serviceException.getMessage());
assertEquals(exception, serviceException.getCause());
GoogleJsonError error = new GoogleJsonError();
error.setCode(CODE);
error.setMessage(MESSAGE);
serviceException = new BaseHttpServiceException(error, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS);
assertEquals(CODE, serviceException.getCode());
assertEquals(MESSAGE, serviceException.getMessage());
assertFalse(serviceException.isRetryable());
serviceException = new CustomServiceException(CODE, MESSAGE, REASON, IDEMPOTENT);
assertEquals(CODE, serviceException.getCode());
assertEquals(MESSAGE, serviceException.getMessage());
assertEquals(REASON, serviceException.getReason());
assertEquals(RETRYABLE, serviceException.isRetryable());
serviceException = new CustomServiceException(CODE_NO_REASON, MESSAGE, null, IDEMPOTENT);
assertEquals(CODE_NO_REASON, serviceException.getCode());
assertEquals(MESSAGE, serviceException.getMessage());
assertNull(serviceException.getReason());
assertEquals(RETRYABLE, serviceException.isRetryable());
serviceException = new CustomServiceException(UNKNOWN_CODE, MESSAGE, REASON, IDEMPOTENT);
assertEquals(UNKNOWN_CODE, serviceException.getCode());
assertEquals(MESSAGE, serviceException.getMessage());
assertEquals(REASON, serviceException.getReason());
assertEquals(RETRYABLE, serviceException.isRetryable());
}
use of com.google.cloud.BaseServiceException in project google-cloud-java by GoogleCloudPlatform.
the class BaseHttpServiceExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
BaseServiceException cause = new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS);
RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
BaseServiceException.translate(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(CODE, ex.getCode());
assertEquals(MESSAGE, ex.getMessage());
assertFalse(ex.isRetryable());
} finally {
verify(exceptionMock);
}
}
Aggregations