-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't schedule local activities on a completed workflow (#1908)
Don't schedule LA on completed workflow
- Loading branch information
1 parent
9b0dcbb
commit 8b3be3b
Showing
9 changed files
with
417 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
temporal-sdk/src/test/java/io/temporal/workflow/CommandInTheLastWorkflowTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.workflow; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.shared.TestActivities; | ||
import io.temporal.workflow.shared.TestWorkflows; | ||
import java.util.Objects; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class CommandInTheLastWorkflowTaskTest { | ||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestWorkflowImpl.class) | ||
.setActivityImplementations(new TestActivities.TestActivitiesImpl()) | ||
.build(); | ||
|
||
@Test | ||
public void testCommandInTheLastWorkflowTask() { | ||
TestWorkflows.TestWorkflowReturnString client = | ||
testWorkflowRule.newWorkflowStub(TestWorkflows.TestWorkflowReturnString.class); | ||
assertEquals("done", client.execute()); | ||
} | ||
|
||
public static class TestWorkflowImpl implements TestWorkflows.TestWorkflowReturnString { | ||
|
||
@Override | ||
public String execute() { | ||
Async.procedure( | ||
() -> { | ||
Workflow.mutableSideEffect( | ||
"id1", Integer.class, (o, n) -> Objects.equals(n, o), () -> 0); | ||
}); | ||
return "done"; | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...k/src/test/java/io/temporal/workflow/activityTests/ActivityInTheLastWorkflowTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.workflow.activityTests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import io.temporal.activity.ActivityOptions; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.Async; | ||
import io.temporal.workflow.Workflow; | ||
import io.temporal.workflow.shared.TestActivities; | ||
import io.temporal.workflow.shared.TestWorkflows; | ||
import java.time.Duration; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class ActivityInTheLastWorkflowTaskTest { | ||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestWorkflowImpl.class) | ||
.setActivityImplementations(new TestActivities.TestActivitiesImpl()) | ||
.build(); | ||
|
||
@Test | ||
public void testActivityInTheLastWorkflowTask() { | ||
TestWorkflows.TestWorkflowReturnString client = | ||
testWorkflowRule.newWorkflowStub(TestWorkflows.TestWorkflowReturnString.class); | ||
assertEquals("done", client.execute()); | ||
} | ||
|
||
public static class TestWorkflowImpl implements TestWorkflows.TestWorkflowReturnString { | ||
|
||
private final TestActivities.VariousTestActivities activities = | ||
Workflow.newActivityStub( | ||
TestActivities.VariousTestActivities.class, | ||
ActivityOptions.newBuilder() | ||
.setScheduleToCloseTimeout(Duration.ofSeconds(200)) | ||
.build()); | ||
|
||
@Override | ||
public String execute() { | ||
Async.procedure(activities::sleepActivity, (long) 1000, 0); | ||
return "done"; | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
.../test/java/io/temporal/workflow/activityTests/LocalActivityInTheLastWorkflowTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.workflow.activityTests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import io.temporal.activity.LocalActivityOptions; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.*; | ||
import io.temporal.workflow.shared.TestActivities; | ||
import java.time.Duration; | ||
import junitparams.JUnitParamsRunner; | ||
import junitparams.Parameters; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(JUnitParamsRunner.class) | ||
public class LocalActivityInTheLastWorkflowTaskTest { | ||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestWorkflowImpl.class) | ||
.setActivityImplementations(new TestActivities.TestActivitiesImpl()) | ||
.build(); | ||
|
||
@Test | ||
@Parameters({"true", "false"}) | ||
public void testLocalActivityInTheLastWorkflowTask(boolean blockOnLA) { | ||
TestWorkflow client = testWorkflowRule.newWorkflowStub(TestWorkflow.class); | ||
assertEquals("done", client.execute(blockOnLA)); | ||
} | ||
|
||
@WorkflowInterface | ||
public interface TestWorkflow { | ||
@WorkflowMethod | ||
String execute(boolean blockOnLA); | ||
} | ||
|
||
public static class TestWorkflowImpl implements TestWorkflow { | ||
|
||
private final TestActivities.VariousTestActivities activities = | ||
Workflow.newLocalActivityStub( | ||
TestActivities.VariousTestActivities.class, | ||
LocalActivityOptions.newBuilder() | ||
.setScheduleToCloseTimeout(Duration.ofSeconds(200)) | ||
.build()); | ||
|
||
@Override | ||
public String execute(boolean blockOnLA) { | ||
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); | ||
return "done"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...va/io/temporal/workflow/signalTests/SignalWithLocalActivityInTheLastWorkflowTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.workflow.signalTests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import io.temporal.activity.LocalActivityOptions; | ||
import io.temporal.client.WorkflowStub; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.*; | ||
import io.temporal.workflow.shared.TestActivities; | ||
import java.time.Duration; | ||
import junitparams.JUnitParamsRunner; | ||
import junitparams.Parameters; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(JUnitParamsRunner.class) | ||
public class SignalWithLocalActivityInTheLastWorkflowTaskTest { | ||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestSignalWorkflowImpl.class) | ||
.setActivityImplementations(new TestActivities.TestActivitiesImpl()) | ||
.build(); | ||
|
||
@Test | ||
@Parameters({"true", "false"}) | ||
public void testSignalWithLocalActivityInTheLastWorkflowTask(Boolean waitOnLA) { | ||
TestSignaledWorkflow client = testWorkflowRule.newWorkflowStub(TestSignaledWorkflow.class); | ||
WorkflowStub.fromTyped(client) | ||
.signalWithStart("testSignal", new String[] {"signalValue"}, new Boolean[] {waitOnLA}); | ||
assertEquals("done", client.execute()); | ||
} | ||
|
||
@WorkflowInterface | ||
public interface TestSignaledWorkflow { | ||
|
||
@WorkflowMethod | ||
String execute(); | ||
|
||
@SignalMethod | ||
void signal(boolean waitOnLA); | ||
} | ||
|
||
public static class TestSignalWorkflowImpl implements TestSignaledWorkflow { | ||
|
||
private final TestActivities.VariousTestActivities activities = | ||
Workflow.newLocalActivityStub( | ||
TestActivities.VariousTestActivities.class, | ||
LocalActivityOptions.newBuilder() | ||
.setScheduleToCloseTimeout(Duration.ofSeconds(200)) | ||
.build()); | ||
|
||
@Override | ||
public String execute() { | ||
return "done"; | ||
} | ||
|
||
@Override | ||
public void signal(boolean waitOnLA) { | ||
if (waitOnLA) { | ||
Promise promise = Async.procedure(activities::sleepActivity, (long) 100, 0); | ||
Async.procedure(activities::sleepActivity, (long) 1000, 0); | ||
promise.get(); | ||
} | ||
|
||
activities.sleepActivity(1000, 0); | ||
} | ||
} | ||
} |
Oops, something went wrong.