Skip to content

Commit 800b709

Browse files
author
Ajay Kannan
committed
Rename RetryResult enum values, and update datastore and storage interceptor.
1 parent af6bbef commit 800b709

4 files changed

Lines changed: 39 additions & 39 deletions

File tree

gcloud-java-core/src/main/java/com/google/gcloud/ExceptionHandler.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ public final class ExceptionHandler implements Serializable {
4747
public interface Interceptor extends Serializable {
4848

4949
enum RetryResult {
50-
ABORT, RETRY, PROCEED;
50+
NO_RETRY, RETRY, CONTINUE_EVALUATION;
5151
}
5252

5353
/**
5454
* This method is called before exception evaluation and could short-circuit the process.
5555
*
5656
* @param exception the exception that is being evaluated
5757
* @return {@link RetryResult} to indicate if the exception should be ignored (
58-
* {@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}), or evaluation
59-
* should proceed ({@link RetryResult#PROCEED}).
58+
* {@link RetryResult#RETRY}), propagated ({@link RetryResult#NO_RETRY}), or evaluation
59+
* should proceed ({@link RetryResult#CONTINUE_EVALUATION}).
6060
*/
6161
RetryResult beforeEval(Exception exception);
6262

@@ -66,8 +66,8 @@ enum RetryResult {
6666
* @param exception the exception that is being evaluated
6767
* @param retryResult the result of the evaluation so far.
6868
* @return {@link RetryResult} to indicate if the exception should be ignored (
69-
* {@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}), or evaluation
70-
* should proceed ({@link RetryResult#PROCEED}).
69+
* {@link RetryResult#RETRY}), propagated ({@link RetryResult#NO_RETRY}), or evaluation
70+
* should proceed ({@link RetryResult#CONTINUE_EVALUATION}).
7171
*/
7272
RetryResult afterEval(Exception exception, RetryResult retryResult);
7373
}
@@ -177,7 +177,7 @@ private ExceptionHandler(Builder builder) {
177177
addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.RETRY), retryInfo);
178178
}
179179
for (Class<? extends Exception> exception : nonRetriableExceptions) {
180-
addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.ABORT), retryInfo);
180+
addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.NO_RETRY), retryInfo);
181181
}
182182
}
183183

@@ -242,17 +242,17 @@ public Set<Class<? extends Exception>> getNonRetriableExceptions() {
242242
boolean shouldRetry(Exception ex) {
243243
for (Interceptor interceptor : interceptors) {
244244
Interceptor.RetryResult retryResult = checkNotNull(interceptor.beforeEval(ex));
245-
if (retryResult != Interceptor.RetryResult.PROCEED) {
246-
return interceptor.beforeEval(ex) == Interceptor.RetryResult.RETRY;
245+
if (retryResult != Interceptor.RetryResult.CONTINUE_EVALUATION) {
246+
return retryResult == Interceptor.RetryResult.RETRY;
247247
}
248248
}
249249
RetryInfo retryInfo = findMostSpecificRetryInfo(this.retryInfo, ex.getClass());
250250
Interceptor.RetryResult retryResult =
251-
retryInfo == null ? Interceptor.RetryResult.ABORT : retryInfo.retry;
251+
retryInfo == null ? Interceptor.RetryResult.NO_RETRY : retryInfo.retry;
252252
for (Interceptor interceptor : interceptors) {
253253
Interceptor.RetryResult interceptorRetry =
254254
checkNotNull(interceptor.afterEval(ex, retryResult));
255-
if (interceptorRetry != Interceptor.RetryResult.PROCEED) {
255+
if (interceptorRetry != Interceptor.RetryResult.CONTINUE_EVALUATION) {
256256
retryResult = interceptorRetry;
257257
}
258258
}

gcloud-java-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.google.gcloud.ExceptionHandler.Interceptor;
2424
import com.google.gcloud.ExceptionHandler.Interceptor.RetryResult;
2525

26+
import org.junit.rules.ExpectedException;
27+
import org.junit.Rule;
2628
import org.junit.Test;
2729

2830
import java.io.FileNotFoundException;
@@ -36,6 +38,9 @@
3638
*/
3739
public class ExceptionHandlerTest {
3840

41+
@Rule
42+
public ExpectedException thrown = ExpectedException.none();
43+
3944
@Test
4045
public void testVerifyCaller() {
4146
class A implements Callable<Object> {
@@ -128,13 +133,13 @@ public void testShouldTry() {
128133
assertFalse(handler.shouldRetry(new RuntimeException()));
129134
assertTrue(handler.shouldRetry(new NullPointerException()));
130135

131-
final AtomicReference<RetryResult> before = new AtomicReference<>(RetryResult.ABORT);
136+
final AtomicReference<RetryResult> before = new AtomicReference<>(RetryResult.NO_RETRY);
132137
@SuppressWarnings("serial")
133138
Interceptor interceptor = new Interceptor() {
134139

135140
@Override
136141
public RetryResult afterEval(Exception exception, RetryResult retryResult) {
137-
return retryResult == RetryResult.ABORT ? RetryResult.RETRY : RetryResult.ABORT;
142+
return retryResult == RetryResult.NO_RETRY ? RetryResult.RETRY : RetryResult.NO_RETRY;
138143
}
139144

140145
@Override
@@ -158,7 +163,7 @@ public RetryResult beforeEval(Exception exception) {
158163
assertTrue(handler.shouldRetry(new RuntimeException()));
159164
assertTrue(handler.shouldRetry(new NullPointerException()));
160165

161-
before.set(RetryResult.PROCEED);
166+
before.set(RetryResult.CONTINUE_EVALUATION);
162167
assertFalse(handler.shouldRetry(new IOException()));
163168
assertTrue(handler.shouldRetry(new ClosedByInterruptException()));
164169
assertTrue(handler.shouldRetry(new InterruptedException()));
@@ -167,9 +172,9 @@ public RetryResult beforeEval(Exception exception) {
167172
}
168173

169174
@Test
170-
public void testNullRetryResult() {
175+
public void testNullRetryResultFromBeforeEval() {
171176
@SuppressWarnings("serial")
172-
Interceptor interceptor1 = new Interceptor() {
177+
Interceptor interceptor = new Interceptor() {
173178

174179
@Override
175180
public RetryResult beforeEval(Exception exception) {
@@ -178,17 +183,24 @@ public RetryResult beforeEval(Exception exception) {
178183

179184
@Override
180185
public RetryResult afterEval(Exception exception, RetryResult retryResult) {
181-
return RetryResult.PROCEED;
186+
return RetryResult.CONTINUE_EVALUATION;
182187
}
183188

184189
};
185190

191+
ExceptionHandler handler = ExceptionHandler.builder().interceptor(interceptor).build();
192+
thrown.expect(NullPointerException.class);
193+
handler.shouldRetry(new Exception());
194+
}
195+
196+
@Test
197+
public void testNullRetryResultFromAfterEval() {
186198
@SuppressWarnings("serial")
187-
Interceptor interceptor2 = new Interceptor() {
199+
Interceptor interceptor = new Interceptor() {
188200

189201
@Override
190202
public RetryResult beforeEval(Exception exception) {
191-
return RetryResult.PROCEED;
203+
return RetryResult.CONTINUE_EVALUATION;
192204
}
193205

194206
@Override
@@ -198,20 +210,8 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) {
198210

199211
};
200212

201-
ExceptionHandler handler1 = ExceptionHandler.builder().interceptor(interceptor1).build();
202-
try {
203-
handler1.shouldRetry(new Exception());
204-
fail("Expected null pointer exception due to null RetryResult from beforeEval");
205-
} catch (NullPointerException e) {
206-
// expected
207-
}
208-
209-
ExceptionHandler handler2 = ExceptionHandler.builder().interceptor(interceptor2).build();
210-
try {
211-
handler2.shouldRetry(new Exception());
212-
fail("Expected null pointer exception due to null RetryResult from afterEval");
213-
} catch (NullPointerException e) {
214-
// expected
215-
}
213+
ExceptionHandler handler = ExceptionHandler.builder().interceptor(interceptor).build();
214+
thrown.expect(NullPointerException.class);
215+
handler.shouldRetry(new Exception());
216216
}
217217
}

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ final class DatastoreImpl extends BaseService<DatastoreOptions>
5353

5454
@Override
5555
public RetryResult afterEval(Exception exception, RetryResult retryResult) {
56-
return Interceptor.RetryResult.PROCEED;
56+
return Interceptor.RetryResult.CONTINUE_EVALUATION;
5757
}
5858

5959
@Override
6060
public RetryResult beforeEval(Exception exception) {
6161
if (exception instanceof DatastoreRpcException) {
6262
boolean retryable = ((DatastoreRpcException) exception).retryable();
63-
return retryable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.ABORT;
63+
return retryable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.NO_RETRY;
6464
}
65-
return Interceptor.RetryResult.PROCEED;
65+
return Interceptor.RetryResult.CONTINUE_EVALUATION;
6666
}
6767
};
6868
private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.builder()

gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ final class StorageImpl extends BaseService<StorageOptions> implements Storage {
7272

7373
@Override
7474
public RetryResult afterEval(Exception exception, RetryResult retryResult) {
75-
return null;
75+
return Interceptor.RetryResult.CONTINUE_EVALUATION;
7676
}
7777

7878
@Override
7979
public RetryResult beforeEval(Exception exception) {
8080
if (exception instanceof StorageException) {
8181
boolean retriable = ((StorageException) exception).retryable();
82-
return retriable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.ABORT;
82+
return retriable ? Interceptor.RetryResult.RETRY : Interceptor.RetryResult.NO_RETRY;
8383
}
84-
return null;
84+
return Interceptor.RetryResult.CONTINUE_EVALUATION;
8585
}
8686
};
8787
static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.builder()

0 commit comments

Comments
 (0)