Skip to content

Commit ee93882

Browse files
committed
add appID support for cross app wf and unit tests for task options
Signed-off-by: Cassandra Coyle <[email protected]>
1 parent f46600c commit ee93882

File tree

3 files changed

+132
-2
lines changed

3 files changed

+132
-2
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Verify Compilation:
2+
```shell
3+
./gradlew compileJava
4+
```
5+
16
Build & test:
27

38
```shell

client/src/main/java/io/dapr/durabletask/TaskOptions.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,51 @@
88
public final class TaskOptions {
99
private final RetryPolicy retryPolicy;
1010
private final RetryHandler retryHandler;
11+
private final String appID;
12+
13+
public TaskOptions(RetryPolicy retryPolicy, RetryHandler retryHandler, String appID) {
14+
this.retryPolicy = retryPolicy;
15+
this.retryHandler = retryHandler;
16+
this.appID = appID;
17+
}
1118

1219
public TaskOptions(RetryPolicy retryPolicy, RetryHandler retryHandler) {
1320
this.retryPolicy = retryPolicy;
1421
this.retryHandler = retryHandler;
22+
this.appID = null;
1523
}
1624

1725
/**
1826
* Creates a new {@code TaskOptions} object from a {@link RetryPolicy}.
1927
* @param retryPolicy the retry policy to use in the new {@code TaskOptions} object.
2028
*/
2129
public TaskOptions(RetryPolicy retryPolicy) {
22-
this(retryPolicy, null);
30+
this(retryPolicy, null, null);
2331
}
2432

2533
/**
2634
* Creates a new {@code TaskOptions} object from a {@link RetryHandler}.
2735
* @param retryHandler the retry handler to use in the new {@code TaskOptions} object.
2836
*/
2937
public TaskOptions(RetryHandler retryHandler) {
30-
this(null, retryHandler);
38+
this(null, retryHandler, null);
39+
}
40+
41+
/**
42+
* Creates a new {@code TaskOptions} object with the specified app ID.
43+
* @param appID the app ID to use for cross-app workflow routing
44+
*/
45+
public TaskOptions(String appID) {
46+
this(null, null, appID);
47+
}
48+
49+
/**
50+
* Creates a new {@code TaskOptions} object with the specified retry policy and app ID.
51+
* @param retryPolicy the retry policy to use
52+
* @param appID the app ID to use for cross-app workflow routing
53+
*/
54+
public TaskOptions(RetryPolicy retryPolicy, String appID) {
55+
this(retryPolicy, null, appID);
3156
}
3257

3358
boolean hasRetryPolicy() {
@@ -53,4 +78,16 @@ boolean hasRetryHandler() {
5378
public RetryHandler getRetryHandler() {
5479
return this.retryHandler;
5580
}
81+
82+
/**
83+
* Gets the configured app ID value or {@code null} if none was configured.
84+
* @return the configured app ID
85+
*/
86+
public String getAppID() {
87+
return this.appID;
88+
}
89+
90+
boolean hasAppID() {
91+
return this.appID != null && !this.appID.isEmpty();
92+
}
5693
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.durabletask;
15+
16+
import org.junit.jupiter.api.Test;
17+
import java.time.Duration;
18+
19+
import static org.junit.jupiter.api.Assertions.*;
20+
21+
/**
22+
* Unit tests for TaskOptions with cross-app workflow support.
23+
*/
24+
public class TaskOptionsTest {
25+
26+
@Test
27+
void taskOptionsWithAppID() {
28+
TaskOptions options = new TaskOptions("app1");
29+
30+
assertTrue(options.hasAppID());
31+
assertEquals("app1", options.getAppID());
32+
assertFalse(options.hasRetryPolicy());
33+
assertFalse(options.hasRetryHandler());
34+
}
35+
36+
@Test
37+
void taskOptionsWithRetryPolicyAndAppID() {
38+
RetryPolicy retryPolicy = new RetryPolicy(3, Duration.ofSeconds(1));
39+
TaskOptions options = new TaskOptions(retryPolicy, null, "app2");
40+
41+
assertTrue(options.hasAppID());
42+
assertEquals("app2", options.getAppID());
43+
assertTrue(options.hasRetryPolicy());
44+
assertEquals(retryPolicy, options.getRetryPolicy());
45+
assertFalse(options.hasRetryHandler());
46+
}
47+
48+
@Test
49+
void taskOptionsWithRetryHandlerAndAppID() {
50+
RetryHandler retryHandler = new RetryHandler() {
51+
@Override
52+
public boolean handle(RetryContext context) {
53+
return context.getLastAttemptNumber() < 2;
54+
}
55+
};
56+
TaskOptions options = new TaskOptions(null, retryHandler, "app3");
57+
58+
assertTrue(options.hasAppID());
59+
assertEquals("app3", options.getAppID());
60+
assertFalse(options.hasRetryPolicy());
61+
assertTrue(options.hasRetryHandler());
62+
assertEquals(retryHandler, options.getRetryHandler());
63+
}
64+
65+
@Test
66+
void taskOptionsWithoutAppID() {
67+
TaskOptions options = new TaskOptions(null, null, null);
68+
69+
assertFalse(options.hasAppID());
70+
assertNull(options.getAppID());
71+
}
72+
73+
@Test
74+
void taskOptionsWithEmptyAppID() {
75+
TaskOptions options = new TaskOptions("");
76+
77+
assertFalse(options.hasAppID());
78+
assertEquals("", options.getAppID());
79+
}
80+
81+
@Test
82+
void taskOptionsWithNullAppID() {
83+
TaskOptions options = new TaskOptions(null, null, null);
84+
85+
assertFalse(options.hasAppID());
86+
assertNull(options.getAppID());
87+
}
88+
}

0 commit comments

Comments
 (0)