Skip to content

Commit 5d1bbbe

Browse files
Test continue as new with local activities (#1922)
Test continue as new with local activities
1 parent 7077b54 commit 5d1bbbe

3 files changed

Lines changed: 46 additions & 29 deletions

File tree

temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityInTheLastWorkflowTaskTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public class LocalActivityInTheLastWorkflowTaskTest {
4343
.build();
4444

4545
@Test
46-
@Parameters({"true", "false"})
47-
public void testLocalActivityInTheLastWorkflowTask(boolean blockOnLA) {
46+
@Parameters({"true, true", "false, true", "true, false", "false, false"})
47+
public void testLocalActivityInTheLastWorkflowTask(boolean blockOnLA, boolean continueAsNew) {
4848
TestWorkflow client = testWorkflowRule.newWorkflowStub(TestWorkflow.class);
49-
assertEquals("done", client.execute(blockOnLA));
49+
assertEquals("done", client.execute(blockOnLA, continueAsNew));
5050
}
5151

5252
@WorkflowInterface
5353
public interface TestWorkflow {
5454
@WorkflowMethod
55-
String execute(boolean blockOnLA);
55+
String execute(boolean blockOnLA, boolean continueAsNew);
5656
}
5757

5858
public static class TestWorkflowImpl implements TestWorkflow {
@@ -65,13 +65,16 @@ public static class TestWorkflowImpl implements TestWorkflow {
6565
.build());
6666

6767
@Override
68-
public String execute(boolean blockOnLA) {
68+
public String execute(boolean blockOnLA, boolean continueAsNew) {
6969
if (blockOnLA) {
7070
Promise promise = Async.procedure(activities::sleepActivity, (long) 100, 0);
7171
Async.procedure(activities::sleepActivity, (long) 1000, 0);
7272
promise.get();
7373
}
7474
Async.procedure(activities::sleepActivity, (long) 1000, 0);
75+
if (continueAsNew) {
76+
Workflow.continueAsNew(blockOnLA, false);
77+
}
7578
return "done";
7679
}
7780
}

temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalWithLocalActivityInTheLastWorkflowTaskTest.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,27 @@ public class SignalWithLocalActivityInTheLastWorkflowTaskTest {
4444
.build();
4545

4646
@Test
47-
@Parameters({"true", "false"})
48-
public void testSignalWithLocalActivityInTheLastWorkflowTask(Boolean waitOnLA) {
47+
@Parameters({"true, true", "false, true", "true, false", "false, false"})
48+
public void testSignalWithLocalActivityInTheLastWorkflowTask(
49+
Boolean waitOnLA, Boolean continueAsNew) {
4950
TestSignaledWorkflow client = testWorkflowRule.newWorkflowStub(TestSignaledWorkflow.class);
5051
WorkflowStub.fromTyped(client)
51-
.signalWithStart("testSignal", new String[] {"signalValue"}, new Boolean[] {waitOnLA});
52-
assertEquals("done", client.execute());
52+
.signalWithStart("signal", new Boolean[] {waitOnLA, continueAsNew}, new Boolean[] {true});
53+
assertEquals("done", client.execute(true));
5354
}
5455

5556
@WorkflowInterface
5657
public interface TestSignaledWorkflow {
5758

5859
@WorkflowMethod
59-
String execute();
60+
String execute(Boolean wait);
6061

6162
@SignalMethod
62-
void signal(boolean waitOnLA);
63+
void signal(boolean waitOnLA, boolean continueAsNew);
6364
}
6465

6566
public static class TestSignalWorkflowImpl implements TestSignaledWorkflow {
67+
boolean finish = false;
6668

6769
private final TestActivities.VariousTestActivities activities =
6870
Workflow.newLocalActivityStub(
@@ -72,18 +74,25 @@ public static class TestSignalWorkflowImpl implements TestSignaledWorkflow {
7274
.build());
7375

7476
@Override
75-
public String execute() {
77+
public String execute(Boolean wait) {
78+
if (wait) {
79+
Workflow.await(() -> finish);
80+
}
7681
return "done";
7782
}
7883

7984
@Override
80-
public void signal(boolean waitOnLA) {
85+
public void signal(boolean waitOnLA, boolean continueAsNew) {
8186
if (waitOnLA) {
8287
Promise promise = Async.procedure(activities::sleepActivity, (long) 100, 0);
83-
Async.procedure(activities::sleepActivity, (long) 1000, 0);
88+
Async.procedure(activities::sleepActivity, (long) 10000, 0);
8489
promise.get();
8590
}
8691

92+
if (continueAsNew) {
93+
Workflow.continueAsNew(false);
94+
}
95+
finish = true;
8796
activities.sleepActivity(1000, 0);
8897
}
8998
}

temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithLocalActivityInTheLastWorkflowTaskTest.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,37 @@ public class UpdateWithLocalActivityInTheLastWorkflowTaskTest {
4444
.build();
4545

4646
@Test
47-
@Parameters({"true", "false"})
48-
public void testUpdateWithLocalActivityInTheLastWorkflowTask(Boolean waitOnLA)
49-
throws InterruptedException {
47+
@Parameters({"true, true", "false, true", "true, false", "false, false"})
48+
public void testUpdateWithLocalActivityInTheLastWorkflowTask(
49+
Boolean waitOnLA, Boolean continueAsNew) {
5050
WorkflowWithUpdate client = testWorkflowRule.newWorkflowStub(WorkflowWithUpdate.class);
5151

52-
WorkflowStub.fromTyped(client).start();
52+
WorkflowStub.fromTyped(client).start(true);
5353
Thread asyncUpdate =
5454
new Thread(
5555
() -> {
5656
try {
57-
client.update(waitOnLA);
57+
client.update(waitOnLA, continueAsNew);
5858
} catch (Exception e) {
5959
}
6060
});
6161
asyncUpdate.start();
62-
assertEquals("done", client.execute());
62+
assertEquals("done", client.execute(true));
6363
asyncUpdate.interrupt();
6464
}
6565

6666
@WorkflowInterface
6767
public interface WorkflowWithUpdate {
6868

6969
@WorkflowMethod
70-
String execute();
70+
String execute(Boolean finish);
7171

7272
@UpdateMethod
73-
String update(Boolean waitOnLA);
73+
String update(Boolean waitOnLA, Boolean continueAsNew);
7474
}
7575

7676
public static class WorkflowWithUpdateImpl implements WorkflowWithUpdate {
77-
Boolean finish = false;
78-
77+
boolean finish = false;
7978
private final TestActivities.VariousTestActivities activities =
8079
Workflow.newLocalActivityStub(
8180
TestActivities.VariousTestActivities.class,
@@ -84,18 +83,24 @@ public static class WorkflowWithUpdateImpl implements WorkflowWithUpdate {
8483
.build());
8584

8685
@Override
87-
public String execute() {
88-
Workflow.await(() -> finish);
86+
public String execute(Boolean wait) {
87+
if (wait) {
88+
Workflow.await(() -> finish);
89+
}
8990
return "done";
9091
}
9192

9293
@Override
93-
public String update(Boolean waitOnLA) {
94+
public String update(Boolean waitOnLA, Boolean continueAsNew) {
9495
if (waitOnLA) {
95-
Promise promise = Async.procedure(activities::sleepActivity, (long) 100, 0);
96-
Async.procedure(activities::sleepActivity, (long) 1000, 0);
96+
Promise promise = Async.procedure(activities::sleepActivity, (long) 10, 0);
97+
Async.procedure(activities::sleepActivity, (long) 10000, 0);
9798
promise.get();
9899
}
100+
101+
if (continueAsNew) {
102+
Workflow.continueAsNew(false);
103+
}
99104
finish = true;
100105
activities.sleepActivity(1000, 0);
101106
return "update";

0 commit comments

Comments
 (0)