Skip to content

Fix the issue with retries not happening correctly for Activities and Workflows #1343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cf30030
Add coverage for some properties (#1297)
mcruzdev Apr 16, 2025
9f78f2e
Make the DAPR version being used consistent across all tests (#1299)
siri-varma Apr 18, 2025
46bf0c7
Separate Dapr constants from IT container constants (#1315)
artur-ciocanu Apr 22, 2025
947634c
Use Java Bean for connection details and add more tests (#1317)
artur-ciocanu Apr 22, 2025
3398dc1
Update CONTRIBUTING.md
siri-varma Apr 29, 2025
5cdb041
Bump codecov/codecov-action from 5.4.0 to 5.4.2 (#1318)
dependabot[bot] Apr 22, 2025
2053f65
Fix URL building logic (#1320)
artur-ciocanu Apr 29, 2025
71c1859
Generate updated javadocs for 1.14.1
dapr-bot Apr 30, 2025
a434e79
Add Conversation AI to Java SDK (#1235)
siri-varma May 1, 2025
02f7a2e
Add docs for usage of Jobs SDK (#1323)
siri-varma May 6, 2025
65f502b
Use dapr/durabletask-java (#1336)
cicoyle May 8, 2025
66b023c
Update master version to 1.16.0-SNAPSHOT
dapr-bot May 8, 2025
5227c38
Fix NPE
siri-varma May 13, 2025
457f3f7
Fix NPE
siri-varma May 13, 2025
f922416
Fix NPE
siri-varma May 13, 2025
0308d4c
Fix NPE
siri-varma May 13, 2025
875816e
Fix NPE
siri-varma May 13, 2025
aabf3ca
Fix NPE
siri-varma May 13, 2025
644683e
Fix things
siri-varma May 13, 2025
78684f1
Renaming and exposing connection details (#1341)
artur-ciocanu May 13, 2025
9d03688
[Master] Fix Vulnerabilities (#1354)
cicoyle May 13, 2025
81ebe96
Feat Add TLS & mTLS support for gRPC with root CA and insecure mode (…
cicoyle May 14, 2025
d1fc827
Address comments
siri-varma May 15, 2025
96f86e9
Fix things
siri-varma May 15, 2025
21ddb95
Fix things
siri-varma May 15, 2025
1d1e482
Merge branch 'master' into users/svegiraju/fix-npe
siri-varma May 15, 2025
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 @@ -15,18 +15,29 @@

import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;
import io.dapr.workflows.WorkflowTaskOptions;
import io.dapr.workflows.WorkflowTaskRetryPolicy;

import java.time.Duration;

public class DemoChildWorkflow implements Workflow {
@Override
public WorkflowStub create() {
return ctx -> {
ctx.getLogger().info("Starting ChildWorkflow: " + ctx.getName());

WorkflowTaskRetryPolicy policy = WorkflowTaskRetryPolicy.newBuilder()
.setFirstRetryInterval(Duration.ofSeconds(1))
.setMaxNumberOfAttempts(10)
.build();

WorkflowTaskOptions options = new WorkflowTaskOptions(policy);

var childWorkflowInput = ctx.getInput(String.class);
ctx.getLogger().info("ChildWorkflow received input: " + childWorkflowInput);

ctx.getLogger().info("ChildWorkflow is calling Activity: " + ReverseActivity.class.getName());
String result = ctx.callActivity(ReverseActivity.class.getName(), childWorkflowInput, String.class).await();
String result = ctx.callActivity(ReverseActivity.class.getName(), childWorkflowInput, options, String.class).await();

ctx.getLogger().info("ChildWorkflow finished with: " + result);
ctx.complete(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static void main(String[] args) throws Exception {

// Build and then start the workflow runtime pulling and executing tasks
WorkflowRuntime runtime = builder.build();
runtime.start();
System.out.println("Start workflow runtime");
}
}
2 changes: 1 addition & 1 deletion sdk-workflows/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>io.dapr</groupId>
<artifactId>durabletask-client</artifactId>
<version>1.5.2</version>
<version>1.5.3</version>
</dependency>
<!--
manually declare durabletask-client's jackson dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ public Builder setMaxRetryInterval(@Nullable Duration maxRetryInterval) {
* @return This builder
*/
public Builder setRetryTimeout(Duration retryTimeout) {
if (retryTimeout != null && retryTimeout.compareTo(this.firstRetryInterval) < 0) {
if (retryTimeout == null || retryTimeout.compareTo(this.firstRetryInterval) < 0) {
throw new IllegalArgumentException(
"The value for retryTimeout must be greater than or equal to the value for firstRetryInterval.");
"The value for retryTimeout cannot be null and"
+ " must be greater than or equal to the value for firstRetryInterval.");
}

this.retryTimeout = retryTimeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ private static TaskOptions toTaskOptions(WorkflowTaskOptions options) {
);

retryPolicy.setBackoffCoefficient(workflowTaskRetryPolicy.getBackoffCoefficient());
retryPolicy.setRetryTimeout(workflowTaskRetryPolicy.getRetryTimeout());
if (workflowTaskRetryPolicy.getRetryTimeout() != null) {
retryPolicy.setRetryTimeout(workflowTaskRetryPolicy.getRetryTimeout());
}

return new TaskOptions(retryPolicy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public void callChildWorkflowWithOptions() {

assertEquals(retryPolicy.getMaxNumberOfAttempts(), taskOptions.getRetryPolicy().getMaxNumberOfAttempts());
assertEquals(retryPolicy.getFirstRetryInterval(), taskOptions.getRetryPolicy().getFirstRetryInterval());
assertEquals(Duration.ZERO, taskOptions.getRetryPolicy().getRetryTimeout());
}

@Test
Expand All @@ -327,4 +328,52 @@ public void newUuidTestNoImplementationExceptionTest() {
String expectedMessage = "No implementation found.";
assertEquals(expectedMessage, runtimeException.getMessage());
}

@Test
public void workflowRetryPolicyRetryTimeoutValueShouldHaveRightValueWhenBeingSet() {
String expectedName = "TestActivity";
String expectedInput = "TestInput";
String expectedInstanceId = "TestInstanceId";
WorkflowTaskRetryPolicy retryPolicy = WorkflowTaskRetryPolicy.newBuilder()
.setMaxNumberOfAttempts(1)
.setFirstRetryInterval(Duration.ofSeconds(10))
.setRetryTimeout(Duration.ofSeconds(10))
.build();
WorkflowTaskOptions executionOptions = new WorkflowTaskOptions(retryPolicy);
ArgumentCaptor<TaskOptions> captor = ArgumentCaptor.forClass(TaskOptions.class);

context.callChildWorkflow(expectedName, expectedInput, expectedInstanceId, executionOptions, String.class);

verify(mockInnerContext, times(1))
.callSubOrchestrator(
eq(expectedName),
eq(expectedInput),
eq(expectedInstanceId),
captor.capture(),
eq(String.class)
);

TaskOptions taskOptions = captor.getValue();

assertEquals(Duration.ofSeconds(10), taskOptions.getRetryPolicy().getRetryTimeout());
}

@Test
public void workflowRetryPolicyRetryThrowIllegalArgumentWhenNullRetryTimeoutIsSet() {
assertThrows(IllegalArgumentException.class, () ->
WorkflowTaskRetryPolicy.newBuilder()
.setMaxNumberOfAttempts(1)
.setFirstRetryInterval(Duration.ofSeconds(10))
.setRetryTimeout(null)
.build());
}

@Test
public void workflowRetryPolicyRetryThrowIllegalArgumentWhenRetryTimeoutIsLessThanMaxRetryInterval() {
assertThrows(IllegalArgumentException.class, () -> WorkflowTaskRetryPolicy.newBuilder()
.setMaxNumberOfAttempts(1)
.setFirstRetryInterval(Duration.ofSeconds(10))
.setRetryTimeout(Duration.ofSeconds(9))
.build());
}
}
Loading