From e08eaeadb43794060801ed8d1d74690cc19f8d42 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Thu, 2 Nov 2023 08:12:45 -0700 Subject: [PATCH 1/2] Test continue as new with local activities --- ...ocalActivityInTheLastWorkflowTaskTest.java | 13 ++++--- ...ocalActivityInTheLastWorkflowTaskTest.java | 27 +++++++++----- ...ocalActivityInTheLastWorkflowTaskTest.java | 35 +++++++++++-------- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityInTheLastWorkflowTaskTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityInTheLastWorkflowTaskTest.java index 7e68084dc..dd1a2a93c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityInTheLastWorkflowTaskTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityInTheLastWorkflowTaskTest.java @@ -43,16 +43,16 @@ public class LocalActivityInTheLastWorkflowTaskTest { .build(); @Test - @Parameters({"true", "false"}) - public void testLocalActivityInTheLastWorkflowTask(boolean blockOnLA) { + @Parameters({"true, true", "false, true", "true, false", "false, false"}) + public void testLocalActivityInTheLastWorkflowTask(boolean blockOnLA, boolean continueAsNew) { TestWorkflow client = testWorkflowRule.newWorkflowStub(TestWorkflow.class); - assertEquals("done", client.execute(blockOnLA)); + assertEquals("done", client.execute(blockOnLA, continueAsNew)); } @WorkflowInterface public interface TestWorkflow { @WorkflowMethod - String execute(boolean blockOnLA); + String execute(boolean blockOnLA, boolean continueAsNew); } public static class TestWorkflowImpl implements TestWorkflow { @@ -65,13 +65,16 @@ public static class TestWorkflowImpl implements TestWorkflow { .build()); @Override - public String execute(boolean blockOnLA) { + public String execute(boolean blockOnLA, boolean continueAsNew) { if (blockOnLA) { Promise promise = Async.procedure(activities::sleepActivity, (long) 100, 0); Async.procedure(activities::sleepActivity, (long) 1000, 0); promise.get(); } Async.procedure(activities::sleepActivity, (long) 1000, 0); + if (continueAsNew) { + Workflow.continueAsNew(blockOnLA, false); + } return "done"; } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalWithLocalActivityInTheLastWorkflowTaskTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalWithLocalActivityInTheLastWorkflowTaskTest.java index fce2a3ca0..058dc3b77 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalWithLocalActivityInTheLastWorkflowTaskTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalWithLocalActivityInTheLastWorkflowTaskTest.java @@ -44,25 +44,27 @@ public class SignalWithLocalActivityInTheLastWorkflowTaskTest { .build(); @Test - @Parameters({"true", "false"}) - public void testSignalWithLocalActivityInTheLastWorkflowTask(Boolean waitOnLA) { + @Parameters({"true, true", "false, true", "true, false", "false, false"}) + public void testSignalWithLocalActivityInTheLastWorkflowTask( + Boolean waitOnLA, Boolean continueAsNew) { TestSignaledWorkflow client = testWorkflowRule.newWorkflowStub(TestSignaledWorkflow.class); WorkflowStub.fromTyped(client) - .signalWithStart("testSignal", new String[] {"signalValue"}, new Boolean[] {waitOnLA}); - assertEquals("done", client.execute()); + .signalWithStart("signal", new Boolean[] {waitOnLA, continueAsNew}, new Boolean[] {true}); + assertEquals("done", client.execute(true)); } @WorkflowInterface public interface TestSignaledWorkflow { @WorkflowMethod - String execute(); + String execute(Boolean wait); @SignalMethod - void signal(boolean waitOnLA); + void signal(boolean waitOnLA, boolean continueAsNew); } public static class TestSignalWorkflowImpl implements TestSignaledWorkflow { + boolean finish = false; private final TestActivities.VariousTestActivities activities = Workflow.newLocalActivityStub( @@ -72,18 +74,25 @@ public static class TestSignalWorkflowImpl implements TestSignaledWorkflow { .build()); @Override - public String execute() { + public String execute(Boolean wait) { + if (wait) { + Workflow.await(() -> finish); + } return "done"; } @Override - public void signal(boolean waitOnLA) { + public void signal(boolean waitOnLA, boolean continueAsNew) { if (waitOnLA) { Promise promise = Async.procedure(activities::sleepActivity, (long) 100, 0); - Async.procedure(activities::sleepActivity, (long) 1000, 0); + Async.procedure(activities::sleepActivity, (long) 10000, 0); promise.get(); } + if (continueAsNew) { + Workflow.continueAsNew(false); + } + finish = true; activities.sleepActivity(1000, 0); } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithLocalActivityInTheLastWorkflowTaskTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithLocalActivityInTheLastWorkflowTaskTest.java index f27861cdb..4f4a14b76 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithLocalActivityInTheLastWorkflowTaskTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithLocalActivityInTheLastWorkflowTaskTest.java @@ -44,22 +44,22 @@ public class UpdateWithLocalActivityInTheLastWorkflowTaskTest { .build(); @Test - @Parameters({"true", "false"}) - public void testUpdateWithLocalActivityInTheLastWorkflowTask(Boolean waitOnLA) - throws InterruptedException { + @Parameters({"true, true", "false, true", "true, false", "false, false"}) + public void testUpdateWithLocalActivityInTheLastWorkflowTask( + Boolean waitOnLA, Boolean continueAsNew) { WorkflowWithUpdate client = testWorkflowRule.newWorkflowStub(WorkflowWithUpdate.class); - WorkflowStub.fromTyped(client).start(); + WorkflowStub.fromTyped(client).start(true); Thread asyncUpdate = new Thread( () -> { try { - client.update(waitOnLA); + client.update(waitOnLA, continueAsNew); } catch (Exception e) { } }); asyncUpdate.start(); - assertEquals("done", client.execute()); + assertEquals("done", client.execute(true)); asyncUpdate.interrupt(); } @@ -67,15 +67,14 @@ public void testUpdateWithLocalActivityInTheLastWorkflowTask(Boolean waitOnLA) public interface WorkflowWithUpdate { @WorkflowMethod - String execute(); + String execute(Boolean finish); @UpdateMethod - String update(Boolean waitOnLA); + String update(Boolean waitOnLA, Boolean continueAsNew); } public static class WorkflowWithUpdateImpl implements WorkflowWithUpdate { - Boolean finish = false; - + boolean finish = false; private final TestActivities.VariousTestActivities activities = Workflow.newLocalActivityStub( TestActivities.VariousTestActivities.class, @@ -84,18 +83,24 @@ public static class WorkflowWithUpdateImpl implements WorkflowWithUpdate { .build()); @Override - public String execute() { - Workflow.await(() -> finish); + public String execute(Boolean wait) { + if (wait) { + Workflow.await(() -> finish); + } return "done"; } @Override - public String update(Boolean waitOnLA) { + public String update(Boolean waitOnLA, Boolean continueAsNew) { if (waitOnLA) { - Promise promise = Async.procedure(activities::sleepActivity, (long) 100, 0); - Async.procedure(activities::sleepActivity, (long) 1000, 0); + Promise promise = Async.procedure(activities::sleepActivity, (long) 10, 0); + Async.procedure(activities::sleepActivity, (long) 10000, 0); promise.get(); } + + if (continueAsNew) { + Workflow.continueAsNew(false); + } finish = true; activities.sleepActivity(1000, 0); return "update"; From 25e9ee70c83ebfbe3721c76c4ccf573bfeffa907 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Fri, 3 Nov 2023 08:21:38 -0700 Subject: [PATCH 2/2] Fix formatting --- .../UpdateWithLocalActivityInTheLastWorkflowTaskTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithLocalActivityInTheLastWorkflowTaskTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithLocalActivityInTheLastWorkflowTaskTest.java index 4f4a14b76..e32e6773a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithLocalActivityInTheLastWorkflowTaskTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithLocalActivityInTheLastWorkflowTaskTest.java @@ -97,7 +97,7 @@ public String update(Boolean waitOnLA, Boolean continueAsNew) { Async.procedure(activities::sleepActivity, (long) 10000, 0); promise.get(); } - + if (continueAsNew) { Workflow.continueAsNew(false); }