SlidingWindowRetryPolicy { public boolean shouldRetry(RetryContext retryContext, int errorCode) { ContainerRetryContext containerRC = retryContext.containerRetryContext; Preconditions.checkNotNull(containerRC, "container retry context null"); ContainerRetryPolicy retryPolicy = containerRC.getRetryPolicy(); if (retryPolicy == ContainerRetryPolicy.RETRY_ON_ALL_ERRORS || (retryPolicy == ContainerRetryPolicy.RETRY_ON_SPECIFIC_ERROR_CODES && containerRC.getErrorCodes() != null && containerRC.getErrorCodes().contains(errorCode))) { return containerRC.getMaxRetries() == ContainerRetryContext.RETRY_FOREVER || calculateRemainingRetries(retryContext) > 0; } return false; } SlidingWindowRetryPolicy(Clock clock); boolean shouldRetry(RetryContext retryContext,
      int errorCode); void setClock(Clock clock);  }
@Test public void testNeverRetry() { ContainerRetryContext retryContext = ContainerRetryContext.NEVER_RETRY_CONTEXT; SlidingWindowRetryPolicy.RetryContext windowContext = new SlidingWindowRetryPolicy.RetryContext(retryContext); Assert.assertFalse("never retry", retryPolicy.shouldRetry(windowContext, 12)); Assert.assertEquals("remaining retries", 0, windowContext.getRemainingRetries()); }
@Test public void testAlwaysRetry() { ContainerRetryContext retryContext = ContainerRetryContext.newInstance( ContainerRetryPolicy.RETRY_ON_ALL_ERRORS, null, -1, 0, 10); SlidingWindowRetryPolicy.RetryContext windowContext = new SlidingWindowRetryPolicy.RetryContext(retryContext); Assert.assertTrue("always retry", retryPolicy.shouldRetry(windowContext, 12)); Assert.assertEquals("remaining retries", ContainerRetryContext.RETRY_FOREVER, windowContext.getRemainingRetries()); }