@Test public void testExponentialBackoff() throws Exception { Config config = newConfig(); config.set("_command", BUCKET + "/" + KEY); when(taskRequest.getConfig()).thenReturn(config); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentType(CONTENT_TYPE); objectMetadata.setContentLength(CONTENT_LENGTH); objectMetadata.setUserMetadata(USER_METADATA); when(s3Client.getObjectMetadata(any(GetObjectMetadataRequest.class))).thenThrow(NOT_FOUND_EXCEPTION); Operator operator = factory.newOperator(newContext(projectPath, taskRequest)); List<Integer> retryIntervals = new ArrayList<>(); for (int i = 0; i < 10; i++) { try { operator.run(); fail(); } catch (TaskExecutionException e) { assertThat(e.isError(), is(false)); assertThat(e.getRetryInterval().isPresent(), is(true)); retryIntervals.add(e.getRetryInterval().get()); Config lastStateParams = e.getStateParams(configFactory).get(); when(taskRequest.getLastStateParams()).thenReturn(lastStateParams); } } for (int i = 1; i < retryIntervals.size(); i++) { int prevInterval = retryIntervals.get(i - 1); int interval = retryIntervals.get(i); assertThat(interval, is(Math.min(MAX_POLL_INTERVAL, prevInterval * 2))); } assertThat(retryIntervals.get(retryIntervals.size() - 1), is(MAX_POLL_INTERVAL)); }
@Override public Operator newOperator(OperatorContext context) { return new S3WaitOperator(context); }
S3WaitOperatorFactory implements OperatorFactory { @Override public Operator newOperator(OperatorContext context) { return new S3WaitOperator(context); } }
S3WaitOperatorFactory implements OperatorFactory { @Override public Operator newOperator(OperatorContext context) { return new S3WaitOperator(context); } @Inject  S3WaitOperatorFactory(@Environment Map<String, String> environment); @VisibleForTesting  S3WaitOperatorFactory(
            AmazonS3ClientFactory s3ClientFactory,
            Map<String, String> environment); }
S3WaitOperatorFactory implements OperatorFactory { @Override public Operator newOperator(OperatorContext context) { return new S3WaitOperator(context); } @Inject  S3WaitOperatorFactory(@Environment Map<String, String> environment); @VisibleForTesting  S3WaitOperatorFactory(
            AmazonS3ClientFactory s3ClientFactory,
            Map<String, String> environment); String getType(); @Override Operator newOperator(OperatorContext context); }
S3WaitOperatorFactory implements OperatorFactory { @Override public Operator newOperator(OperatorContext context) { return new S3WaitOperator(context); } @Inject  S3WaitOperatorFactory(@Environment Map<String, String> environment); @VisibleForTesting  S3WaitOperatorFactory(
            AmazonS3ClientFactory s3ClientFactory,
            Map<String, String> environment); String getType(); @Override Operator newOperator(OperatorContext context);  }