} catch (RetryException e) { LOG.warn("Tried to update session 10 times, but still failed. This is likely because of https://jira.mongodb.org/browse/SERVER-14322", e); throw new RuntimeException(e.getCause());
metrics.error(); LOG.warn("{} Couldn't upload or delete {}", logIdentifier, file, re); exceptionNotifier.notify(String.format("%s exception during upload", re.getCause().getClass()), re.getCause(), ImmutableMap.of("logIdentifier", logIdentifier, "file", file.toString(), "failedAttempts", Integer.toString(re.getNumberOfFailedAttempts()))); } catch (Exception e) { metrics.error();
} catch (RetryException e) { LOG.warn("Tried to update session 10 times, but still failed. This is likely because of https://jira.mongodb.org/browse/SERVER-14322", e); throw new RuntimeException(e.getCause());
} catch (RetryException e) { throw new DirectiveExecutionException( String.format("Issue in retrieving schema from schema registry. %s", e.getCause()) );
} catch (RetryException e) { throw new DirectiveExecutionException( String.format("Issue in retrieving protobuf descriptor from schema registry. %s", e.getCause()) );
@ParameterizedTest @MethodSource("unchecked") void testRunThrowsWithNoRetryOnException(Class<? extends Throwable> throwable) throws Exception { Retryer retryer = RetryerBuilder.newBuilder().build(); Thrower thrower = new Thrower(throwable, 5); try { retryer.run(thrower); fail("Should have thrown"); } catch (RetryException e) { assertSame(e.getCause().getClass(), throwable); } assertEquals(1, thrower.invocations); }
@ParameterizedTest @MethodSource("checkedAndUnchecked") void testCallThrowsWithNoRetryOnException(Class<? extends Throwable> throwable) throws Exception { Retryer retryer = RetryerBuilder.newBuilder().build(); Thrower thrower = new Thrower(throwable, 5); try { retryer.call(thrower); fail("Should have thrown"); } catch (RetryException e) { assertSame(e.getCause().getClass(), throwable); } assertEquals(1, thrower.invocations); }
@ParameterizedTest @MethodSource("unchecked") void testRunThrowsWhenRetriesAreStopped(Class<? extends Throwable> throwable) throws Exception { Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(throwable) .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .build(); Thrower thrower = new Thrower(throwable, 5); try { retryer.run(thrower); fail("Should have thrown"); } catch (RetryException e) { assertSame(e.getCause().getClass(), throwable); } assertEquals(3, thrower.invocations); }
@ParameterizedTest @MethodSource("checkedAndUnchecked") void testCallThrowsWhenRetriesAreStopped(Class<? extends Throwable> throwable) throws Exception { Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(throwable) .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .build(); Thrower thrower = new Thrower(throwable, 5); try { retryer.call(thrower); fail("Should have thrown"); } catch (RetryException e) { assertSame(e.getCause().getClass(), throwable); } assertEquals(3, thrower.invocations); }
@Test public void testRetryIfResult() throws Exception { Callable<Boolean> callable = notNullAfter5Attempts(); Retryer retryer = RetryerBuilder.newBuilder() .retryIfResult(Objects::isNull) .build(); assertTrue(retryer.call(callable)); callable = notNullAfter5Attempts(); retryer = RetryerBuilder.newBuilder() .retryIfResult(Objects::isNull) .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .build(); try { retryer.call(callable); fail("Exception expected"); } catch (RetryException e) { assertEquals(3, e.getNumberOfFailedAttempts()); assertTrue(e.getLastFailedAttempt().hasResult()); assertNull(e.getLastFailedAttempt().getResult()); assertNull(e.getCause()); } }