@Test public void testShouldTry() { ExceptionHandler handler = ExceptionHandler.newBuilder().retryOn(IOException.class).build(); assertTrue(handler.shouldRetry(new IOException(), null)); assertTrue(handler.shouldRetry(new ClosedByInterruptException(), null)); InterruptedException.class); handler = builder.build(); assertTrue(handler.shouldRetry(new IOException(), null)); assertFalse(handler.shouldRetry(new ClosedByInterruptException(), null)); handler = builder.build(); assertFalse(handler.shouldRetry(new IOException(), null)); assertFalse(handler.shouldRetry(new ClosedByInterruptException(), null));
@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.shouldRetry(new Exception(), null); }
@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.shouldRetry(new Exception(), null); } }
@Override public void start() throws IOException { ExceptionHandler retryOnAnythingExceptionHandler = ExceptionHandler.newBuilder().retryOn(Exception.class).build(); Path emulatorPath = RetryHelper.runWithRetries( new Callable<Path>() { @Override public Path call() throws IOException { return downloadEmulator(); } }, ServiceOptions.getDefaultRetrySettings(), retryOnAnythingExceptionHandler, CurrentMillisClock.getDefaultClock()); process = CommandWrapper.create() .setCommand(commandText) .setDirectory(emulatorPath) // gcloud redirects all output to stderr while emulators' executables use either // stdout // or stderr with no apparent convention. To be able to properly intercept and block // waiting for emulators to be ready we redirect everything to stdout .setRedirectErrorStream() .start(); }
public static ExceptionHandler build() { return ExceptionHandler.newBuilder() .abortOn(RuntimeException.class) .addInterceptors( DatastoreImpl.EXCEPTION_HANDLER_INTERCEPTOR, TRANSACTION_EXCEPTION_HANDLER_INTERCEPTOR) .build(); }
ExceptionHandler.newBuilder() .retryOn(FileNotFoundException.class, NullPointerException.class) .build(); assertInvalidCallable(new A(), handler); assertInvalidCallable(new B(), handler);
.abortOn(RuntimeException.class) .addInterceptors(DatastoreImpl.EXCEPTION_HANDLER_INTERCEPTOR) .build(); ExceptionHandler transactionHandler = TransactionExceptionHandler.build();
@Override public void start() throws IOException { ExceptionHandler retryOnAnythingExceptionHandler = ExceptionHandler.newBuilder().retryOn(Exception.class).build(); Path emulatorPath = RetryHelper.runWithRetries( new Callable<Path>() { @Override public Path call() throws IOException { return downloadEmulator(); } }, ServiceOptions.getDefaultRetrySettings(), retryOnAnythingExceptionHandler, CurrentMillisClock.getDefaultClock()); process = CommandWrapper.create() .setCommand(commandText) .setDirectory(emulatorPath) // gcloud redirects all output to stderr while emulators' executables use either // stdout // or stderr with no apparent convention. To be able to properly intercept and block // waiting for emulators to be ready we redirect everything to stdout .setRedirectErrorStream() .start(); }
public static ExceptionHandler build() { return ExceptionHandler.newBuilder() .abortOn(RuntimeException.class) .addInterceptors( DatastoreImpl.EXCEPTION_HANDLER_INTERCEPTOR, TRANSACTION_EXCEPTION_HANDLER_INTERCEPTOR) .build(); }