Skip to content

Commit cc21312

Browse files
Merge branch 'master' into ja-task-idempotency-keys
Signed-off-by: Javier Aliaga <javier@diagrid.io>
2 parents 45872ef + e4cc030 commit cc21312

File tree

10 files changed

+79
-23
lines changed

10 files changed

+79
-23
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
env:
122122
DOCKER_HOST: ${{steps.setup_docker.outputs.sock}}
123123
- name: Codecov
124-
uses: codecov/codecov-action@v5.4.2
124+
uses: codecov/codecov-action@v5.4.3
125125
- name: Install jars
126126
run: ./mvnw install -q -B -DskipTests
127127
- name: Integration tests using spring boot version ${{ matrix.spring-boot-version }}

.github/workflows/fossa.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ jobs:
3535
uses: actions/checkout@v4
3636

3737
- name: "Run FOSSA Scan"
38-
uses: fossas/fossa-action@v1.6.0 # Use a specific version if locking is preferred
38+
uses: fossas/fossa-action@v1.7.0 # Use a specific version if locking is preferred
3939
with:
4040
api-key: ${{ env.FOSSA_API_KEY }}
4141

4242
- name: "Run FOSSA Test"
43-
uses: fossas/fossa-action@v1.6.0 # Use a specific version if locking is preferred
43+
uses: fossas/fossa-action@v1.7.0 # Use a specific version if locking is preferred
4444
with:
4545
api-key: ${{ env.FOSSA_API_KEY }}
4646
run-tests: true

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.3</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
@@ -305,6 +305,7 @@ public void callChildWorkflowWithOptions() {
305305

306306
assertEquals(retryPolicy.getMaxNumberOfAttempts(), taskOptions.getRetryPolicy().getMaxNumberOfAttempts());
307307
assertEquals(retryPolicy.getFirstRetryInterval(), taskOptions.getRetryPolicy().getFirstRetryInterval());
308+
assertEquals(Duration.ZERO, taskOptions.getRetryPolicy().getRetryTimeout());
308309
}
309310

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

testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,19 @@ public DaprContainer withComponent(Path path) {
210210
try {
211211
Map<String, Object> component = YAML_MAPPER.loadAs(Files.newInputStream(path), Map.class);
212212

213-
String type = (String) component.get("type");
214213
Map<String, Object> metadata = (Map<String, Object>) component.get("metadata");
215214
String name = (String) metadata.get("name");
216215

217216
Map<String, Object> spec = (Map<String, Object>) component.get("spec");
217+
String type = (String) spec.get("type");
218218
String version = (String) spec.get("version");
219219
List<Map<String, String>> specMetadata =
220-
(List<Map<String, String>>) spec.getOrDefault("metadata", Collections.emptyMap());
220+
(List<Map<String, String>>) spec.getOrDefault("metadata", Collections.emptyList());
221221

222222
ArrayList<MetadataEntry> metadataEntries = new ArrayList<>();
223223

224224
for (Map<String, String> specMetadataItem : specMetadata) {
225-
for (Map.Entry<String, String> metadataItem : specMetadataItem.entrySet()) {
226-
metadataEntries.add(new MetadataEntry(metadataItem.getKey(), metadataItem.getValue()));
227-
}
225+
metadataEntries.add(new MetadataEntry(specMetadataItem.get("name"), specMetadataItem.get("value")));
228226
}
229227

230228
return withComponent(new Component(name, type, version, metadataEntries));

testcontainers-dapr/src/test/java/io/dapr/testcontainers/DaprComponentTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,14 @@ public void withComponentFromPath() {
6969
+ "metadata:\n"
7070
+ " name: statestore\n"
7171
+ "spec:\n"
72-
+ " type: null\n"
72+
+ " type: state.redis\n"
7373
+ " version: v1\n"
7474
+ " metadata:\n"
75-
+ " - name: name\n"
76-
+ " value: keyPrefix\n"
77-
+ " - name: value\n"
75+
+ " - name: keyPrefix\n"
7876
+ " value: name\n"
79-
+ " - name: name\n"
80-
+ " value: redisHost\n"
81-
+ " - name: value\n"
77+
+ " - name: redisHost\n"
8278
+ " value: redis:6379\n"
83-
+ " - name: name\n"
84-
+ " value: redisPassword\n"
85-
+ " - name: value\n"
79+
+ " - name: redisPassword\n"
8680
+ " value: ''\n";
8781

8882
assertEquals(expectedComponentYaml, componentYaml);

0 commit comments

Comments
 (0)