Skip to content

Commit 9142f0a

Browse files
committed
getResult/Async continue polling across the server's long-poll boundary and the client's rpc boundary (this and previous)
1 parent 7328b47 commit 9142f0a

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package io.temporal.client.functional;
2+
3+
import static org.junit.Assume.assumeTrue;
4+
5+
import io.temporal.activity.ActivityInterface;
6+
import io.temporal.activity.ActivityMethod;
7+
import io.temporal.client.ActivityClient;
8+
import io.temporal.client.ActivityClientOptions;
9+
import io.temporal.client.ActivityHandle;
10+
import io.temporal.client.StartActivityOptions;
11+
import io.temporal.testing.internal.SDKTestWorkflowRule;
12+
import java.time.Duration;
13+
import java.util.UUID;
14+
import java.util.concurrent.ExecutionException;
15+
import org.junit.Rule;
16+
import org.junit.Test;
17+
18+
/**
19+
* Verifies that {@link ActivityHandle#getResult()} and {@link ActivityHandle#getResultAsync()}
20+
* continue polling after the server cuts a long poll and returns an empty response. The server cuts
21+
* activity long polls after approximately {@value ACTIVITY_LONG_POLL_TIMEOUT_SECONDS} seconds; the
22+
* activity here runs for 1.5× that so the server-side cut fires at least once before the activity
23+
* completes.
24+
*/
25+
public class GetActivityResultOverServerLongPollWaitTest {
26+
private static final int ACTIVITY_LONG_POLL_TIMEOUT_SECONDS = 20;
27+
28+
@ActivityInterface
29+
public interface SlowActivity {
30+
@ActivityMethod(name = "SlowActivity")
31+
void run();
32+
}
33+
34+
public static class SlowActivityImpl implements SlowActivity {
35+
@Override
36+
public void run() {
37+
try {
38+
Thread.sleep(Duration.ofSeconds(3 * ACTIVITY_LONG_POLL_TIMEOUT_SECONDS / 2).toMillis());
39+
} catch (InterruptedException e) {
40+
Thread.currentThread().interrupt();
41+
}
42+
}
43+
}
44+
45+
@Rule
46+
public SDKTestWorkflowRule testWorkflowRule =
47+
SDKTestWorkflowRule.newBuilder()
48+
.setUseTimeskipping(false)
49+
.setActivityImplementations(new SlowActivityImpl())
50+
.build();
51+
52+
private ActivityClient newActivityClient() {
53+
return ActivityClient.newInstance(
54+
testWorkflowRule.getWorkflowClient().getWorkflowServiceStubs(),
55+
ActivityClientOptions.newBuilder().setNamespace(SDKTestWorkflowRule.NAMESPACE).build());
56+
}
57+
58+
private StartActivityOptions slowOpts() {
59+
return StartActivityOptions.newBuilder()
60+
.setId("slow-act-" + UUID.randomUUID())
61+
.setTaskQueue(testWorkflowRule.getTaskQueue())
62+
.setScheduleToCloseTimeout(Duration.ofMinutes(2))
63+
.build();
64+
}
65+
66+
@Test(timeout = 2 * ACTIVITY_LONG_POLL_TIMEOUT_SECONDS * 1000)
67+
public void testGetResult() {
68+
assumeTrue(SDKTestWorkflowRule.useExternalService);
69+
newActivityClient().execute(SlowActivity.class, SlowActivity::run, slowOpts());
70+
}
71+
72+
@Test(timeout = 2 * ACTIVITY_LONG_POLL_TIMEOUT_SECONDS * 1000)
73+
public void testGetResultAsync() throws ExecutionException, InterruptedException {
74+
assumeTrue(SDKTestWorkflowRule.useExternalService);
75+
newActivityClient().executeAsync(SlowActivity.class, SlowActivity::run, slowOpts()).get();
76+
}
77+
}

0 commit comments

Comments
 (0)