use of com.google.cloud.ExceptionHandler.Interceptor in project google-cloud-java by GoogleCloudPlatform.
the class ExceptionHandlerTest method testNullRetryResultFromBeforeEval.
@Test
public void testNullRetryResultFromBeforeEval() {
@SuppressWarnings("serial") Interceptor interceptor = new Interceptor() {
@Override
public RetryResult beforeEval(Exception exception) {
return null;
}
@Override
public RetryResult afterEval(Exception exception, RetryResult retryResult) {
return RetryResult.CONTINUE_EVALUATION;
}
};
ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build();
thrown.expect(NullPointerException.class);
handler.accept(new Exception());
}
use of com.google.cloud.ExceptionHandler.Interceptor in project google-cloud-java by GoogleCloudPlatform.
the class ExceptionHandlerTest method testNullRetryResultFromAfterEval.
@Test
public void testNullRetryResultFromAfterEval() {
@SuppressWarnings("serial") Interceptor interceptor = new Interceptor() {
@Override
public RetryResult beforeEval(Exception exception) {
return RetryResult.CONTINUE_EVALUATION;
}
@Override
public RetryResult afterEval(Exception exception, RetryResult retryResult) {
return null;
}
};
ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build();
thrown.expect(NullPointerException.class);
handler.accept(new Exception());
}
use of com.google.cloud.ExceptionHandler.Interceptor in project google-cloud-java by GoogleCloudPlatform.
the class ExceptionHandlerTest method testShouldTry.
@Test
public void testShouldTry() {
ExceptionHandler handler = ExceptionHandler.newBuilder().retryOn(IOException.class).build();
assertTrue(handler.accept(new IOException()));
assertTrue(handler.accept(new ClosedByInterruptException()));
assertFalse(handler.accept(new RuntimeException()));
ExceptionHandler.Builder builder = ExceptionHandler.newBuilder().retryOn(IOException.class, NullPointerException.class).abortOn(RuntimeException.class, ClosedByInterruptException.class, InterruptedException.class);
handler = builder.build();
assertTrue(handler.accept(new IOException()));
assertFalse(handler.accept(new ClosedByInterruptException()));
assertFalse(handler.accept(new InterruptedException()));
assertFalse(handler.accept(new RuntimeException()));
assertTrue(handler.accept(new NullPointerException()));
final AtomicReference<RetryResult> before = new AtomicReference<>(RetryResult.NO_RETRY);
@SuppressWarnings("serial") Interceptor interceptor = new Interceptor() {
@Override
public RetryResult afterEval(Exception exception, RetryResult retryResult) {
return retryResult == RetryResult.NO_RETRY ? RetryResult.RETRY : RetryResult.NO_RETRY;
}
@Override
public RetryResult beforeEval(Exception exception) {
return before.get();
}
};
builder.addInterceptors(interceptor);
handler = builder.build();
assertFalse(handler.accept(new IOException()));
assertFalse(handler.accept(new ClosedByInterruptException()));
assertFalse(handler.accept(new InterruptedException()));
assertFalse(handler.accept(new RuntimeException()));
assertFalse(handler.accept(new NullPointerException()));
before.set(RetryResult.RETRY);
assertTrue(handler.accept(new IOException()));
assertTrue(handler.accept(new ClosedByInterruptException()));
assertTrue(handler.accept(new InterruptedException()));
assertTrue(handler.accept(new RuntimeException()));
assertTrue(handler.accept(new NullPointerException()));
before.set(RetryResult.CONTINUE_EVALUATION);
assertFalse(handler.accept(new IOException()));
assertTrue(handler.accept(new ClosedByInterruptException()));
assertTrue(handler.accept(new InterruptedException()));
assertTrue(handler.accept(new RuntimeException()));
assertFalse(handler.accept(new NullPointerException()));
}
Aggregations