From d2c24a97f974fbaede5b2e2c634df0dee27d4ef2 Mon Sep 17 00:00:00 2001 From: vam Date: Mon, 20 Mar 2017 17:14:12 -0700 Subject: [PATCH] Reverted ExceptionHandler rename. --- .../java/com/google/cloud/BaseService.java | 49 +++++++++---------- ...ryAlgorithm.java => ExceptionHandler.java} | 20 ++++---- .../java/com/google/cloud/RetryHelper.java | 2 +- ...thmTest.java => ExceptionHandlerTest.java} | 24 ++++----- .../com/google/cloud/SerializationTest.java | 3 +- 5 files changed, 48 insertions(+), 50 deletions(-) rename google-cloud-core/src/main/java/com/google/cloud/{HttpExceptionRetryAlgorithm.java => ExceptionHandler.java} (94%) rename google-cloud-core/src/test/java/com/google/cloud/{HttpExceptionRetryAlgorithmTest.java => ExceptionHandlerTest.java} (87%) diff --git a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java index 7b7caa5de2b8..619341bc3729 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/BaseService.java +++ b/google-cloud-core/src/main/java/com/google/cloud/BaseService.java @@ -16,7 +16,7 @@ package com.google.cloud; -import com.google.cloud.HttpExceptionRetryAlgorithm.Interceptor; +import com.google.cloud.ExceptionHandler.Interceptor; /** * Base class for service objects. @@ -26,30 +26,28 @@ public abstract class BaseService> implements Service { - public static final Interceptor EXCEPTION_HANDLER_INTERCEPTOR = - new Interceptor() { - - private static final long serialVersionUID = -8429573486870467828L; - - @Override - public RetryResult afterEval(Exception exception, RetryResult retryResult) { - return Interceptor.RetryResult.CONTINUE_EVALUATION; - } - - @Override - public RetryResult beforeEval(Exception exception) { - if (exception instanceof BaseServiceException) { - boolean retriable = ((BaseServiceException) exception).isRetryable(); - return retriable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.NO_RETRY; - } - return Interceptor.RetryResult.CONTINUE_EVALUATION; - } - }; - public static final HttpExceptionRetryAlgorithm EXCEPTION_HANDLER = - HttpExceptionRetryAlgorithm.newBuilder() - .abortOn(RuntimeException.class) - .addInterceptors(EXCEPTION_HANDLER_INTERCEPTOR) - .build(); + public static final Interceptor EXCEPTION_HANDLER_INTERCEPTOR = new Interceptor() { + + private static final long serialVersionUID = -8429573486870467828L; + + @Override + public RetryResult afterEval(Exception exception, RetryResult retryResult) { + return Interceptor.RetryResult.CONTINUE_EVALUATION; + } + + @Override + public RetryResult beforeEval(Exception exception) { + if (exception instanceof BaseServiceException) { + boolean retriable = ((BaseServiceException) exception).isRetryable(); + return retriable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.NO_RETRY; + } + return Interceptor.RetryResult.CONTINUE_EVALUATION; + } + }; + public static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.newBuilder() + .abortOn(RuntimeException.class) + .addInterceptors(EXCEPTION_HANDLER_INTERCEPTOR) + .build(); private final OptionsT options; @@ -57,6 +55,7 @@ protected BaseService(OptionsT options) { this.options = options; } + @Override public OptionsT getOptions() { return options; diff --git a/google-cloud-core/src/main/java/com/google/cloud/HttpExceptionRetryAlgorithm.java b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java similarity index 94% rename from google-cloud-core/src/main/java/com/google/cloud/HttpExceptionRetryAlgorithm.java rename to google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java index e5d3e908cf0d..81703b561285 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/HttpExceptionRetryAlgorithm.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ExceptionHandler.java @@ -35,11 +35,11 @@ /** * Exception retry algorithm implementation used by {@link RetryHelper}. */ -public final class HttpExceptionRetryAlgorithm implements ExceptionRetryAlgorithm, Serializable { +public final class ExceptionHandler implements ExceptionRetryAlgorithm, Serializable { private static final long serialVersionUID = -2460707015779532919L; - private static final HttpExceptionRetryAlgorithm DEFAULT_INSTANCE = + private static final ExceptionHandler DEFAULT_INSTANCE = newBuilder().retryOn(Exception.class).abortOn(RuntimeException.class).build(); private final ImmutableList interceptors; @@ -76,7 +76,7 @@ enum RetryResult { } /** - * HttpExceptionRetryAlgorithm builder. + * ExceptionHandler builder. */ public static class Builder { @@ -132,10 +132,10 @@ public final Builder abortOn(Class... exceptions) { } /** - * Returns a new HttpExceptionRetryAlgorithm instance. + * Returns a new ExceptionHandler instance. */ - public HttpExceptionRetryAlgorithm build() { - return new HttpExceptionRetryAlgorithm(this); + public ExceptionHandler build() { + return new ExceptionHandler(this); } } @@ -170,7 +170,7 @@ public boolean equals(Object obj) { } } - private HttpExceptionRetryAlgorithm(Builder builder) { + private ExceptionHandler(Builder builder) { interceptors = builder.interceptors.build(); retriableExceptions = builder.retriableExceptions.build(); nonRetriableExceptions = builder.nonRetriableExceptions.build(); @@ -278,10 +278,10 @@ public boolean equals(Object obj) { if (obj == this) { return true; } - if (!(obj instanceof HttpExceptionRetryAlgorithm)) { + if (!(obj instanceof ExceptionHandler)) { return false; } - HttpExceptionRetryAlgorithm other = (HttpExceptionRetryAlgorithm) obj; + ExceptionHandler other = (ExceptionHandler) obj; return Objects.equals(interceptors, other.interceptors) && Objects.equals(retriableExceptions, other.retriableExceptions) && Objects.equals(nonRetriableExceptions, other.nonRetriableExceptions) @@ -292,7 +292,7 @@ public boolean equals(Object obj) { /** * Returns an instance which retry any checked exception and abort on any runtime exception. */ - public static HttpExceptionRetryAlgorithm getDefaultInstance() { + public static ExceptionHandler getDefaultInstance() { return DEFAULT_INSTANCE; } diff --git a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java index 6372518bce79..6d36096bb68b 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/google-cloud-core/src/main/java/com/google/cloud/RetryHelper.java @@ -35,7 +35,7 @@ public class RetryHelper { public static V runWithRetries( Callable callable, RetrySettings retrySettings, - HttpExceptionRetryAlgorithm exceptionRetryAlgorithm, + ExceptionHandler exceptionRetryAlgorithm, ApiClock clock) throws RetryHelperException { try { diff --git a/google-cloud-core/src/test/java/com/google/cloud/HttpExceptionRetryAlgorithmTest.java b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java similarity index 87% rename from google-cloud-core/src/test/java/com/google/cloud/HttpExceptionRetryAlgorithmTest.java rename to google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java index 8d8fb1f5f0dc..c78f7773d3fb 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/HttpExceptionRetryAlgorithmTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/ExceptionHandlerTest.java @@ -20,8 +20,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.cloud.HttpExceptionRetryAlgorithm.Interceptor; -import com.google.cloud.HttpExceptionRetryAlgorithm.Interceptor.RetryResult; +import com.google.cloud.ExceptionHandler.Interceptor; +import com.google.cloud.ExceptionHandler.Interceptor.RetryResult; import org.junit.Rule; import org.junit.Test; @@ -34,9 +34,9 @@ import java.util.concurrent.atomic.AtomicReference; /** - * Tests for {@link HttpExceptionRetryAlgorithm}. + * Tests for {@link ExceptionHandler}. */ -public class HttpExceptionRetryAlgorithmTest { +public class ExceptionHandlerTest { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -82,7 +82,7 @@ public Object call() throws Error { } // using default exception handler (retry upon any non-runtime exceptions) - HttpExceptionRetryAlgorithm handler = HttpExceptionRetryAlgorithm.getDefaultInstance(); + ExceptionHandler handler = ExceptionHandler.getDefaultInstance(); assertValidCallable(new A(), handler); assertValidCallable(new B(), handler); assertValidCallable(new C(), handler); @@ -90,7 +90,7 @@ public Object call() throws Error { assertValidCallable(new E(), handler); assertInvalidCallable(new F(), handler); - handler = HttpExceptionRetryAlgorithm.newBuilder() + handler = ExceptionHandler.newBuilder() .retryOn(FileNotFoundException.class, NullPointerException.class) .build(); assertInvalidCallable(new A(), handler); @@ -101,11 +101,11 @@ public Object call() throws Error { assertInvalidCallable(new F(), handler); } - private static void assertValidCallable(Callable callable, HttpExceptionRetryAlgorithm handler) { + private static void assertValidCallable(Callable callable, ExceptionHandler handler) { handler.verifyCaller(callable); } - private static void assertInvalidCallable(Callable callable, HttpExceptionRetryAlgorithm handler) { + private static void assertInvalidCallable(Callable callable, ExceptionHandler handler) { try { handler.verifyCaller(callable); fail("Expected RetryHelper constructor to fail"); @@ -116,12 +116,12 @@ private static void assertInvalidCallable(Callable callable, HttpExceptio @Test public void testShouldTry() { - HttpExceptionRetryAlgorithm handler = HttpExceptionRetryAlgorithm.newBuilder().retryOn(IOException.class).build(); + ExceptionHandler handler = ExceptionHandler.newBuilder().retryOn(IOException.class).build(); assertTrue(handler.accept(new IOException())); assertTrue(handler.accept(new ClosedByInterruptException())); assertFalse(handler.accept(new RuntimeException())); - HttpExceptionRetryAlgorithm.Builder builder = HttpExceptionRetryAlgorithm.newBuilder() + ExceptionHandler.Builder builder = ExceptionHandler.newBuilder() .retryOn(IOException.class, NullPointerException.class) .abortOn(RuntimeException.class, ClosedByInterruptException.class, InterruptedException.class); @@ -188,7 +188,7 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { }; - HttpExceptionRetryAlgorithm handler = HttpExceptionRetryAlgorithm.newBuilder().addInterceptors(interceptor).build(); + ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); handler.accept(new Exception()); } @@ -210,7 +210,7 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) { }; - HttpExceptionRetryAlgorithm handler = HttpExceptionRetryAlgorithm.newBuilder().addInterceptors(interceptor).build(); + ExceptionHandler handler = ExceptionHandler.newBuilder().addInterceptors(interceptor).build(); thrown.expect(NullPointerException.class); handler.accept(new Exception()); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 44c510a3c984..11bdae8b2807 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -29,8 +29,7 @@ public class SerializationTest extends BaseSerializationTest { private static final BaseServiceException BASE_SERVICE_EXCEPTION = new BaseServiceException(42, "message", "reason", true); - private static final HttpExceptionRetryAlgorithm EXCEPTION_HANDLER = - HttpExceptionRetryAlgorithm.getDefaultInstance(); + private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.getDefaultInstance(); private static final Identity IDENTITY = Identity.allAuthenticatedUsers(); private static final PageImpl PAGE = new PageImpl<>(null, "cursor", ImmutableList.of("string1", "string2"));