Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.*;

import io.temporal.common.RetryOptions;
import io.temporal.failure.ApplicationFailure;
import io.temporal.testing.internal.SDKTestOptions;
import io.temporal.testing.internal.SDKTestWorkflowRule;
Expand All @@ -10,33 +11,39 @@
import io.temporal.workflow.WorkflowMethod;
import io.temporal.workflow.shared.TestActivities;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

public class ActivityNextRetryDelayTest {

private final NextRetryDelayActivityImpl activity = new NextRetryDelayActivityImpl();

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder()
.setTestTimeoutSeconds(30)
.setWorkflowTypes(TestWorkflowImpl.class)
.setActivityImplementations(new NextRetryDelayActivityImpl())
.setActivityImplementations(activity)
.build();

@Test
public void activityNextRetryDelay() {
TestWorkflowReturnDuration workflow =
testWorkflowRule.newWorkflowStub(TestWorkflowReturnDuration.class);
Duration result = workflow.execute(false);
Assert.assertTrue(result.toMillis() > 5000 && result.toMillis() < 7000);
Assert.assertTrue(result.toMillis() > 5000);
Assert.assertEquals(4, activity.getAttemptCount());
}

@Test
public void localActivityNextRetryDelay() {
TestWorkflowReturnDuration workflow =
testWorkflowRule.newWorkflowStub(TestWorkflowReturnDuration.class);
Duration result = workflow.execute(true);
Assert.assertTrue(result.toMillis() > 5000 && result.toMillis() < 7000);
Assert.assertTrue(result.toMillis() > 5000);
Assert.assertEquals(4, activity.getAttemptCount());
}

@WorkflowInterface
Expand All @@ -47,15 +54,22 @@ public interface TestWorkflowReturnDuration {

public static class TestWorkflowImpl implements TestWorkflowReturnDuration {

private static final RetryOptions FALLBACK_RETRY_OPTIONS =
RetryOptions.newBuilder().setInitialInterval(Duration.ofMillis(100)).build();

private final TestActivities.NoArgsActivity activities =
Workflow.newActivityStub(
TestActivities.NoArgsActivity.class,
SDKTestOptions.newActivityOptions20sScheduleToClose());
SDKTestOptions.newActivityOptions20sScheduleToClose().toBuilder()
.setRetryOptions(FALLBACK_RETRY_OPTIONS)
.build());

private final TestActivities.NoArgsActivity localActivities =
Workflow.newLocalActivityStub(
TestActivities.NoArgsActivity.class,
SDKTestOptions.newLocalActivityOptions20sScheduleToClose());
SDKTestOptions.newLocalActivityOptions20sScheduleToClose().toBuilder()
.setRetryOptions(FALLBACK_RETRY_OPTIONS)
.build());

@Override
public Duration execute(boolean useLocalActivity) {
Expand All @@ -71,8 +85,11 @@ public Duration execute(boolean useLocalActivity) {
}

public static class NextRetryDelayActivityImpl implements TestActivities.NoArgsActivity {
private final AtomicInteger attemptCount = new AtomicInteger();

@Override
public void execute() {
attemptCount.incrementAndGet();
int attempt = Activity.getExecutionContext().getInfo().getAttempt();
if (attempt < 4) {
throw ApplicationFailure.newFailureWithCauseAndDelay(
Expand All @@ -82,5 +99,9 @@ public void execute() {
Duration.ofSeconds(attempt));
}
}

public int getAttemptCount() {
return attemptCount.get();
}
}
}
Loading