-
Notifications
You must be signed in to change notification settings - Fork 177
Refactor WorkflowTest #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bd9d6a4
Update service client dependencies
acc66e4
Update temporal-sdk dependencies
7a4069c
Missed micrometer-core update
af82446
Merge remote-tracking branch 'upstream/master'
0108f7f
Last batch of factored out tests
62ba735
Moved classes/methods into places where they're used.
91f8ea0
These tests fail at the moment. Pushing to PR to get hints
4d3c90c
Fixed ContinueAsNewTest
b6c24bb
Merge remote-tracking branch 'upstream/master' into refactor-workflow…
43115ed
Fixed testHeartbeatTimeoutDetails()
5d8b25f
Fixed a few more tests that needed replay.
714251c
Fixed SyncTest
cc916ca
Fixed a silly bug.
29e1d88
Previously run only when testEnvironment != null, and it was null whe…
17859b0
Merge branch 'master' into refactor-workflowtest
vkoby 4b0395f
Fixed CustomDatetimeField search attribute string
01a996d
Added .getWorkflowExecutionHistory() and .blockingStub to WorkflowRules
632bab2
Removed unnesassary ActivityImplementations setting.
41e71e4
Factored out execution history logic into the workflow rule.
b900865
Removed unnecessary activityImpl field
faa1af3
Fixed bug.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
84 changes: 84 additions & 0 deletions
84
temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java
This file contains hidden or 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,84 @@ | ||
/* | ||
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright 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 file except in compliance with the License. A copy of the License is | ||
* located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 static org.junit.Assert.assertTrue; | ||
|
||
import io.temporal.activity.ActivityOptions; | ||
import io.temporal.api.common.v1.WorkflowExecution; | ||
import io.temporal.api.enums.v1.EventType; | ||
import io.temporal.api.history.v1.History; | ||
import io.temporal.api.history.v1.HistoryEvent; | ||
import io.temporal.client.WorkflowClient; | ||
import io.temporal.client.WorkflowClientOptions; | ||
import io.temporal.client.WorkflowStub; | ||
import io.temporal.workflow.shared.*; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class BinaryChecksumSetWhenTaskCompletedTest { | ||
|
||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowClientOptions( | ||
WorkflowClientOptions.newBuilder() | ||
.setBinaryChecksum(SDKTestWorkflowRule.BINARY_CHECKSUM) | ||
.build()) | ||
.setWorkflowTypes(SimpleTestWorkflow.class) | ||
.build(); | ||
|
||
@Test | ||
public void testBinaryChecksumSetWhenTaskCompleted() { | ||
TestWorkflows.TestWorkflow1 client = | ||
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); | ||
WorkflowExecution execution = | ||
WorkflowClient.start(client::execute, testWorkflowRule.getTaskQueue()); | ||
WorkflowStub stub = WorkflowStub.fromTyped(client); | ||
SDKTestWorkflowRule.waitForOKQuery(stub); | ||
History history = testWorkflowRule.getWorkflowExecutionHistory(execution); | ||
|
||
boolean foundCompletedTask = false; | ||
for (HistoryEvent event : history.getEventsList()) { | ||
if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_COMPLETED) { | ||
assertEquals( | ||
SDKTestWorkflowRule.BINARY_CHECKSUM, | ||
event.getWorkflowTaskCompletedEventAttributes().getBinaryChecksum()); | ||
foundCompletedTask = true; | ||
} | ||
} | ||
assertTrue(foundCompletedTask); | ||
} | ||
|
||
public static class SimpleTestWorkflow implements TestWorkflows.TestWorkflow1 { | ||
|
||
@Override | ||
public String execute(String taskQueue) { | ||
TestActivities testActivities = | ||
Workflow.newActivityStub( | ||
TestActivities.class, | ||
ActivityOptions.newBuilder(TestOptions.newActivityOptionsForTaskQueue(taskQueue)) | ||
.build()); | ||
testActivities.activity(); | ||
return "done"; | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java
This file contains hidden or 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,74 @@ | ||
/* | ||
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright 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 file except in compliance with the License. A copy of the License is | ||
* located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 io.temporal.testing.TracingWorkerInterceptor; | ||
import io.temporal.workflow.shared.SDKTestWorkflowRule; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class ContinueAsNewNoArgsTest { | ||
|
||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestContinueAsNewNoArgsImpl.class) | ||
.setWorkerInterceptors( | ||
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) | ||
.build(); | ||
|
||
@Test | ||
public void testContinueAsNewNoArgs() { | ||
|
||
NoArgsWorkflow client = testWorkflowRule.newWorkflowStubTimeoutOptions(NoArgsWorkflow.class); | ||
String result = client.execute(); | ||
Assert.assertEquals("done", result); | ||
testWorkflowRule | ||
.getInterceptor(TracingWorkerInterceptor.class) | ||
.setExpected( | ||
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, | ||
"newThread workflow-method", | ||
"continueAsNew", | ||
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, | ||
"newThread workflow-method"); | ||
} | ||
|
||
@WorkflowInterface | ||
public interface NoArgsWorkflow { | ||
@WorkflowMethod | ||
String execute(); | ||
} | ||
|
||
public static class TestContinueAsNewNoArgsImpl implements NoArgsWorkflow { | ||
|
||
@Override | ||
public String execute() { | ||
NoArgsWorkflow next = Workflow.newContinueAsNewStub(NoArgsWorkflow.class); | ||
WorkflowInfo info = Workflow.getInfo(); | ||
if (!info.getContinuedExecutionRunId().isPresent()) { | ||
next.execute(); | ||
throw new RuntimeException("unreachable"); | ||
} else { | ||
return "done"; | ||
} | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java
This file contains hidden or 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,98 @@ | ||
/* | ||
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright 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 file except in compliance with the License. A copy of the License is | ||
* located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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.TracingWorkerInterceptor; | ||
import io.temporal.workflow.shared.SDKTestWorkflowRule; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class ContinueAsNewTest { | ||
|
||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestContinueAsNewImpl.class) | ||
.setWorkerInterceptors( | ||
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) | ||
.build(); | ||
|
||
@Test | ||
public void testContinueAsNew() { | ||
TestContinueAsNew client = | ||
testWorkflowRule.newWorkflowStubTimeoutOptions(TestContinueAsNew.class); | ||
int result = client.execute(4, testWorkflowRule.getTaskQueue()); | ||
Assert.assertEquals(111, result); | ||
testWorkflowRule | ||
.getInterceptor(TracingWorkerInterceptor.class) | ||
.setExpected( | ||
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, | ||
"newThread workflow-method", | ||
"continueAsNew", | ||
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, | ||
"newThread workflow-method", | ||
"continueAsNew", | ||
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, | ||
"newThread workflow-method", | ||
"continueAsNew", | ||
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, | ||
"newThread workflow-method", | ||
"continueAsNew", | ||
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, | ||
"newThread workflow-method"); | ||
} | ||
|
||
@WorkflowInterface | ||
public interface TestContinueAsNew { | ||
|
||
@WorkflowMethod | ||
int execute(int count, String continueAsNewTaskQueue); | ||
} | ||
|
||
public static class TestContinueAsNewImpl implements TestContinueAsNew { | ||
|
||
@Override | ||
public int execute(int count, String continueAsNewTaskQueue) { | ||
String taskQueue = Workflow.getInfo().getTaskQueue(); | ||
if (count == 0) { | ||
assertEquals(continueAsNewTaskQueue, taskQueue); | ||
return 111; | ||
} | ||
Map<String, Object> memo = new HashMap<>(); | ||
memo.put("myKey", "MyValue"); | ||
Map<String, Object> searchAttributes = new HashMap<>(); | ||
searchAttributes.put("CustomKeywordField", "foo1"); | ||
ContinueAsNewOptions options = | ||
ContinueAsNewOptions.newBuilder() | ||
.setTaskQueue(continueAsNewTaskQueue) | ||
.setMemo(memo) | ||
.setSearchAttributes(searchAttributes) | ||
.build(); | ||
TestContinueAsNew next = Workflow.newContinueAsNewStub(TestContinueAsNew.class, options); | ||
next.execute(count - 1, continueAsNewTaskQueue); | ||
throw new RuntimeException("unreachable"); | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java
This file contains hidden or 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,98 @@ | ||
/* | ||
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright 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 file except in compliance with the License. A copy of the License is | ||
* located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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.*; | ||
|
||
import io.temporal.client.WorkflowFailedException; | ||
import io.temporal.client.WorkflowStub; | ||
import io.temporal.failure.ActivityFailure; | ||
import io.temporal.failure.CanceledFailure; | ||
import io.temporal.workflow.shared.SDKTestWorkflowRule; | ||
import io.temporal.workflow.shared.TestActivities; | ||
import io.temporal.workflow.shared.TestOptions; | ||
import io.temporal.workflow.shared.TestWorkflows; | ||
import java.time.Duration; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class DetachedScopeTest { | ||
|
||
private final TestActivities.TestActivitiesImpl activitiesImpl = | ||
new TestActivities.TestActivitiesImpl(); | ||
|
||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestDetachedCancellationScope.class) | ||
.setActivityImplementations(activitiesImpl) | ||
.build(); | ||
|
||
@Test | ||
public void testDetachedScope() { | ||
WorkflowStub client = testWorkflowRule.newUntypedWorkflowStubTimeoutOptions("TestWorkflow1"); | ||
client.start(testWorkflowRule.getTaskQueue()); | ||
testWorkflowRule.sleep(Duration.ofMillis(500)); // To let activityWithDelay start. | ||
client.cancel(); | ||
try { | ||
client.getResult(String.class); | ||
Assert.fail("unreachable"); | ||
} catch (WorkflowFailedException e) { | ||
Assert.assertTrue(e.getCause() instanceof CanceledFailure); | ||
} | ||
activitiesImpl.assertInvocations("activityWithDelay", "activity1", "activity2", "activity3"); | ||
} | ||
|
||
public static class TestDetachedCancellationScope implements TestWorkflows.TestWorkflow1 { | ||
|
||
@Override | ||
public String execute(String taskQueue) { | ||
TestActivities testActivities = | ||
Workflow.newActivityStub( | ||
TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); | ||
try { | ||
testActivities.activityWithDelay(100000, true); | ||
fail("unreachable"); | ||
} catch (ActivityFailure e) { | ||
assertTrue(e.getCause() instanceof CanceledFailure); | ||
Workflow.newDetachedCancellationScope(() -> assertEquals(1, testActivities.activity1(1))) | ||
.run(); | ||
} | ||
try { | ||
Workflow.sleep(Duration.ofHours(1)); | ||
fail("unreachable"); | ||
} catch (CanceledFailure e) { | ||
Workflow.newDetachedCancellationScope( | ||
() -> assertEquals("a12", testActivities.activity2("a1", 2))) | ||
.run(); | ||
} | ||
try { | ||
Workflow.newTimer(Duration.ofHours(1)).get(); | ||
fail("unreachable"); | ||
} catch (CanceledFailure e) { | ||
Workflow.newDetachedCancellationScope( | ||
() -> assertEquals("a123", testActivities.activity3("a1", 2, 3))) | ||
.run(); | ||
} | ||
return "result"; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.