@Test public void checksAreRetried() throws Exception { configGenerator.setProperty(BackingServiceConfigurator.PARAM_RETRY_POLICY_ENABLED,"true"); FakeCheck.setReady(false); try { configGenerator.verifyInstallation(); } catch (ConfigurationException e) { } assertThat(FakeCheck.getCallCount()).isEqualTo(6); configGenerator.setProperty(BackingServiceConfigurator.PARAM_RETRY_POLICY_ENABLED,"false"); FakeCheck.reset(); try { configGenerator.verifyInstallation(); } catch (ConfigurationException e) { } assertThat(FakeCheck.getCallCount()).isEqualTo(1); }
public void verifyInstallation() throws ConfigurationException { RetryPolicy retryPolicy = buildRetryPolicy(); for (BackingChecker checker : getCheckers()) { if (checker.accepts(configurationGenerator)) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(checker.getClass().getClassLoader()); Failsafe.with(retryPolicy) .onFailedAttempt(failure -> log.error(failure.getMessage(), failure)) .onRetry((c, f, ctx) -> log.warn(String.format("Failure %d. Retrying....", ctx.getExecutions()))) .run(() -> checker.check(configurationGenerator)); } catch (FailsafeException e) { if (e.getCause() instanceof ConfigurationException) { throw ((ConfigurationException) e.getCause()); } else { throw e; } } finally { Thread.currentThread().setContextClassLoader(classLoader); } } } }
BackingServiceConfigurator { public void verifyInstallation() throws ConfigurationException { RetryPolicy retryPolicy = buildRetryPolicy(); for (BackingChecker checker : getCheckers()) { if (checker.accepts(configurationGenerator)) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(checker.getClass().getClassLoader()); Failsafe.with(retryPolicy) .onFailedAttempt(failure -> log.error(failure.getMessage(), failure)) .onRetry((c, f, ctx) -> log.warn(String.format("Failure %d. Retrying....", ctx.getExecutions()))) .run(() -> checker.check(configurationGenerator)); } catch (FailsafeException e) { if (e.getCause() instanceof ConfigurationException) { throw ((ConfigurationException) e.getCause()); } else { throw e; } } finally { Thread.currentThread().setContextClassLoader(classLoader); } } } } }
BackingServiceConfigurator { public void verifyInstallation() throws ConfigurationException { RetryPolicy retryPolicy = buildRetryPolicy(); for (BackingChecker checker : getCheckers()) { if (checker.accepts(configurationGenerator)) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(checker.getClass().getClassLoader()); Failsafe.with(retryPolicy) .onFailedAttempt(failure -> log.error(failure.getMessage(), failure)) .onRetry((c, f, ctx) -> log.warn(String.format("Failure %d. Retrying....", ctx.getExecutions()))) .run(() -> checker.check(configurationGenerator)); } catch (FailsafeException e) { if (e.getCause() instanceof ConfigurationException) { throw ((ConfigurationException) e.getCause()); } else { throw e; } } finally { Thread.currentThread().setContextClassLoader(classLoader); } } } } BackingServiceConfigurator(ConfigurationGenerator configurationGenerator); }
BackingServiceConfigurator { public void verifyInstallation() throws ConfigurationException { RetryPolicy retryPolicy = buildRetryPolicy(); for (BackingChecker checker : getCheckers()) { if (checker.accepts(configurationGenerator)) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(checker.getClass().getClassLoader()); Failsafe.with(retryPolicy) .onFailedAttempt(failure -> log.error(failure.getMessage(), failure)) .onRetry((c, f, ctx) -> log.warn(String.format("Failure %d. Retrying....", ctx.getExecutions()))) .run(() -> checker.check(configurationGenerator)); } catch (FailsafeException e) { if (e.getCause() instanceof ConfigurationException) { throw ((ConfigurationException) e.getCause()); } else { throw e; } } finally { Thread.currentThread().setContextClassLoader(classLoader); } } } } BackingServiceConfigurator(ConfigurationGenerator configurationGenerator); void verifyInstallation(); }
BackingServiceConfigurator { public void verifyInstallation() throws ConfigurationException { RetryPolicy retryPolicy = buildRetryPolicy(); for (BackingChecker checker : getCheckers()) { if (checker.accepts(configurationGenerator)) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(checker.getClass().getClassLoader()); Failsafe.with(retryPolicy) .onFailedAttempt(failure -> log.error(failure.getMessage(), failure)) .onRetry((c, f, ctx) -> log.warn(String.format("Failure %d. Retrying....", ctx.getExecutions()))) .run(() -> checker.check(configurationGenerator)); } catch (FailsafeException e) { if (e.getCause() instanceof ConfigurationException) { throw ((ConfigurationException) e.getCause()); } else { throw e; } } finally { Thread.currentThread().setContextClassLoader(classLoader); } } } } BackingServiceConfigurator(ConfigurationGenerator configurationGenerator); void verifyInstallation(); static final String PARAM_RETRY_POLICY_ENABLED; static final String PARAM_RETRY_POLICY_MAX_RETRIES; static final String PARAM_RETRY_POLICY_DELAY_IN_MS; static final String PARAM_POLICY_DEFAULT_DELAY_IN_MS; static final String PARAM_RETRY_POLICY_DEFAULT_RETRIES; static final String PARAM_CHECK_CLASSPATH_SUFFIX; static final String PARAM_CHECK_SUFFIX; }