Skip to content

Commit fa9af63

Browse files
authored
Merge branch 'master' into adding-wf-examples-to-sb
2 parents cb45e24 + 910b13b commit fa9af63

File tree

6 files changed

+69
-5
lines changed

6 files changed

+69
-5
lines changed

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflow.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,29 @@
1515

1616
import io.dapr.workflows.Workflow;
1717
import io.dapr.workflows.WorkflowStub;
18+
import io.dapr.workflows.WorkflowTaskOptions;
19+
import io.dapr.workflows.WorkflowTaskRetryPolicy;
20+
21+
import java.time.Duration;
1822

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

29+
WorkflowTaskRetryPolicy policy = WorkflowTaskRetryPolicy.newBuilder()
30+
.setFirstRetryInterval(Duration.ofSeconds(1))
31+
.setMaxNumberOfAttempts(10)
32+
.build();
33+
34+
WorkflowTaskOptions options = new WorkflowTaskOptions(policy);
35+
2536
var childWorkflowInput = ctx.getInput(String.class);
2637
ctx.getLogger().info("ChildWorkflow received input: " + childWorkflowInput);
2738

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

3142
ctx.getLogger().info("ChildWorkflow finished with: " + result);
3243
ctx.complete(result);

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflowWorker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static void main(String[] args) throws Exception {
3232

3333
// Build and then start the workflow runtime pulling and executing tasks
3434
WorkflowRuntime runtime = builder.build();
35+
runtime.start();
3536
System.out.println("Start workflow runtime");
3637
}
3738
}

sdk-workflows/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>io.dapr</groupId>
4949
<artifactId>durabletask-client</artifactId>
50-
<version>1.5.2</version>
50+
<version>1.5.4</version>
5151
</dependency>
5252
<!--
5353
manually declare durabletask-client's jackson dependencies

sdk-workflows/src/main/java/io/dapr/workflows/WorkflowTaskRetryPolicy.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ public Builder setMaxRetryInterval(@Nullable Duration maxRetryInterval) {
166166
* @return This builder
167167
*/
168168
public Builder setRetryTimeout(Duration retryTimeout) {
169-
if (retryTimeout != null && retryTimeout.compareTo(this.firstRetryInterval) < 0) {
169+
if (retryTimeout == null || retryTimeout.compareTo(this.firstRetryInterval) < 0) {
170170
throw new IllegalArgumentException(
171-
"The value for retryTimeout must be greater than or equal to the value for firstRetryInterval.");
171+
"The value for retryTimeout cannot be null and"
172+
+ " must be greater than or equal to the value for firstRetryInterval.");
172173
}
173174

174175
this.retryTimeout = retryTimeout;

sdk-workflows/src/main/java/io/dapr/workflows/runtime/DefaultWorkflowContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ private static TaskOptions toTaskOptions(WorkflowTaskOptions options) {
240240
);
241241

242242
retryPolicy.setBackoffCoefficient(workflowTaskRetryPolicy.getBackoffCoefficient());
243-
retryPolicy.setRetryTimeout(workflowTaskRetryPolicy.getRetryTimeout());
243+
if (workflowTaskRetryPolicy.getRetryTimeout() != null) {
244+
retryPolicy.setRetryTimeout(workflowTaskRetryPolicy.getRetryTimeout());
245+
}
244246

245247
return new TaskOptions(retryPolicy);
246248
}

sdk-workflows/src/test/java/io/dapr/workflows/DefaultWorkflowContextTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ public void callChildWorkflowWithOptions() {
304304

305305
assertEquals(retryPolicy.getMaxNumberOfAttempts(), taskOptions.getRetryPolicy().getMaxNumberOfAttempts());
306306
assertEquals(retryPolicy.getFirstRetryInterval(), taskOptions.getRetryPolicy().getFirstRetryInterval());
307+
assertEquals(Duration.ZERO, taskOptions.getRetryPolicy().getRetryTimeout());
307308
}
308309

309310
@Test
@@ -327,4 +328,52 @@ public void newUuidTestNoImplementationExceptionTest() {
327328
String expectedMessage = "No implementation found.";
328329
assertEquals(expectedMessage, runtimeException.getMessage());
329330
}
331+
332+
@Test
333+
public void workflowRetryPolicyRetryTimeoutValueShouldHaveRightValueWhenBeingSet() {
334+
String expectedName = "TestActivity";
335+
String expectedInput = "TestInput";
336+
String expectedInstanceId = "TestInstanceId";
337+
WorkflowTaskRetryPolicy retryPolicy = WorkflowTaskRetryPolicy.newBuilder()
338+
.setMaxNumberOfAttempts(1)
339+
.setFirstRetryInterval(Duration.ofSeconds(10))
340+
.setRetryTimeout(Duration.ofSeconds(10))
341+
.build();
342+
WorkflowTaskOptions executionOptions = new WorkflowTaskOptions(retryPolicy);
343+
ArgumentCaptor<TaskOptions> captor = ArgumentCaptor.forClass(TaskOptions.class);
344+
345+
context.callChildWorkflow(expectedName, expectedInput, expectedInstanceId, executionOptions, String.class);
346+
347+
verify(mockInnerContext, times(1))
348+
.callSubOrchestrator(
349+
eq(expectedName),
350+
eq(expectedInput),
351+
eq(expectedInstanceId),
352+
captor.capture(),
353+
eq(String.class)
354+
);
355+
356+
TaskOptions taskOptions = captor.getValue();
357+
358+
assertEquals(Duration.ofSeconds(10), taskOptions.getRetryPolicy().getRetryTimeout());
359+
}
360+
361+
@Test
362+
public void workflowRetryPolicyRetryThrowIllegalArgumentWhenNullRetryTimeoutIsSet() {
363+
assertThrows(IllegalArgumentException.class, () ->
364+
WorkflowTaskRetryPolicy.newBuilder()
365+
.setMaxNumberOfAttempts(1)
366+
.setFirstRetryInterval(Duration.ofSeconds(10))
367+
.setRetryTimeout(null)
368+
.build());
369+
}
370+
371+
@Test
372+
public void workflowRetryPolicyRetryThrowIllegalArgumentWhenRetryTimeoutIsLessThanMaxRetryInterval() {
373+
assertThrows(IllegalArgumentException.class, () -> WorkflowTaskRetryPolicy.newBuilder()
374+
.setMaxNumberOfAttempts(1)
375+
.setFirstRetryInterval(Duration.ofSeconds(10))
376+
.setRetryTimeout(Duration.ofSeconds(9))
377+
.build());
378+
}
330379
}

0 commit comments

Comments
 (0)