private static RetryExecutor retryExecutor() { return RetryExecutor.retryExecutor() .withInitialRetryWait(0) .withMaxRetryWait(0); }
private static RetryExecutor retryExecutor() { return RetryExecutor.retryExecutor() .withInitialRetryWait(0) .withMaxRetryWait(0); }
/** * Build the common retry executor from some configuration params of plugin task. * @param task Plugin task. * @return RetryExecutor object */ private static RetryExecutor retryExecutorFrom(RetrySupportPluginTask task) { return retryExecutor() .withRetryLimit(task.getMaximumRetries()) .withInitialRetryWait(task.getInitialRetryIntervalMillis()) .withMaxRetryWait(task.getMaximumRetryIntervalMillis()); }
@Test public void reopenS3FileByReopener() throws Exception { String content = "value"; { // not retry doReturn(s3object("in/aa/a", content)).when(client).getObject(any(GetObjectRequest.class)); S3InputStreamReopener opener = new S3InputStreamReopener(client, new GetObjectRequest("my_bucket", "in/aa/a"), content.length()); try (InputStream in = opener.reopen(0, new RuntimeException())) { BufferedReader r = new BufferedReader(new InputStreamReader(in)); assertEquals("value", r.readLine()); } } { // retry once doThrow(new RuntimeException()).doReturn(s3object("in/aa/a", content)).when(client).getObject(any(GetObjectRequest.class)); S3InputStreamReopener opener = new S3InputStreamReopener( client, new GetObjectRequest("my_bucket", "in/aa/a"), content.length(), retryExecutor() .withInitialRetryWait(0) .withRetryLimit(1)); try (InputStream in = opener.reopen(0, new RuntimeException())) { BufferedReader r = new BufferedReader(new InputStreamReader(in)); assertEquals("value", r.readLine()); } } }
@Test(expected = AmazonClientException.class) public void reopenS3FileByReopener_on_retry_gave_up_should_throw_original_exception() throws Exception { String content = "value"; doThrow(new AmazonClientException("no")).doReturn(s3object("in/aa/a", content)).when(client).getObject(any(GetObjectRequest.class)); S3InputStreamReopener opener = new S3InputStreamReopener( client, new GetObjectRequest("my_bucket", "in/aa/a"), content.length(), retryExecutor() .withInitialRetryWait(0) .withRetryLimit(0)); opener.reopen(0, new RuntimeException()); }
@Test(expected = AmazonClientException.class) public void reopenS3FileByReopener_on_retry_always_throw_exception() throws Exception { // always failed call with 2 retries doThrow(new AmazonClientException("This exception is thrown when retrying.")).when(client).getObject(any(GetObjectRequest.class)); S3InputStreamReopener opener = new S3InputStreamReopener( client, new GetObjectRequest("my_bucket", "in/aa/a"), "value".length(), retryExecutor() .withInitialRetryWait(0) .withRetryLimit(2)); try (InputStream in = opener.reopen(0, new AmazonClientException("This exception can be ignored"))) { fail("Should throw exception."); } }