use of com.uber.cadence.common.RetryOptions in project cadence-client by uber-java.
the class RetryerTest method testInterruptedException.
@Test
public void testInterruptedException() throws InterruptedException {
RetryOptions options = new RetryOptions.Builder().setInitialInterval(Duration.ofMillis(10)).setMaximumInterval(Duration.ofMillis(100)).setExpiration(Duration.ofSeconds(100)).setDoNotRetry(InterruptedException.class).validateBuildWithDefaults();
long start = System.currentTimeMillis();
try {
Retryer.retryWithResultAsync(options, () -> {
CompletableFuture<Void> result = new CompletableFuture<>();
result.completeExceptionally(new InterruptedException("simulated"));
return result;
}).get();
fail("unreachable");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof InterruptedException);
assertEquals("simulated", e.getCause().getMessage());
}
assertTrue(System.currentTimeMillis() - start < 100000);
}
use of com.uber.cadence.common.RetryOptions in project cadence-client by uber-java.
the class DeterministicRunnerTest method testRetry.
/**
* Async retry cannot be tested here as it relies on timer that is implemented outside of
* Dispatcher.
*
* @see WorkflowTest#testAsyncRetry()
*/
@Test
public void testRetry() throws Throwable {
RetryOptions retryOptions = new RetryOptions.Builder().setInitialInterval(Duration.ofSeconds(10)).setMaximumInterval(Duration.ofSeconds(100)).setExpiration(Duration.ofMinutes(5)).setBackoffCoefficient(2.0).build();
DeterministicRunnerImpl d = new DeterministicRunnerImpl(threadPool, null, // clock override
() -> currentTime, () -> {
trace.add("started");
Workflow.retry(retryOptions, () -> {
trace.add("retry at " + Workflow.currentTimeMillis());
throw new IllegalThreadStateException("simulated");
});
trace.add("beforeSleep");
Workflow.sleep(60000);
trace.add("done");
});
try {
for (int i = 0; i < Duration.ofSeconds(400).toMillis(); i += 10) {
currentTime = i;
d.runUntilAllBlocked();
}
fail("failure expected");
} catch (IllegalThreadStateException e) {
assertEquals("simulated", e.getMessage());
}
int attempt = 1;
long time = 0;
trace.addExpected("started");
while (time < retryOptions.getExpiration().toMillis()) {
trace.addExpected("retry at " + time);
long sleepMillis = (long) ((Math.pow(retryOptions.getBackoffCoefficient(), attempt - 1)) * retryOptions.getInitialInterval().toMillis());
sleepMillis = Math.min(sleepMillis, retryOptions.getMaximumInterval().toMillis());
attempt++;
time += sleepMillis;
}
}
use of com.uber.cadence.common.RetryOptions in project cadence-client by uber-java.
the class ActivityOptionsTest method testOnlyAnnotationsPresent.
@Test
public void testOnlyAnnotationsPresent() throws NoSuchMethodException {
Method method = ActivityOptionsTest.class.getMethod("activityAndRetryOptions");
ActivityMethod a = method.getAnnotation(ActivityMethod.class);
MethodRetry r = method.getAnnotation(MethodRetry.class);
ActivityOptions o = new ActivityOptions.Builder().build();
ActivityOptions merged = ActivityOptions.merge(a, r, o);
Assert.assertEquals(a.taskList(), merged.getTaskList());
Assert.assertEquals(a.heartbeatTimeoutSeconds(), merged.getHeartbeatTimeout().getSeconds());
Assert.assertEquals(a.scheduleToCloseTimeoutSeconds(), merged.getScheduleToCloseTimeout().getSeconds());
Assert.assertEquals(a.scheduleToStartTimeoutSeconds(), merged.getScheduleToStartTimeout().getSeconds());
Assert.assertEquals(a.startToCloseTimeoutSeconds(), merged.getStartToCloseTimeout().getSeconds());
RetryOptions rMerged = merged.getRetryOptions();
Assert.assertEquals(r.maximumAttempts(), rMerged.getMaximumAttempts());
Assert.assertEquals(r.minimumAttempts(), rMerged.getMinimumAttempts());
Assert.assertEquals(r.backoffCoefficient(), rMerged.getBackoffCoefficient(), 0.0);
Assert.assertEquals(Duration.ofSeconds(r.expirationSeconds()), rMerged.getExpiration());
Assert.assertEquals(Duration.ofSeconds(r.initialIntervalSeconds()), rMerged.getInitialInterval());
Assert.assertEquals(Duration.ofSeconds(r.maximumIntervalSeconds()), rMerged.getMaximumInterval());
Assert.assertEquals(Arrays.asList(r.doNotRetry()), rMerged.getDoNotRetry());
}
use of com.uber.cadence.common.RetryOptions in project cadence-client by uber-java.
the class RetryerTest method testExpiration.
@Test
public void testExpiration() throws InterruptedException {
RetryOptions options = new RetryOptions.Builder().setInitialInterval(Duration.ofMillis(10)).setMaximumInterval(Duration.ofMillis(100)).setExpiration(Duration.ofMillis(500)).validateBuildWithDefaults();
long start = System.currentTimeMillis();
try {
Retryer.retryWithResultAsync(options, () -> {
throw new IllegalArgumentException("simulated");
}).get();
fail("unreachable");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof IllegalArgumentException);
assertEquals("simulated", e.getCause().getMessage());
}
assertTrue(System.currentTimeMillis() - start > 500);
}
use of com.uber.cadence.common.RetryOptions in project cadence-client by uber-java.
the class RetryerTest method testExpirationFuture.
@Test
public void testExpirationFuture() throws InterruptedException {
RetryOptions options = new RetryOptions.Builder().setInitialInterval(Duration.ofMillis(10)).setMaximumInterval(Duration.ofMillis(100)).setExpiration(Duration.ofMillis(500)).validateBuildWithDefaults();
long start = System.currentTimeMillis();
try {
Retryer.retryWithResultAsync(options, () -> {
CompletableFuture<Void> result = new CompletableFuture<>();
result.completeExceptionally(new IllegalArgumentException("simulated"));
return result;
}).get();
fail("unreachable");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof IllegalArgumentException);
assertEquals("simulated", e.getCause().getMessage());
}
assertTrue(System.currentTimeMillis() - start > 500);
}
Aggregations