From bd9d6a434ff90621f81fe7e8c9edb88fe2738821 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Tue, 16 Mar 2021 14:39:08 -0700 Subject: [PATCH 01/21] Update service client dependencies --- temporal-serviceclient/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/temporal-serviceclient/build.gradle b/temporal-serviceclient/build.gradle index 047a56d983..f1462cc85f 100644 --- a/temporal-serviceclient/build.gradle +++ b/temporal-serviceclient/build.gradle @@ -80,7 +80,7 @@ dependencies { api 'io.grpc:grpc-protobuf:1.36.0' api 'io.grpc:grpc-stub:1.36.0' api 'io.grpc:grpc-core:1.36.0' - api group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.15.2' + api group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.15.6' api group: 'com.uber.m3', name: 'tally-core', version: '0.6.1' api group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' api 'io.grpc:grpc-netty-shaded:1.36.0' @@ -122,7 +122,7 @@ jar { protobuf { protoc { - artifact = 'com.google.protobuf:protoc:3.15.2' + artifact = 'com.google.protobuf:protoc:3.15.6' } plugins { grpc { From acc66e4a7dcf6b91b79b3fc867469dc66112e11f Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Tue, 16 Mar 2021 14:57:10 -0700 Subject: [PATCH 02/21] Update temporal-sdk dependencies --- temporal-sdk/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/temporal-sdk/build.gradle b/temporal-sdk/build.gradle index 38b88acfad..83051ca804 100644 --- a/temporal-sdk/build.gradle +++ b/temporal-sdk/build.gradle @@ -45,8 +45,8 @@ dependencies { implementation group: 'com.google.guava', name: 'guava', version: '30.1-jre' implementation group: 'com.cronutils', name: 'cron-utils', version: '9.1.3' - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.1' - implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.12.1' + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.2' + implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.12.2' if (!JavaVersion.current().isJava8()) { implementation 'javax.annotation:javax.annotation-api:1.3.2' } From 7a4069c8ec1700cd1acd7a1b2228667d873e89ec Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Tue, 16 Mar 2021 17:35:18 -0700 Subject: [PATCH 03/21] Missed micrometer-core update --- temporal-sdk/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/temporal-sdk/build.gradle b/temporal-sdk/build.gradle index 83051ca804..6705d32bfc 100644 --- a/temporal-sdk/build.gradle +++ b/temporal-sdk/build.gradle @@ -41,7 +41,7 @@ dependencies { api project(':temporal-serviceclient') api group: 'com.google.code.gson', name: 'gson', version: '2.8.6' - api group: 'io.micrometer', name: 'micrometer-core', version: '1.6.4' + api group: 'io.micrometer', name: 'micrometer-core', version: '1.6.5' implementation group: 'com.google.guava', name: 'guava', version: '30.1-jre' implementation group: 'com.cronutils', name: 'cron-utils', version: '9.1.3' From 0108f7fd0f25b9c61c2e84964d99d5d6b635f19d Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Wed, 17 Mar 2021 15:17:33 -0700 Subject: [PATCH 04/21] Last batch of factored out tests --- .../workflow/ContinueAsNewNoArgsTest.java | 75 + .../temporal/workflow/DetachedScopeTest.java | 98 + .../workflow/ExceptionPropagationTest.java | 204 ++ .../io/temporal/workflow/ExecuteTest.java | 111 + .../GenericParametersWorkflowTest.java | 141 + .../GetAttemptFromWorkflowInfoTest.java | 68 + .../temporal/workflow/LargeHistoryTest.java | 91 + .../java/io/temporal/workflow/MemoTest.java | 91 + .../temporal/workflow/MultipleTimersTest.java | 67 + .../workflow/MutableSideEffectTest.java | 89 + .../workflow/NoQueryThreadLeakTest.java | 87 + .../workflow/ParentContinueAsNewTest.java | 82 + .../workflow/PolymorphicStartTest.java | 70 + .../java/io/temporal/workflow/SagaTest.java | 79 + .../workflow/SearchAttributesTest.java | 126 + .../io/temporal/workflow/SideEffectTest.java | 89 + .../java/io/temporal/workflow/StartTest.java | 199 ++ .../workflow/TimerCallbackBlockedTest.java | 76 + .../java/io/temporal/workflow/TimerTest.java | 138 + .../temporal/workflow/UUIDAndRandomTest.java | 86 + .../workflow/UpsertSearchAttributesTest.java | 130 + .../WorkflowCancellationScopePromiseTest.java | 66 + .../WorkflowFailureNonRetryableFlagTest.java | 103 + .../workflow/WorkflowIdResuePolicyTest.java | 88 + .../temporal/workflow/WorkflowLocalsTest.java | 86 + .../WorkflowRetryDoNotRetryExceptionTest.java | 100 + .../temporal/workflow/WorkflowRetryTest.java | 101 + ...ithMethodRetryDoNotRetryExceptionTest.java | 91 + .../WorkflowTaskFailureBackoffTest.java | 99 + .../workflow/WorkflowTaskNPEBackoffTest.java | 99 + .../WorkflowTaskTimeoutWorkflowTest.java | 82 + .../io/temporal/workflow/WorkflowTest.java | 2993 +---------------- ...wsWithFailedPromisesCanBeCanceledTest.java | 79 + .../AbandonOnCancelActivityTest.java | 3 +- ...ityApplicationFailureNonRetryableTest.java | 3 +- .../ActivityApplicationFailureRetryTest.java | 3 +- ...tivityApplicationNoSpecifiedRetryTest.java | 3 +- .../ActivityApplicationOptOutOfRetryTest.java | 3 +- .../ActivityPollerPrefetchingTest.java | 3 +- .../ActivityRetryAnnotatedTest.java | 3 +- .../ActivityRetryOnTimeoutTest.java | 3 +- .../ActivityRetryOptionsChangeTest.java | 3 +- .../ActivityRetryWithExpirationTest.java | 4 +- .../ActivityRetryWithMaxAttemptsTest.java | 3 +- .../ActivityThrowingErrorTest.java | 5 +- .../AsyncActivityCompleteWithErrorTest.java | 3 +- .../AsyncActivityRetryOptionsChangeTest.java | 4 +- .../AsyncActivityRetryTest.java} | 6 +- .../AsyncActivityTest.java | 5 +- .../AsyncRetryOptionsChangeTest.java | 4 +- .../{ => activityTests}/AsyncRetryTest.java | 4 +- .../AsyncUntyped2ActivityTest.java | 5 +- .../AsyncUntypedActivityTest.java | 6 +- ...alActivitiesWorkflowTaskHeartbeatTest.java | 73 + .../LocalActivityAndQueryTest.java | 6 +- .../LocalActivityManyWorkflowsTest.java | 5 +- .../LocalActivityRetryTest.java | 3 +- .../LocalActivityTest.java | 3 +- ...ivityWorkflowTaskHeartbeatFailureTest.java | 85 + ...ocalActivityWorkflowTaskHeartbeatTest.java | 61 + ...onSerializableArgumentsInActivityTest.java | 5 +- ...izableExceptionInActivityWorkflowTest.java | 4 +- .../ParallelLocalActivitiesTest.java | 6 +- ...lelLocalActivityExecutionWorkflowTest.java | 96 + .../TryCancelActivityTest.java | 3 +- .../UntypedActivityRetryTest.java | 4 +- .../ChildAsyncLambdaWorkflowTest.java | 3 +- .../ChildAsyncWorkflowTest.java | 7 +- .../ChildWorkflowAsyncRetryTest.java | 6 +- .../ChildWorkflowCancellationTest.java | 6 +- ...ldWorkflowExecutionPromiseHandlerTest.java | 3 +- .../ChildWorkflowRetryTest.java | 5 +- .../ChildWorkflowTest.java | 3 +- .../ChildWorkflowTimeoutTest.java | 5 +- .../ChildWorkflowWithCronScheduleTest.java | 4 +- .../NamedChildTest.java | 3 +- ...ializableExceptionInChildWorkflowTest.java | 4 +- ...arentWorkflowInfoInChildWorkflowsTest.java | 78 + ...hCancellationScopeAndCancelParentTest.java | 3 +- ...typedChildStubWorkflowAsyncInvokeTest.java | 6 +- .../UntypedChildStubWorkflowAsyncTest.java | 5 +- .../UntypedChildStubWorkflowTest.java | 3 +- .../ExceptionInSignalTest.java | 5 +- .../SignalAndQueryInterfaceTest.java | 6 +- .../SignalAndQueryListenerTest.java | 3 +- .../SignalDuringLastWorkflowTaskTest.java | 3 +- .../SignalExternalWorkflowFailureTest.java | 4 +- ...rnalWorkflowImmediateCancellationTest.java | 3 +- .../SignalExternalWorkflowTest.java | 3 +- .../SignalOrderingWorkflowTest.java | 6 +- .../{ => signalTests}/SignalTest.java | 5 +- .../UntypedSignalExternalWorkflowTest.java | 3 +- .../GetVersionAddNewBeforeTest.java | 80 + .../GetVersionRemovedBeforeTest.java | 89 + .../GetVersionRemovedInReplayTest.java | 88 + .../GetVersionSameIdOnReplayTest.java | 97 + .../versionTests/GetVersionSameIdTest.java | 74 + .../workflow/versionTests/GetVersionTest.java | 112 + .../GetVersionWorkflowRemoveTest.java | 80 + ...tVersionWorkflowReplaceCompletelyTest.java | 82 + ...ersionWorkflowReplaceGetVersionIdTest.java | 87 + .../versionTests/VersionNotSupportedTest.java | 87 + 102 files changed, 4715 insertions(+), 2960 deletions(-) create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/GenericParametersWorkflowTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/LargeHistoryTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/AbandonOnCancelActivityTest.java (98%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityApplicationFailureNonRetryableTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityApplicationFailureRetryTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityApplicationNoSpecifiedRetryTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityApplicationOptOutOfRetryTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityPollerPrefetchingTest.java (98%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityRetryAnnotatedTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityRetryOnTimeoutTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityRetryOptionsChangeTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityRetryWithExpirationTest.java (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityRetryWithMaxAttemptsTest.java (98%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ActivityThrowingErrorTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/AsyncActivityCompleteWithErrorTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/AsyncActivityRetryOptionsChangeTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{AsyncActivityRetry.java => activityTests/AsyncActivityRetryTest.java} (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/AsyncActivityTest.java (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/AsyncRetryOptionsChangeTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/AsyncRetryTest.java (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/AsyncUntyped2ActivityTest.java (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/AsyncUntypedActivityTest.java (95%) create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/LocalActivityAndQueryTest.java (95%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/LocalActivityManyWorkflowsTest.java (94%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/LocalActivityRetryTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/LocalActivityTest.java (98%) create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/NonSerializableArgumentsInActivityTest.java (95%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/NonSerializableExceptionInActivityWorkflowTest.java (95%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/ParallelLocalActivitiesTest.java (95%) create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/TryCancelActivityTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => activityTests}/UntypedActivityRetryTest.java (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/ChildAsyncLambdaWorkflowTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/ChildAsyncWorkflowTest.java (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/ChildWorkflowAsyncRetryTest.java (95%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/ChildWorkflowCancellationTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/ChildWorkflowExecutionPromiseHandlerTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/ChildWorkflowRetryTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/ChildWorkflowTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/ChildWorkflowTimeoutTest.java (93%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/ChildWorkflowWithCronScheduleTest.java (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/NamedChildTest.java (98%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/NonSerializableExceptionInChildWorkflowTest.java (95%) create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/UntypedChildStubWorkflowAsyncInvokeTest.java (95%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/UntypedChildStubWorkflowAsyncTest.java (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => childWorkflowTests}/UntypedChildStubWorkflowTest.java (95%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/ExceptionInSignalTest.java (95%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/SignalAndQueryInterfaceTest.java (92%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/SignalAndQueryListenerTest.java (98%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/SignalDuringLastWorkflowTaskTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/SignalExternalWorkflowFailureTest.java (96%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/SignalExternalWorkflowImmediateCancellationTest.java (97%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/SignalExternalWorkflowTest.java (98%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/SignalOrderingWorkflowTest.java (93%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/SignalTest.java (98%) rename temporal-sdk/src/test/java/io/temporal/workflow/{ => signalTests}/UntypedSignalExternalWorkflowTest.java (97%) create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java new file mode 100644 index 0000000000..2ac2e4dd30 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java @@ -0,0 +1,75 @@ +/* + * 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 io.temporal.workflow.shared.TestActivities; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class ContinueAsNewNoArgsTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestContinueAsNewNoArgsImpl.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testContinueAsNewNoArgs() { + + WorkflowTest.NoArgsWorkflow client = + testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.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"); + } + + public static class TestContinueAsNewNoArgsImpl implements WorkflowTest.NoArgsWorkflow { + + @Override + public String execute() { + WorkflowTest.NoArgsWorkflow next = + Workflow.newContinueAsNewStub(WorkflowTest.NoArgsWorkflow.class); + WorkflowInfo info = Workflow.getInfo(); + if (!info.getContinuedExecutionRunId().isPresent()) { + next.execute(); + throw new RuntimeException("unreachable"); + } else { + return "done"; + } + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java new file mode 100644 index 0000000000..d68806a62f --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java @@ -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(null); + + @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"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java new file mode 100644 index 0000000000..3ca66f22a1 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java @@ -0,0 +1,204 @@ +/* + * 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.common.RetryOptions; +import io.temporal.failure.ActivityFailure; +import io.temporal.failure.ApplicationFailure; +import io.temporal.failure.ChildWorkflowFailure; +import io.temporal.worker.WorkflowImplementationOptions; +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.io.FileNotFoundException; +import java.io.IOException; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class ExceptionPropagationTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes( + WorkflowImplementationOptions.newBuilder() + .setFailWorkflowExceptionTypes( + NumberFormatException.class, FileNotFoundException.class) + .build(), + ThrowingChild.class, + TestExceptionPropagationImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + /** + * Test that an NPE thrown in an activity executed from a child workflow results in the following + * chain of exceptions when an exception is received in an external client that executed workflow + * through a WorkflowClient: + * + *
+   * {@link WorkflowFailedException}
+   *     ->{@link ChildWorkflowFailure}
+   *         ->{@link ActivityFailure}
+   *             ->OriginalActivityException
+   * 
+ * + *

This test also tests that Checked exception wrapping and unwrapping works producing a nice + * exception chain without the wrappers. + */ + @Test + public void testExceptionPropagation() { + TestExceptionPropagation client = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestExceptionPropagation.class); + try { + client.execute(testWorkflowRule.getTaskQueue()); + Assert.fail("Unreachable"); + } catch (WorkflowFailedException e) { + // Rethrow the assertion failure + Throwable c1 = e.getCause(); + Throwable c2 = c1.getCause(); + Throwable c3 = c2.getCause(); + Throwable c4 = c3.getCause(); + Throwable c5 = c4.getCause(); + Throwable c6 = c5.getCause(); + if (c2 instanceof AssertionError) { + throw (AssertionError) c2; + } + assertNoEmptyStacks(e); + // Uncomment to see the actual trace. + // e.printStackTrace(); + Assert.assertTrue(e.getMessage(), e.getMessage().contains("TestExceptionPropagation")); + Assert.assertTrue(e.getStackTrace().length > 0); + Assert.assertTrue(c1 instanceof ApplicationFailure); + Assert.assertEquals( + FileNotFoundException.class.getName(), ((ApplicationFailure) c1).getType()); + Assert.assertTrue(c2 instanceof ChildWorkflowFailure); + Assert.assertTrue(c3 instanceof ApplicationFailure); + Assert.assertEquals( + NumberFormatException.class.getName(), ((ApplicationFailure) c3).getType()); + Assert.assertEquals(Throwable.class.getName(), ((ApplicationFailure) c4).getType()); + Assert.assertTrue(c5 instanceof ActivityFailure); + Assert.assertTrue(c6 instanceof ApplicationFailure); + Assert.assertEquals(IOException.class.getName(), ((ApplicationFailure) c6).getType()); + Assert.assertEquals( + "message='simulated IO problem', type='java.io.IOException', nonRetryable=false", + c6.getMessage()); + } + } + + private static void assertNoEmptyStacks(RuntimeException e) { + // Check that there are no empty stacks + Throwable c = e; + while (c != null) { + assertTrue(c.getStackTrace().length > 0); + c = c.getCause(); + } + } + + @WorkflowInterface + public interface TestExceptionPropagation { + @WorkflowMethod + void execute(String taskQueue); + } + + public static class ThrowingChild implements TestWorkflows.TestWorkflow1 { + + @Override + @SuppressWarnings("AssertionFailureIgnored") + public String execute(String taskQueue) { + TestActivities testActivities = + Workflow.newActivityStub( + TestActivities.class, + TestOptions.newActivityOptions20sScheduleToClose() + .toBuilder() + .setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build()) + .build()); + try { + testActivities.throwIO(); + fail("unreachable"); + return "ignored"; + } catch (ActivityFailure e) { + try { + assertTrue(e.getMessage().contains("ThrowIO")); + assertTrue(e.getCause() instanceof ApplicationFailure); + assertEquals(IOException.class.getName(), ((ApplicationFailure) e.getCause()).getType()); + assertEquals( + "message='simulated IO problem', type='java.io.IOException', nonRetryable=false", + e.getCause().getMessage()); + } catch (AssertionError ae) { + // Errors cause workflow task to fail. But we want workflow to fail in this case. + throw new RuntimeException(ae); + } + Exception ee = new NumberFormatException(); + ee.initCause(new Throwable("simulated throwable", e)); + throw Workflow.wrap(ee); + } + } + } + + public static class TestExceptionPropagationImpl implements TestExceptionPropagation { + + @Override + @SuppressWarnings("AssertionFailureIgnored") + public void execute(String taskQueue) { + ChildWorkflowOptions options = + ChildWorkflowOptions.newBuilder().setWorkflowRunTimeout(Duration.ofHours(1)).build(); + TestWorkflows.TestWorkflow1 child = + Workflow.newChildWorkflowStub(TestWorkflows.TestWorkflow1.class, options); + try { + child.execute(taskQueue); + fail("unreachable"); + } catch (RuntimeException e) { + Throwable c1 = e.getCause(); + Throwable c2 = c1.getCause(); + Throwable c3 = c2.getCause(); + Throwable c4 = c3.getCause(); + try { + assertNoEmptyStacks(e); + assertTrue(e.getMessage().contains("TestWorkflow1")); + assertTrue(e instanceof ChildWorkflowFailure); + assertTrue(c1 instanceof ApplicationFailure); + assertEquals(NumberFormatException.class.getName(), ((ApplicationFailure) c1).getType()); + assertEquals(Throwable.class.getName(), ((ApplicationFailure) c2).getType()); + assertTrue(c3 instanceof ActivityFailure); + assertTrue(c4 instanceof ApplicationFailure); + assertEquals(IOException.class.getName(), ((ApplicationFailure) c4).getType()); + assertEquals( + "message='simulated IO problem', type='java.io.IOException', nonRetryable=false", + c4.getMessage()); + } catch (AssertionError ae) { + // Errors cause workflow task to fail. But we want workflow to fail in this case. + throw new RuntimeException(ae); + } + Exception fnf = new FileNotFoundException("simulated exception"); + fnf.initCause(e); + throw Workflow.wrap(fnf); + } + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java new file mode 100644 index 0000000000..769065949b --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java @@ -0,0 +1,111 @@ +/* + * 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.client.WorkflowClient; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; +import java.util.concurrent.ExecutionException; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class ExecuteTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testExecute() throws ExecutionException, InterruptedException { + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class); + Assert.assertEquals("func", WorkflowClient.execute(stubF::func).get()); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class); + Assert.assertEquals(1, (int) WorkflowClient.execute(stubF1::func1, 1).get()); + Assert.assertEquals(1, stubF1.func1(1)); // Check that duplicated start just returns the result. + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2 stubF2 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2.class); + Assert.assertEquals("12", WorkflowClient.execute(stubF2::func2, "1", 2).get()); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc3 stubF3 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc3.class); + Assert.assertEquals("123", WorkflowClient.execute(stubF3::func3, "1", 2, 3).get()); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc4 stubF4 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc4.class); + Assert.assertEquals("1234", WorkflowClient.execute(stubF4::func4, "1", 2, 3, 4).get()); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc5 stubF5 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc5.class); + Assert.assertEquals("12345", WorkflowClient.execute(stubF5::func5, "1", 2, 3, 4, 5).get()); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc6 stubF6 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc6.class); + Assert.assertEquals("123456", WorkflowClient.execute(stubF6::func6, "1", 2, 3, 4, 5, 6).get()); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc stubP = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc.class); + WorkflowClient.execute(stubP::proc).get(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc1 stubP1 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc1.class); + WorkflowClient.execute(stubP1::proc1, "1").get(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc2 stubP2 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc2.class); + WorkflowClient.execute(stubP2::proc2, "1", 2).get(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc3 stubP3 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc3.class); + WorkflowClient.execute(stubP3::proc3, "1", 2, 3).get(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc4 stubP4 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc4.class); + WorkflowClient.execute(stubP4::proc4, "1", 2, 3, 4).get(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc5 stubP5 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc5.class); + WorkflowClient.execute(stubP5::proc5, "1", 2, 3, 4, 5).get(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc6 stubP6 = + testWorkflowRule.newWorkflowStubTimeoutOptions( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc6.class); + WorkflowClient.execute(stubP6::proc6, "1", 2, 3, 4, 5, 6).get(); + + Assert.assertEquals("proc", stubP.query()); + Assert.assertEquals("1", stubP1.query()); + Assert.assertEquals("12", stubP2.query()); + Assert.assertEquals("123", stubP3.query()); + Assert.assertEquals("1234", stubP4.query()); + Assert.assertEquals("12345", stubP5.query()); + Assert.assertEquals("123456", stubP6.query()); + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/GenericParametersWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/GenericParametersWorkflowTest.java new file mode 100644 index 0000000000..16db2cdb9f --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/GenericParametersWorkflowTest.java @@ -0,0 +1,141 @@ +/* + * 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.activity.ActivityInterface; +import io.temporal.client.WorkflowClient; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestOptions; +import java.time.Duration; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class GenericParametersWorkflowTest { + + private final GenericParametersActivityImpl activitiesImpl = new GenericParametersActivityImpl(); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(GenericParametersWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testGenericParametersWorkflow() throws ExecutionException, InterruptedException { + GenericParametersWorkflow workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(GenericParametersWorkflow.class); + List uuidList = new ArrayList(); + uuidList.add(UUID.randomUUID()); + uuidList.add(UUID.randomUUID()); + Set uuidSet = new HashSet(); + uuidSet.add(UUID.randomUUID()); + uuidSet.add(UUID.randomUUID()); + uuidSet.add(UUID.randomUUID()); + CompletableFuture> resultF = + WorkflowClient.execute( + workflowStub::execute, testWorkflowRule.getTaskQueue(), uuidList, uuidSet); + // Test signal and query serialization + workflowStub.signal(uuidList); + testWorkflowRule.sleep(Duration.ofSeconds(1)); + List queryArg = new ArrayList(); + queryArg.add(UUID.randomUUID()); + queryArg.add(UUID.randomUUID()); + List queryResult = workflowStub.query(queryArg); + List expectedQueryResult = new ArrayList(); + expectedQueryResult.addAll(queryArg); + expectedQueryResult.addAll(uuidList); + expectedQueryResult.sort(UUID::compareTo); + queryResult.sort(UUID::compareTo); + Assert.assertEquals(expectedQueryResult, queryResult); + workflowStub.signal(new ArrayList()); // empty list unblocks workflow await. + // test workflow result serialization + List expectedResult = new ArrayList(); + expectedResult.addAll(uuidList); + expectedResult.addAll(uuidSet); + List result = resultF.get(); + result.sort(UUID::compareTo); + expectedResult.sort(UUID::compareTo); + Assert.assertEquals(expectedResult, result); + } + + @ActivityInterface + public interface GenericParametersActivity { + + List execute(List arg1, Set arg2); + } + + @WorkflowInterface + public interface GenericParametersWorkflow { + + @WorkflowMethod + List execute(String taskQueue, List arg1, Set arg2); + + @SignalMethod + void signal(List arg); + + @QueryMethod + List query(List arg); + } + + public static class GenericParametersActivityImpl implements GenericParametersActivity { + + @Override + public List execute(List arg1, Set arg2) { + List result = new ArrayList<>(); + result.addAll(arg1); + result.addAll(arg2); + return result; + } + } + + public static class GenericParametersWorkflowImpl implements GenericParametersWorkflow { + + private List signaled; + private GenericParametersActivity activity; + + @Override + public List execute(String taskQueue, List arg1, Set arg2) { + Workflow.await(() -> signaled != null && signaled.size() == 0); + activity = + Workflow.newActivityStub( + GenericParametersActivity.class, + TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + return activity.execute(arg1, arg2); + } + + @Override + public void signal(List arg) { + signaled = arg; + } + + @Override + public List query(List arg) { + List result = new ArrayList<>(); + result.addAll(arg); + result.addAll(signaled); + return result; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java new file mode 100644 index 0000000000..57e13b3fc5 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java @@ -0,0 +1,68 @@ +/* + * 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.client.WorkflowOptions; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestOptions; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class GetAttemptFromWorkflowInfoTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes( + WorkflowTest.TestMultiargsWorkflowsFuncParent.class, + TestAttemptReturningWorkflowFunc.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testGetAttemptFromWorkflowInfo() { + String workflowId = "testGetAttemptWorkflow"; + WorkflowOptions workflowOptions = + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setWorkflowId(workflowId) + .build(); + WorkflowTest.TestGetAttemptWorkflowsFunc workflow = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(WorkflowTest.TestGetAttemptWorkflowsFunc.class, workflowOptions); + int attempt = workflow.func(); + Assert.assertEquals(1, attempt); + } + + public static class TestAttemptReturningWorkflowFunc + implements WorkflowTest.TestGetAttemptWorkflowsFunc { + @Override + public int func() { + WorkflowInfo wi = Workflow.getInfo(); + return wi.getAttempt(); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/LargeHistoryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/LargeHistoryTest.java new file mode 100644 index 0000000000..e5ac5bdb01 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/LargeHistoryTest.java @@ -0,0 +1,91 @@ +/* + * 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.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestOptions; +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LargeHistoryTest { + + private static final Logger log = LoggerFactory.getLogger(LargeHistoryTest.class); + private final TestLargeWorkflowActivityImpl activitiesImpl = new TestLargeWorkflowActivityImpl(); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestLargeHistory.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + @Ignore // Requires DEBUG_TIMEOUTS=true + public void testLargeHistory() { + final int activityCount = 1000; + WorkflowTest.TestLargeWorkflow workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + WorkflowTest.TestLargeWorkflow.class, + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setWorkflowTaskTimeout(Duration.ofSeconds(30)) + .build()); + long start = System.currentTimeMillis(); + String result = workflowStub.execute(activityCount, testWorkflowRule.getTaskQueue()); + long duration = System.currentTimeMillis() - start; + log.info(testWorkflowRule.getTestEnvironment().getNamespace() + " duration is " + duration); + Assert.assertEquals("done", result); + } + + public static class TestLargeWorkflowActivityImpl + implements WorkflowTest.TestLargeWorkflowActivity { + @Override + public String activity() { + return "done"; + } + } + + public static class TestLargeHistory implements WorkflowTest.TestLargeWorkflow { + + @Override + public String execute(int activityCount, String taskQueue) { + WorkflowTest.TestLargeWorkflowActivity activities = + Workflow.newActivityStub( + WorkflowTest.TestLargeWorkflowActivity.class, + TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + List> results = new ArrayList<>(); + for (int i = 0; i < activityCount; i++) { + Promise result = Async.function(activities::activity); + results.add(result); + } + Promise.allOf(results).get(); + return "done"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java new file mode 100644 index 0000000000..3c1fe83d4f --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java @@ -0,0 +1,91 @@ +/* + * 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 com.google.protobuf.ByteString; +import com.uber.m3.tally.NoopScope; +import io.temporal.api.common.v1.Memo; +import io.temporal.api.common.v1.Payload; +import io.temporal.api.common.v1.WorkflowExecution; +import io.temporal.api.history.v1.HistoryEvent; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import io.temporal.common.converter.GsonJsonPayloadConverter; +import io.temporal.internal.common.WorkflowExecutionUtils; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; +import io.temporal.workflow.shared.TestOptions; +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class MemoTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testMemo() { + if (testWorkflowRule.getTestEnvironment() != null) { + String testMemoKey = "testKey"; + String testMemoValue = "testValue"; + Map memo = new HashMap(); + memo.put(testMemoKey, testMemoValue); + + WorkflowOptions workflowOptions = + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setMemo(memo) + .build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, + workflowOptions); + WorkflowExecution executionF = WorkflowClient.start(stubF::func); + + GetWorkflowExecutionHistoryResponse historyResp = + WorkflowExecutionUtils.getHistoryPage( + testWorkflowRule.getTestEnvironment().getWorkflowService(), + SDKTestWorkflowRule.NAMESPACE, + executionF, + ByteString.EMPTY, + new NoopScope()); + HistoryEvent startEvent = historyResp.getHistory().getEvents(0); + Memo memoFromEvent = startEvent.getWorkflowExecutionStartedEventAttributes().getMemo(); + Payload memoBytes = memoFromEvent.getFieldsMap().get(testMemoKey); + String memoRetrieved = + GsonJsonPayloadConverter.getInstance().fromData(memoBytes, String.class, String.class); + Assert.assertEquals(testMemoValue, memoRetrieved); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java new file mode 100644 index 0000000000..2fa1f1846d --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java @@ -0,0 +1,67 @@ +/* + * 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.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class MultipleTimersTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestMultipleTimersImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testMultipleTimers() { + TestMultipleTimers workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestMultipleTimers.class); + long result = workflowStub.execute(); + Assert.assertTrue("should be around 1 second: " + result, result < 2000); + } + + @WorkflowInterface + public interface TestMultipleTimers { + @WorkflowMethod + long execute(); + } + + public static class TestMultipleTimersImpl implements TestMultipleTimers { + + @Override + public long execute() { + Promise t1 = Async.procedure(() -> Workflow.sleep(Duration.ofSeconds(1))); + Promise t2 = Async.procedure(() -> Workflow.sleep(Duration.ofSeconds(2))); + long start = Workflow.currentTimeMillis(); + Promise.anyOf(t1, t2).get(); + long elapsed = Workflow.currentTimeMillis() - start; + return elapsed; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java new file mode 100644 index 0000000000..6ae3960e11 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java @@ -0,0 +1,89 @@ +/* + * 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.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import java.util.*; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class MutableSideEffectTest { + + private static final Map> mutableSideEffectValue = + Collections.synchronizedMap(new HashMap<>()); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestMutableSideEffectWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testMutableSideEffect() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + ArrayDeque values = new ArrayDeque(); + values.add(1234L); + values.add(1234L); + values.add(123L); // expected to be ignored as it is smaller than 1234. + values.add(3456L); + values.add(1234L); // expected to be ignored as it is smaller than 3456L. + values.add(4234L); + values.add(4234L); + values.add(3456L); // expected to be ignored as it is smaller than 4234L. + mutableSideEffectValue.put(testWorkflowRule.getTaskQueue(), values); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("1234, 1234, 1234, 3456, 3456, 4234, 4234, 4234", result); + } + + public static class TestMutableSideEffectWorkflowImpl implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + StringBuilder result = new StringBuilder(); + for (int j = 0; j < 1; j++) { + for (int i = 0; i < 8; i++) { + long value = + Workflow.mutableSideEffect( + "id1", + Long.class, + (o, n) -> n > o, + () -> mutableSideEffectValue.get(taskQueue).poll()); + if (result.length() > 0) { + result.append(", "); + } + result.append(value); + // Sleep is here to ensure that mutableSideEffect works when replaying a history. + if (i >= 8) { + Workflow.sleep(Duration.ofSeconds(1)); + } + } + } + return result.toString(); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java new file mode 100644 index 0000000000..e618014eca --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java @@ -0,0 +1,87 @@ +/* + * 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.client.WorkflowClient; +import io.temporal.client.WorkflowStub; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import java.lang.management.ManagementFactory; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class NoQueryThreadLeakTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestNoQueryWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testNoQueryThreadLeak() throws InterruptedException { + int threadCount = ManagementFactory.getThreadMXBean().getThreadCount(); + WorkflowTest.QueryableWorkflow client = + testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.QueryableWorkflow.class); + WorkflowClient.start(client::execute); + testWorkflowRule.sleep(Duration.ofSeconds(1)); + // Calls query multiple times to check at the end of the method that if it doesn't leak threads + int queryCount = 100; + for (int i = 0; i < queryCount; i++) { + Assert.assertEquals("some state", client.getState()); + if (SDKTestWorkflowRule.useExternalService) { + // Sleep a little bit to avoid server throttling error. + Thread.sleep(50); + } + } + client.mySignal("Hello "); + WorkflowStub.fromTyped(client).getResult(String.class); + // Ensures that no threads were leaked due to query + int threadsCreated = ManagementFactory.getThreadMXBean().getThreadCount() - threadCount; + Assert.assertTrue("query leaks threads: " + threadsCreated, threadsCreated < queryCount); + } + + public static class TestNoQueryWorkflowImpl implements WorkflowTest.QueryableWorkflow { + + CompletablePromise promise = Workflow.newPromise(); + + @Override + public String execute() { + promise.get(); + return "done"; + } + + @Override + public String getState() { + return "some state"; + } + + @Override + public void mySignal(String value) { + promise.complete(null); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java new file mode 100644 index 0000000000..1288c9b9bc --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java @@ -0,0 +1,82 @@ +/* + * 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.api.enums.v1.WorkflowIdReusePolicy; +import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class ParentContinueAsNewTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestParentWorkflowContinueAsNew.class, WorkflowTest.TestChild.class) + .setActivityImplementations(activitiesImpl) + .build(); + + /** Reproduction of a bug when a child of continued as new workflow has the same UUID ID. */ + @Test + public void testParentContinueAsNew() { + + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofSeconds(200)) + .setWorkflowTaskTimeout(Duration.ofSeconds(60)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + TestWorkflows.TestWorkflow1 client = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); + Assert.assertEquals("foo", client.execute("not empty")); + } + + public static class TestParentWorkflowContinueAsNew implements TestWorkflows.TestWorkflow1 { + + private final WorkflowTest.ITestChild child1 = + Workflow.newChildWorkflowStub( + WorkflowTest.ITestChild.class, + ChildWorkflowOptions.newBuilder() + .setWorkflowIdReusePolicy( + WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE) + .build()); + private final TestWorkflows.TestWorkflow1 self = + Workflow.newContinueAsNewStub(TestWorkflows.TestWorkflow1.class); + + @Override + public String execute(String arg) { + child1.execute("Hello", 0); + if (arg.length() > 0) { + self.execute(""); // continue as new + } + return "foo"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java new file mode 100644 index 0000000000..b7321c38a2 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java @@ -0,0 +1,70 @@ +/* + * 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.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class PolymorphicStartTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(WorkflowAImpl.class, WorkflowBImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testPolymorphicStart() { + WorkflowTest.WorkflowBase[] stubs = + new WorkflowTest.WorkflowBase[] { + testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowA.class), + testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowB.class) + }; + String results = stubs[0].execute("0") + ", " + stubs[1].execute("1"); + Assert.assertEquals("WorkflowAImpl0, WorkflowBImpl1", results); + } + + @WorkflowInterface + public interface WorkflowA extends WorkflowTest.WorkflowBase {} + + @WorkflowInterface + public interface WorkflowB extends WorkflowTest.WorkflowBase {} + + public static class WorkflowBImpl implements WorkflowB { + @Override + public String execute(String arg) { + return "WorkflowBImpl" + arg; + } + } + + public static class WorkflowAImpl implements WorkflowA { + @Override + public String execute(String arg) { + return "WorkflowAImpl" + arg; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java new file mode 100644 index 0000000000..ec6b5cc88f --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java @@ -0,0 +1,79 @@ +/* + * 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 io.temporal.workflow.shared.TestActivities; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class SagaTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes( + WorkflowTest.TestSagaWorkflowImpl.class, + WorkflowTest.TestMultiargsWorkflowsFuncImpl.class, + WorkflowTest.TestCompensationWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testSaga() { + WorkflowTest.TestSagaWorkflow sagaWorkflow = + testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.TestSagaWorkflow.class); + sagaWorkflow.execute(testWorkflowRule.getTaskQueue(), false); + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "executeActivity customActivity1", + "activity customActivity1", + "executeChildWorkflow TestMultiargsWorkflowsFunc", + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "executeActivity ThrowIO", + "activity ThrowIO", + "executeChildWorkflow TestCompensationWorkflow", + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "executeActivity Activity2", + "activity Activity2"); + } + + @Test + public void testSagaParallelCompensation() { + WorkflowTest.TestSagaWorkflow sagaWorkflow = + testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.TestSagaWorkflow.class); + sagaWorkflow.execute(testWorkflowRule.getTaskQueue(), true); + String trace = testWorkflowRule.getInterceptor(TracingWorkerInterceptor.class).getTrace(); + Assert.assertTrue(trace, trace.contains("executeChildWorkflow TestCompensationWorkflow")); + Assert.assertTrue(trace, trace.contains("executeActivity Activity2")); + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java new file mode 100644 index 0000000000..2da852cb25 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java @@ -0,0 +1,126 @@ +/* + * 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 com.google.protobuf.ByteString; +import com.uber.m3.tally.NoopScope; +import io.temporal.api.common.v1.Payload; +import io.temporal.api.common.v1.SearchAttributes; +import io.temporal.api.common.v1.WorkflowExecution; +import io.temporal.api.history.v1.HistoryEvent; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import io.temporal.common.converter.DataConverter; +import io.temporal.internal.common.WorkflowExecutionUtils; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; +import io.temporal.workflow.shared.TestOptions; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class SearchAttributesTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testSearchAttributes() { + if (testWorkflowRule.getTestEnvironment() != null) { + String testKeyString = "CustomKeywordField"; + String testValueString = "testKeyword"; + String testKeyInteger = "CustomIntField"; + Integer testValueInteger = 1; + String testKeyDateTime = "CustomDateTimeField"; + LocalDateTime testValueDateTime = LocalDateTime.now(); + String testKeyBool = "CustomBoolField"; + Boolean testValueBool = true; + String testKeyDouble = "CustomDoubleField"; + Double testValueDouble = 1.23; + + // add more type to test + Map searchAttr = new HashMap(); + searchAttr.put(testKeyString, testValueString); + searchAttr.put(testKeyInteger, testValueInteger); + searchAttr.put(testKeyDateTime, testValueDateTime); + searchAttr.put(testKeyBool, testValueBool); + searchAttr.put(testKeyDouble, testValueDouble); + + WorkflowOptions workflowOptions = + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setSearchAttributes(searchAttr) + .build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, + workflowOptions); + WorkflowExecution executionF = WorkflowClient.start(stubF::func); + + GetWorkflowExecutionHistoryResponse historyResp = + WorkflowExecutionUtils.getHistoryPage( + testWorkflowRule.getTestEnvironment().getWorkflowService(), + SDKTestWorkflowRule.NAMESPACE, + executionF, + ByteString.EMPTY, + new NoopScope()); + HistoryEvent startEvent = historyResp.getHistory().getEvents(0); + SearchAttributes searchAttrFromEvent = + startEvent.getWorkflowExecutionStartedEventAttributes().getSearchAttributes(); + + Map fieldsMap = searchAttrFromEvent.getIndexedFieldsMap(); + Payload searchAttrStringBytes = fieldsMap.get(testKeyString); + DataConverter converter = DataConverter.getDefaultInstance(); + String retrievedString = + converter.fromPayload(searchAttrStringBytes, String.class, String.class); + Assert.assertEquals(testValueString, retrievedString); + Payload searchAttrIntegerBytes = fieldsMap.get(testKeyInteger); + Integer retrievedInteger = + converter.fromPayload(searchAttrIntegerBytes, Integer.class, Integer.class); + Assert.assertEquals(testValueInteger, retrievedInteger); + Payload searchAttrDateTimeBytes = fieldsMap.get(testKeyDateTime); + LocalDateTime retrievedDateTime = + converter.fromPayload(searchAttrDateTimeBytes, LocalDateTime.class, LocalDateTime.class); + Assert.assertEquals(testValueDateTime, retrievedDateTime); + Payload searchAttrBoolBytes = fieldsMap.get(testKeyBool); + Boolean retrievedBool = + converter.fromPayload(searchAttrBoolBytes, Boolean.class, Boolean.class); + Assert.assertEquals(testValueBool, retrievedBool); + Payload searchAttrDoubleBytes = fieldsMap.get(testKeyDouble); + Double retrievedDouble = + converter.fromPayload(searchAttrDoubleBytes, Double.class, Double.class); + Assert.assertEquals(testValueDouble, retrievedDouble); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java new file mode 100644 index 0000000000..b6bf1a6f98 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java @@ -0,0 +1,89 @@ +/* + * 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 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 SideEffectTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestSideEffectWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testSideEffect() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("activity1", result); + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "currentTimeMillis", + "sideEffect", + "sideEffect", + "sleep PT1S", + "executeActivity customActivity1", + "activity customActivity1"); + } + + public static class TestSideEffectWorkflowImpl implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + TestActivities testActivities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + + long workflowTime = Workflow.currentTimeMillis(); + long time1 = Workflow.sideEffect(long.class, () -> workflowTime); + long time2 = Workflow.sideEffect(long.class, () -> workflowTime); + assertEquals(time1, time2); + Workflow.sleep(Duration.ofSeconds(1)); + String result; + if (workflowTime == time1) { + result = "activity" + testActivities.activity1(1); + } else { + result = testActivities.activity2("activity2", 2); + } + return result; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java new file mode 100644 index 0000000000..96f64752fd --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java @@ -0,0 +1,199 @@ +/* + * 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.api.common.v1.WorkflowExecution; +import io.temporal.api.enums.v1.WorkflowIdReusePolicy; +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; +import io.temporal.workflow.shared.TestOptions; +import java.util.Optional; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class StartTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testStart() { + WorkflowOptions workflowOptions = + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setWorkflowIdReusePolicy( + WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE) + .build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); + assertResult("func", WorkflowClient.start(stubF::func)); + Assert.assertEquals( + "func", stubF.func()); // Check that duplicated start just returns the result. + WorkflowOptions options = + WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, options); + + if (!SDKTestWorkflowRule.useExternalService) { + // Use worker that polls on a task queue configured through @WorkflowMethod annotation of + // func1 + assertResult(1, WorkflowClient.start(stubF1::func1, 1)); + Assert.assertEquals( + 1, stubF1.func1(1)); // Check that duplicated start just returns the result. + } + // Check that duplicated start is not allowed for AllowDuplicate IdReusePolicy + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2 stubF2 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2.class, + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setWorkflowIdReusePolicy( + WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE) + .build()); + assertResult("12", WorkflowClient.start(stubF2::func2, "1", 2)); + try { + stubF2.func2("1", 2); + Assert.fail("unreachable"); + } catch (IllegalStateException e) { + // expected + } + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc3 stubF3 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc3.class, workflowOptions); + assertResult("123", WorkflowClient.start(stubF3::func3, "1", 2, 3)); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc4 stubF4 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc4.class, workflowOptions); + assertResult("1234", WorkflowClient.start(stubF4::func4, "1", 2, 3, 4)); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc5 stubF5 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc5.class, workflowOptions); + assertResult("12345", WorkflowClient.start(stubF5::func5, "1", 2, 3, 4, 5)); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc6 stubF6 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc6.class, workflowOptions); + assertResult("123456", WorkflowClient.start(stubF6::func6, "1", 2, 3, 4, 5, 6)); + + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc stubP = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc.class, workflowOptions); + waitForProc(WorkflowClient.start(stubP::proc)); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc1 stubP1 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc1.class, workflowOptions); + waitForProc(WorkflowClient.start(stubP1::proc1, "1")); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc2 stubP2 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc2.class, workflowOptions); + waitForProc(WorkflowClient.start(stubP2::proc2, "1", 2)); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc3 stubP3 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc3.class, workflowOptions); + waitForProc(WorkflowClient.start(stubP3::proc3, "1", 2, 3)); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc4 stubP4 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc4.class, workflowOptions); + waitForProc(WorkflowClient.start(stubP4::proc4, "1", 2, 3, 4)); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc5 stubP5 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc5.class, workflowOptions); + waitForProc(WorkflowClient.start(stubP5::proc5, "1", 2, 3, 4, 5)); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc6 stubP6 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc6.class, workflowOptions); + waitForProc(WorkflowClient.start(stubP6::proc6, "1", 2, 3, 4, 5, 6)); + + Assert.assertEquals("proc", stubP.query()); + Assert.assertEquals("1", stubP1.query()); + Assert.assertEquals("12", stubP2.query()); + Assert.assertEquals("123", stubP3.query()); + Assert.assertEquals("1234", stubP4.query()); + Assert.assertEquals("12345", stubP5.query()); + Assert.assertEquals("123456", stubP6.query()); + } + + private void assertResult(String expected, WorkflowExecution execution) { + String result = + testWorkflowRule + .getWorkflowClient() + .newUntypedWorkflowStub(execution, Optional.empty()) + .getResult(String.class); + assertEquals(expected, result); + } + + private void assertResult(int expected, WorkflowExecution execution) { + int result = + testWorkflowRule + .getWorkflowClient() + .newUntypedWorkflowStub(execution, Optional.empty()) + .getResult(int.class); + assertEquals(expected, result); + } + + private void waitForProc(WorkflowExecution execution) { + testWorkflowRule + .getWorkflowClient() + .newUntypedWorkflowStub(execution, Optional.empty()) + .getResult(Void.class); + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java new file mode 100644 index 0000000000..9363edbfa8 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java @@ -0,0 +1,76 @@ +/* + * 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.client.WorkflowOptions; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class TimerCallbackBlockedTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestTimerCallbackBlockedWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + /** Test that it is not allowed to block in the timer callback thread. */ + @Test + public void testTimerCallbackBlocked() { + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofSeconds(10)) + .setWorkflowTaskTimeout(Duration.ofSeconds(1)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + TestWorkflows.TestWorkflow1 client = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); + String result = client.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("timer2Fired", result); + } + + public static class TestTimerCallbackBlockedWorkflowImpl implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + Promise timer1 = Workflow.newTimer(Duration.ZERO); + Promise timer2 = Workflow.newTimer(Duration.ofSeconds(1)); + + return timer1 + .thenApply( + e -> { + timer2.get(); + return "timer2Fired"; + }) + .get(); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java new file mode 100644 index 0000000000..838ecc4d25 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java @@ -0,0 +1,138 @@ +/* + * 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.assertTrue; + +import io.temporal.client.WorkflowOptions; +import io.temporal.testing.TracingWorkerInterceptor; +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 java.util.List; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class TimerTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestTimerWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testTimer() { + WorkflowOptions options; + if (SDKTestWorkflowRule.useExternalService) { + options = TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()); + } else { + options = + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setWorkflowRunTimeout(Duration.ofDays(1)) + .build(); + } + TestWorkflows.TestWorkflow2 client = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(TestWorkflows.TestWorkflow2.class, options); + String result = client.execute(SDKTestWorkflowRule.useExternalService); + Assert.assertEquals("testTimer", result); + if (SDKTestWorkflowRule.useExternalService) { + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "registerQuery getTrace", + "newThread workflow-method", + "newTimer PT0.7S", + "newTimer PT1.3S", + "currentTimeMillis", + "newTimer PT10S", + "currentTimeMillis", + "currentTimeMillis", + "currentTimeMillis"); + } else { + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "registerQuery getTrace", + "newThread workflow-method", + "newTimer PT11M40S", + "newTimer PT21M40S", + "currentTimeMillis", + "newTimer PT10H", + "currentTimeMillis", + "currentTimeMillis", + "currentTimeMillis"); + } + } + + public static class TestTimerWorkflowImpl implements TestWorkflows.TestWorkflow2 { + + @Override + public String execute(boolean useExternalService) { + Promise timer1; + Promise timer2; + Duration timeout1 = useExternalService ? Duration.ofMillis(700) : Duration.ofSeconds(700); + Duration timeout2 = useExternalService ? Duration.ofMillis(1300) : Duration.ofSeconds(1300); + timer1 = Workflow.newTimer(timeout1); + timer2 = Workflow.newTimer(timeout2); + long time = Workflow.currentTimeMillis(); + timer1 + .thenApply( + r -> { + // Testing that timer can be created from a callback thread. + if (useExternalService) { + Workflow.newTimer(Duration.ofSeconds(10)); + } else { + Workflow.newTimer(Duration.ofHours(10)); + } + Workflow.currentTimeMillis(); // Testing that time is available here. + return r; + }) + .get(); + timer1.get(); + long slept = Workflow.currentTimeMillis() - time; + // Also checks that rounding up to a second works. + assertTrue(slept + "<" + timeout1.toMillis(), slept >= timeout1.toMillis()); + timer2.get(); + slept = Workflow.currentTimeMillis() - time; + assertTrue(String.valueOf(slept), slept >= timeout2.toMillis()); + return "testTimer"; + } + + @Override + public List getTrace() { + throw new UnsupportedOperationException("not implemented"); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java new file mode 100644 index 0000000000..880e0591bb --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java @@ -0,0 +1,86 @@ +/* + * 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 io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestOptions; +import io.temporal.workflow.shared.TestWorkflows; +import java.util.Random; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class UUIDAndRandomTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestUUIDAndRandom.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testUUIDAndRandom() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("foo10", result); + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "sideEffect", + "sideEffect", + "executeActivity Activity2", + "activity Activity2"); + } + + public static class TestUUIDAndRandom implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + TestActivities activities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + Random rand1 = Workflow.newRandom(); + int r11 = rand1.nextInt(); + int r12 = r11 + rand1.nextInt(); + int savedInt = Workflow.sideEffect(int.class, () -> r12); + String id = Workflow.randomUUID().toString() + "-" + Workflow.randomUUID().toString(); + String savedId = Workflow.sideEffect(String.class, () -> id); + // Invoke activity in a blocking mode to ensure that asserts run after replay. + String result = activities.activity2("foo", 10); + // Assert that during replay values didn't change. + assertEquals(savedId, id); + assertEquals(savedInt, r12); + return result; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java new file mode 100644 index 0000000000..ae8decfaba --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java @@ -0,0 +1,130 @@ +/* + * 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.assertNull; + +import io.temporal.api.common.v1.SearchAttributes; +import io.temporal.api.common.v1.WorkflowExecution; +import io.temporal.api.enums.v1.EventType; +import io.temporal.api.history.v1.HistoryEvent; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; +import io.temporal.client.WorkflowClient; +import io.temporal.internal.common.SearchAttributesUtil; +import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestOptions; +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class UpsertSearchAttributesTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestUpsertSearchAttributesImpl.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testUpsertSearchAttributes() { + TestUpsertSearchAttributes testWorkflow = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestUpsertSearchAttributes.class); + WorkflowExecution execution = + WorkflowClient.start(testWorkflow::execute, testWorkflowRule.getTaskQueue(), "testKey"); + String result = testWorkflow.execute(testWorkflowRule.getTaskQueue(), "testKey"); + Assert.assertEquals("done", result); + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "upsertSearchAttributes", + "executeActivity Activity", + "activity Activity"); + GetWorkflowExecutionHistoryRequest request = + GetWorkflowExecutionHistoryRequest.newBuilder() + .setNamespace(SDKTestWorkflowRule.NAMESPACE) + .setExecution(execution) + .build(); + GetWorkflowExecutionHistoryResponse response = + testWorkflowRule + .getTestEnvironment() + .getWorkflowService() + .blockingStub() + .getWorkflowExecutionHistory(request); + + boolean found = false; + for (HistoryEvent event : response.getHistory().getEventsList()) { + if (EventType.EVENT_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES == event.getEventType()) { + found = true; + break; + } + } + Assert.assertTrue("EVENT_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES found in the history", found); + } + + @WorkflowInterface + public interface TestUpsertSearchAttributes { + @WorkflowMethod + String execute(String taskQueue, String keyword); + } + + public static class TestUpsertSearchAttributesImpl implements TestUpsertSearchAttributes { + + @Override + public String execute(String taskQueue, String keyword) { + SearchAttributes searchAttributes = Workflow.getInfo().getSearchAttributes(); + assertNull(searchAttributes); + + Map searchAttrMap = new HashMap<>(); + searchAttrMap.put("CustomKeywordField", keyword); + Workflow.upsertSearchAttributes(searchAttrMap); + + searchAttributes = Workflow.getInfo().getSearchAttributes(); + assertEquals( + "testKey", + SearchAttributesUtil.getValueFromSearchAttributes( + searchAttributes, "CustomKeywordField", String.class)); + + // Running the activity below ensures that we have one more workflow task to be executed after + // adding the search attributes. This helps with replaying the history one more time to check + // against a possible NonDeterminisicWorkflowError which could be caused by missing + // UpsertWorkflowSearchAttributes event in history. + TestActivities activities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + activities.activity(); + + return "done"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java new file mode 100644 index 0000000000..26167a7334 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java @@ -0,0 +1,66 @@ +/* + * 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.client.WorkflowFailedException; +import io.temporal.client.WorkflowStub; +import io.temporal.failure.CanceledFailure; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class WorkflowCancellationScopePromiseTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestCancellationScopePromise.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowCancellationScopePromise() { + WorkflowStub client = testWorkflowRule.newUntypedWorkflowStubTimeoutOptions("TestWorkflow1"); + client.start(testWorkflowRule.getTaskQueue()); + client.cancel(); + try { + client.getResult(String.class); + Assert.fail("unreachable"); + } catch (WorkflowFailedException e) { + Assert.assertTrue(e.getCause() instanceof CanceledFailure); + } + } + + public static class TestCancellationScopePromise implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + Promise cancellationRequest = CancellationScope.current().getCancellationRequest(); + cancellationRequest.get(); + return "done"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java new file mode 100644 index 0000000000..99f95fe46a --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java @@ -0,0 +1,103 @@ +/* + * 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.client.WorkflowException; +import io.temporal.common.RetryOptions; +import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestOptions; +import java.time.Duration; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +public class WorkflowFailureNonRetryableFlagTest { + + private static final Map retryCount = new ConcurrentHashMap<>(); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule public TestName testName = new TestName(); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestWorkflowNonRetryableFlag.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowFailureNonRetryableFlag() { + RetryOptions workflowRetryOptions = + RetryOptions.newBuilder() + .setInitialInterval(Duration.ofSeconds(1)) + .setMaximumAttempts(100) + .setBackoffCoefficient(1.0) + .build(); + WorkflowTest.TestWorkflowRetry workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + WorkflowTest.TestWorkflowRetry.class, + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setRetryOptions(workflowRetryOptions) + .build()); + try { + workflowStub.execute(testName.getMethodName()); + Assert.fail("unreachable"); + } catch (WorkflowException e) { + Assert.assertTrue(e.getCause() instanceof ApplicationFailure); + Assert.assertEquals("foo", ((ApplicationFailure) e.getCause()).getType()); + Assert.assertEquals( + "details1", ((ApplicationFailure) e.getCause()).getDetails().get(0, String.class)); + Assert.assertEquals( + Integer.valueOf(123), + ((ApplicationFailure) e.getCause()).getDetails().get(1, Integer.class)); + Assert.assertEquals( + "message='simulated 3', type='foo', nonRetryable=true", e.getCause().getMessage()); + } + } + + public static class TestWorkflowNonRetryableFlag implements WorkflowTest.TestWorkflowRetry { + + @Override + public String execute(String testName) { + AtomicInteger count = retryCount.get(testName); + if (count == null) { + count = new AtomicInteger(); + retryCount.put(testName, count); + } + int c = count.incrementAndGet(); + ApplicationFailure f = + ApplicationFailure.newFailure("simulated " + c, "foo", "details1", 123); + if (c == 3) { + f.setNonRetryable(true); + } + throw f; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java new file mode 100644 index 0000000000..060e3abc83 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java @@ -0,0 +1,88 @@ +/* + * 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.api.enums.v1.WorkflowIdReusePolicy; +import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; +import io.temporal.workflow.shared.TestOptions; +import java.util.UUID; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class WorkflowIdResuePolicyTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowIdResuePolicy() { + // When WorkflowIdReusePolicy is not AllowDuplicate the semantics is to get result for the + // previous run. + String workflowId = UUID.randomUUID().toString(); + WorkflowOptions workflowOptions = + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setWorkflowIdReusePolicy( + WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY) + .setWorkflowId(workflowId) + .build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1_1 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, workflowOptions); + Assert.assertEquals(1, stubF1_1.func1(1)); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1_2 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, workflowOptions); + Assert.assertEquals(1, stubF1_2.func1(2)); + + // Setting WorkflowIdReusePolicy to AllowDuplicate will trigger new run. + workflowOptions = + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setWorkflowIdReusePolicy( + WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE) + .setWorkflowId(workflowId) + .build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1_3 = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, workflowOptions); + Assert.assertEquals(2, stubF1_3.func1(2)); + + // Setting WorkflowIdReusePolicy to RejectDuplicate or AllowDuplicateFailedOnly does not work as + // expected. See https://github.com/uber/cadence-java-client/issues/295. + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java new file mode 100644 index 0000000000..bce8d2b0d4 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java @@ -0,0 +1,86 @@ +/* + * 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.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +import java.time.Duration; + +import static org.junit.Assert.assertEquals; + +public class WorkflowLocalsTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestWorkflowLocals.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowLocals() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("result=2, 100", result); + } + + public static class TestWorkflowLocals implements TestWorkflows.TestWorkflow1 { + + private final WorkflowThreadLocal threadLocal = + WorkflowThreadLocal.withInitial(() -> 2); + + private final WorkflowLocal workflowLocal = WorkflowLocal.withInitial(() -> 5); + + @Override + public String execute(String taskQueue) { + assertEquals(2, (int) threadLocal.get()); + assertEquals(5, (int) workflowLocal.get()); + Promise p1 = + Async.procedure( + () -> { + assertEquals(2, (int) threadLocal.get()); + threadLocal.set(10); + Workflow.sleep(Duration.ofSeconds(1)); + assertEquals(10, (int) threadLocal.get()); + assertEquals(100, (int) workflowLocal.get()); + }); + Promise p2 = + Async.procedure( + () -> { + assertEquals(2, (int) threadLocal.get()); + threadLocal.set(22); + workflowLocal.set(100); + assertEquals(22, (int) threadLocal.get()); + }); + p1.get(); + p2.get(); + return "result=" + threadLocal.get() + ", " + workflowLocal.get(); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java new file mode 100644 index 0000000000..81118f38a3 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java @@ -0,0 +1,100 @@ +/* + * 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.client.WorkflowException; +import io.temporal.common.RetryOptions; +import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestOptions; +import java.time.Duration; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +public class WorkflowRetryDoNotRetryExceptionTest { + + private static final Map retryCount = new ConcurrentHashMap<>(); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule public TestName testName = new TestName(); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestWorkflowRetryDoNotRetryException.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowRetryDoNotRetryException() { + RetryOptions workflowRetryOptions = + RetryOptions.newBuilder() + .setInitialInterval(Duration.ofSeconds(1)) + .setDoNotRetry("NonRetryable") + .setMaximumAttempts(100) + .setBackoffCoefficient(1.0) + .build(); + WorkflowTest.TestWorkflowRetry workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + WorkflowTest.TestWorkflowRetry.class, + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setRetryOptions(workflowRetryOptions) + .build()); + try { + workflowStub.execute(testName.getMethodName()); + Assert.fail("unreachable"); + } catch (WorkflowException e) { + Assert.assertTrue(e.getCause() instanceof ApplicationFailure); + Assert.assertEquals("NonRetryable", ((ApplicationFailure) e.getCause()).getType()); + Assert.assertEquals( + "message='simulated 3', type='NonRetryable', nonRetryable=false", + e.getCause().getMessage()); + } + } + + public static class TestWorkflowRetryDoNotRetryException + implements WorkflowTest.TestWorkflowRetry { + + @Override + public String execute(String testName) { + AtomicInteger count = retryCount.get(testName); + if (count == null) { + count = new AtomicInteger(); + retryCount.put(testName, count); + } + int c = count.incrementAndGet(); + if (c < 3) { + throw new IllegalArgumentException("simulated " + c); + } else { + throw ApplicationFailure.newFailure("simulated " + c, "NonRetryable"); + } + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java new file mode 100644 index 0000000000..e912e39b81 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java @@ -0,0 +1,101 @@ +/* + * 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.client.WorkflowException; +import io.temporal.common.RetryOptions; +import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestOptions; +import java.time.Duration; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +public class WorkflowRetryTest { + + private static final Map retryCount = new ConcurrentHashMap<>(); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule public TestName testName = new TestName(); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestWorkflowRetryImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowRetry() { + RetryOptions workflowRetryOptions = + RetryOptions.newBuilder() + .setInitialInterval(Duration.ofSeconds(1)) + .setMaximumAttempts(3) + .setBackoffCoefficient(1.0) + .build(); + WorkflowTest.TestWorkflowRetry workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + WorkflowTest.TestWorkflowRetry.class, + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setRetryOptions(workflowRetryOptions) + .build()); + long start = testWorkflowRule.getTestEnvironment().currentTimeMillis(); + try { + workflowStub.execute(testName.getMethodName()); + Assert.fail("unreachable"); + } catch (WorkflowException e) { + Assert.assertEquals( + e.toString(), + "message='simulated 3', type='test', nonRetryable=false", + e.getCause().getMessage()); + } finally { + long elapsed = testWorkflowRule.getTestEnvironment().currentTimeMillis() - start; + Assert.assertTrue( + String.valueOf(elapsed), elapsed >= 2000); // Ensure that retry delays the restart + } + } + + public static class TestWorkflowRetryImpl implements WorkflowTest.TestWorkflowRetry { + + @Override + public String execute(String testName) { + AtomicInteger count = retryCount.get(testName); + if (count == null) { + count = new AtomicInteger(); + retryCount.put(testName, count); + } + int attempt = Workflow.getInfo().getAttempt(); + assertEquals(count.get() + 1, attempt); + throw ApplicationFailure.newFailure("simulated " + count.incrementAndGet(), "test"); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java new file mode 100644 index 0000000000..54530ef4f5 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java @@ -0,0 +1,91 @@ +/* + * 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.client.WorkflowException; +import io.temporal.failure.ApplicationFailure; +import io.temporal.worker.WorkflowImplementationOptions; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +public class WorkflowRetryWithMethodRetryDoNotRetryExceptionTest { + + private static final Map retryCount = new ConcurrentHashMap<>(); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule public TestName testName = new TestName(); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes( + WorkflowImplementationOptions.newBuilder() + .setFailWorkflowExceptionTypes( + IllegalStateException.class, IllegalArgumentException.class) + .build(), + TestWorkflowRetryWithMethodRetryImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowRetryWithMethodRetryDoNotRetryException() { + WorkflowTest.TestWorkflowRetryWithMethodRetry workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions( + WorkflowTest.TestWorkflowRetryWithMethodRetry.class); + try { + workflowStub.execute(testName.getMethodName()); + Assert.fail("unreachable"); + } catch (WorkflowException e) { + Assert.assertTrue(e.getCause() instanceof ApplicationFailure); + Assert.assertEquals( + IllegalArgumentException.class.getName(), ((ApplicationFailure) e.getCause()).getType()); + Assert.assertEquals( + "message='simulated 3', type='java.lang.IllegalArgumentException', nonRetryable=false", + e.getCause().getMessage()); + } + } + + public static class TestWorkflowRetryWithMethodRetryImpl + implements WorkflowTest.TestWorkflowRetryWithMethodRetry { + + @Override + public String execute(String testName) { + AtomicInteger count = retryCount.get(testName); + if (count == null) { + count = new AtomicInteger(); + retryCount.put(testName, count); + } + int c = count.incrementAndGet(); + if (c < 3) { + throw new IllegalStateException("simulated " + c); + } else { + throw new IllegalArgumentException("simulated " + c); + } + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java new file mode 100644 index 0000000000..93962d716a --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java @@ -0,0 +1,99 @@ +/* + * 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.api.enums.v1.EventType; +import io.temporal.api.history.v1.HistoryEvent; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; +import io.temporal.client.WorkflowOptions; +import io.temporal.client.WorkflowStub; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class WorkflowTaskFailureBackoffTest { + + private static int testWorkflowTaskFailureBackoffReplayCount; + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestWorkflowTaskFailureBackoff.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowTaskFailureBackoff() { + testWorkflowTaskFailureBackoffReplayCount = 0; + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofSeconds(10)) + .setWorkflowTaskTimeout(Duration.ofSeconds(1)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); + long start = testWorkflowRule.getTestEnvironment().currentTimeMillis(); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + long elapsed = testWorkflowRule.getTestEnvironment().currentTimeMillis() - start; + Assert.assertTrue("spinned on fail workflow task", elapsed > 1000); + Assert.assertEquals("result1", result); + GetWorkflowExecutionHistoryRequest request = + GetWorkflowExecutionHistoryRequest.newBuilder() + .setNamespace(SDKTestWorkflowRule.NAMESPACE) + .setExecution(WorkflowStub.fromTyped(workflowStub).getExecution()) + .build(); + GetWorkflowExecutionHistoryResponse response = + testWorkflowRule + .getTestEnvironment() + .getWorkflowService() + .blockingStub() + .getWorkflowExecutionHistory(request); + + int failedTaskCount = 0; + for (HistoryEvent event : response.getHistory().getEventsList()) { + if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_FAILED) { + failedTaskCount++; + } + } + Assert.assertEquals(1, failedTaskCount); + } + + public static class TestWorkflowTaskFailureBackoff implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + if (testWorkflowTaskFailureBackoffReplayCount++ < 2) { + throw new Error("simulated workflow task failure"); + } + return "result1"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java new file mode 100644 index 0000000000..8900a48388 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java @@ -0,0 +1,99 @@ +/* + * 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.api.enums.v1.EventType; +import io.temporal.api.history.v1.HistoryEvent; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; +import io.temporal.client.WorkflowOptions; +import io.temporal.client.WorkflowStub; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class WorkflowTaskNPEBackoffTest { + + private static int testWorkflowTaskFailureBackoffReplayCount; + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestWorkflowTaskNPEBackoff.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowTaskNPEBackoff() { + testWorkflowTaskFailureBackoffReplayCount = 0; + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofSeconds(10)) + .setWorkflowTaskTimeout(Duration.ofSeconds(1)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); + long start = testWorkflowRule.getTestEnvironment().currentTimeMillis(); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + long elapsed = testWorkflowRule.getTestEnvironment().currentTimeMillis() - start; + Assert.assertTrue("spinned on fail workflow task", elapsed > 1000); + Assert.assertEquals("result1", result); + GetWorkflowExecutionHistoryRequest request = + GetWorkflowExecutionHistoryRequest.newBuilder() + .setNamespace(SDKTestWorkflowRule.NAMESPACE) + .setExecution(WorkflowStub.fromTyped(workflowStub).getExecution()) + .build(); + GetWorkflowExecutionHistoryResponse response = + testWorkflowRule + .getTestEnvironment() + .getWorkflowService() + .blockingStub() + .getWorkflowExecutionHistory(request); + + int failedTaskCount = 0; + for (HistoryEvent event : response.getHistory().getEventsList()) { + if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_FAILED) { + failedTaskCount++; + } + } + Assert.assertEquals(1, failedTaskCount); + } + + public static class TestWorkflowTaskNPEBackoff implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + if (testWorkflowTaskFailureBackoffReplayCount++ < 2) { + throw new NullPointerException("simulated workflow task failure"); + } + return "result1"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java new file mode 100644 index 0000000000..291f9ae806 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java @@ -0,0 +1,82 @@ +/* + * 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.client.WorkflowOptions; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import java.time.Duration; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +public class WorkflowTaskTimeoutWorkflowTest { + + private static final Map retryCount = new ConcurrentHashMap<>(); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule public TestName testName = new TestName(); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(WorkflowTaskTimeoutWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testWorkflowTaskTimeoutWorkflow() throws InterruptedException { + + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .setWorkflowTaskTimeout(Duration.ofSeconds(1)) + .build(); + + WorkflowTest.WorkflowTaskTimeoutWorkflow stub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(WorkflowTest.WorkflowTaskTimeoutWorkflow.class, options); + String result = stub.execute(testName.getMethodName()); + Assert.assertEquals("some result", result); + } + + public static class WorkflowTaskTimeoutWorkflowImpl + implements WorkflowTest.WorkflowTaskTimeoutWorkflow { + + @Override + public String execute(String testName) throws InterruptedException { + + AtomicInteger count = retryCount.get(testName); + if (count == null) { + count = new AtomicInteger(); + retryCount.put(testName, count); + Thread.sleep(2000); + } + + return "some result"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java index 04de445ef4..cf1a1db930 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java @@ -19,237 +19,26 @@ package io.temporal.workflow; -import static io.temporal.client.WorkflowClient.QUERY_TYPE_STACK_TRACE; import static org.junit.Assert.*; -import com.google.common.util.concurrent.UncheckedExecutionException; -import com.google.protobuf.ByteString; -import com.uber.m3.tally.NoopScope; import io.temporal.activity.*; -import io.temporal.api.common.v1.Memo; -import io.temporal.api.common.v1.Payload; -import io.temporal.api.common.v1.SearchAttributes; -import io.temporal.api.common.v1.WorkflowExecution; -import io.temporal.api.enums.v1.*; -import io.temporal.api.history.v1.HistoryEvent; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; -import io.temporal.client.*; import io.temporal.common.CronSchedule; import io.temporal.common.MethodRetry; import io.temporal.common.RetryOptions; -import io.temporal.common.converter.DataConverter; -import io.temporal.common.converter.GsonJsonPayloadConverter; -import io.temporal.common.interceptors.WorkflowClientInterceptorBase; import io.temporal.failure.*; -import io.temporal.internal.common.SearchAttributesUtil; -import io.temporal.internal.common.WorkflowExecutionUtils; -import io.temporal.internal.replay.InternalWorkflowTaskException; -import io.temporal.serviceclient.WorkflowServiceStubs; -import io.temporal.serviceclient.WorkflowServiceStubsOptions; -import io.temporal.testing.*; -import io.temporal.worker.*; import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestWorkflows; import java.io.*; -import java.lang.management.ManagementFactory; -import java.lang.management.ThreadInfo; import java.text.SimpleDateFormat; import java.time.Duration; -import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import org.junit.*; -import org.junit.rules.TestName; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class WorkflowTest { - private static final Logger log = LoggerFactory.getLogger(WorkflowTest.class); - private static final String serviceAddress = System.getenv("TEMPORAL_SERVICE_ADDRESS"); - private static WorkflowServiceStubs service; - private static TestWorkflowEnvironment testEnvironment; - private static final List> delayedCallbacks = new ArrayList<>(); - private final AtomicReference lastStartedWorkflowType = new AtomicReference<>(); - private String taskQueue; - private Worker worker; - private TestActivities.TestActivitiesImpl activitiesImpl; - private WorkflowClient workflowClient; - private TracingWorkerInterceptor tracer; - private WorkerFactory workerFactory; - private static ScheduledExecutorService scheduledExecutor; - - @Rule public TestName testName = new TestName(); - - @Rule - public TestWatcher watchman = - new TestWatcher() { - @Override - protected void failed(Throwable e, Description description) { - if (tracer != null) { - System.err.println("TRACE:\n" + tracer.getTrace()); - } - if (testEnvironment != null) { - System.err.println("HISTORIES:\n" + testEnvironment.getDiagnostics()); - } - } - }; - - @BeforeClass() - public static void startService() { - if (SDKTestWorkflowRule.REGENERATE_JSON_FILES && !SDKTestWorkflowRule.useExternalService) { - throw new IllegalStateException( - "SDKTestWorkflowRule.REGENERATE_JSON_FILES is true when SDKTestWorkflowRule.useExternalService is false"); - } - if (SDKTestWorkflowRule.useExternalService) { - service = - WorkflowServiceStubs.newInstance( - WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build()); - } - } - - @AfterClass - public static void closeService() { - if (SDKTestWorkflowRule.useExternalService) { - service.shutdownNow(); - service.awaitTermination(10, TimeUnit.SECONDS); - } - } - - @Before - public void setUp() { - String testMethod = testName.getMethodName(); - if (testMethod.startsWith("testExecute") || testMethod.startsWith("testStart")) { - taskQueue = SDKTestWorkflowRule.ANNOTATION_TASK_QUEUE; - } else { - taskQueue = "WorkflowTest-" + testMethod + "-" + UUID.randomUUID().toString(); - } - TracingWorkerInterceptor.FilteredTrace trace = new TracingWorkerInterceptor.FilteredTrace(); - tracer = new TracingWorkerInterceptor(trace); - // TODO: Create a version of TestWorkflowEnvironment that runs against a real service. - lastStartedWorkflowType.set(null); - WorkflowClientOptions workflowClientOptions = - WorkflowClientOptions.newBuilder() - .setBinaryChecksum(SDKTestWorkflowRule.BINARY_CHECKSUM) - .setInterceptors( - new WorkflowClientInterceptorBase() { - @Override - public WorkflowStub newUntypedWorkflowStub( - String workflowType, WorkflowOptions options, WorkflowStub next) { - lastStartedWorkflowType.set(workflowType); - return next; - } - }) - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .build(); - boolean versionTest = testMethod.contains("GetVersion") || testMethod.contains("Deterministic"); - WorkerFactoryOptions factoryOptions = - WorkerFactoryOptions.newBuilder() - .setWorkerInterceptors(tracer) - .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) - .setWorkflowHostLocalTaskQueueScheduleToStartTimeout( - versionTest ? Duration.ZERO : Duration.ofSeconds(10)) - .build(); - if (SDKTestWorkflowRule.useExternalService) { - workflowClient = WorkflowClient.newInstance(service, workflowClientOptions); - workerFactory = WorkerFactory.newInstance(workflowClient, factoryOptions); - WorkerOptions workerOptions = - WorkerOptions.newBuilder().setMaxConcurrentActivityExecutionSize(1000).build(); - - worker = workerFactory.newWorker(taskQueue, workerOptions); - scheduledExecutor = new ScheduledThreadPoolExecutor(1); - } else { - TestEnvironmentOptions testOptions = - TestEnvironmentOptions.newBuilder() - .setWorkflowClientOptions(workflowClientOptions) - .setWorkerFactoryOptions(factoryOptions) - .build(); - testEnvironment = TestWorkflowEnvironment.newInstance(testOptions); - worker = testEnvironment.newWorker(taskQueue); - workflowClient = testEnvironment.getWorkflowClient(); - service = testEnvironment.getWorkflowService(); - } - - ActivityCompletionClient completionClient = workflowClient.newActivityCompletionClient(); - activitiesImpl = new TestActivities.TestActivitiesImpl(completionClient); - worker.registerActivitiesImplementations(activitiesImpl); - - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue); - - TestOptions.newActivityOptionsForTaskQueue(taskQueue); - activitiesImpl.invocations.clear(); - activitiesImpl.procResult.clear(); - } - - @After - public void tearDown() throws Throwable { - if (activitiesImpl != null) { - activitiesImpl.close(); - } - if (testEnvironment != null) { - testEnvironment.close(); - } else { - workerFactory.shutdown(); - } - for (ScheduledFuture result : delayedCallbacks) { - if (result.isDone() && !result.isCancelled()) { - try { - result.get(); - } catch (InterruptedException e) { - } catch (ExecutionException e) { - throw e.getCause(); - } - } - } - if (tracer != null) { - tracer.assertExpected(); - } - } - - private void startWorkerFor( - WorkflowImplementationOptions implementationOptions, Class... workflowTypes) { - worker.registerWorkflowImplementationTypes(implementationOptions, workflowTypes); - if (SDKTestWorkflowRule.useExternalService) { - workerFactory.start(); - } else { - testEnvironment.start(); - } - } - - private void startWorkerFor(Class... workflowTypes) { - worker.registerWorkflowImplementationTypes(workflowTypes); - if (SDKTestWorkflowRule.useExternalService) { - workerFactory.start(); - } else { - testEnvironment.start(); - } - } - - static void sleep(Duration d) { - if (SDKTestWorkflowRule.useExternalService) { - try { - Thread.sleep(d.toMillis()); - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted", e); - } - } else { - testEnvironment.sleep(d); - } - } - - long currentTimeMillis() { - if (SDKTestWorkflowRule.useExternalService) { - return System.currentTimeMillis(); - } else { - return testEnvironment.currentTimeMillis(); - } - } @WorkflowInterface public interface TestWorkflowSignaled { @@ -261,285 +50,12 @@ public interface TestWorkflowSignaled { void signal1(String arg); } - public static class TestSyncWorkflowImpl implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - TestActivities activities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - // Invoke synchronously in a separate thread for testing purposes only. - // In real workflows use - // Async.procedure(activities::activityWithDelay, 1000, true) - Promise a1 = Async.function(() -> activities.activityWithDelay(1000, true)); - Workflow.sleep(2000); - return activities.activity2(a1.get(), 10); - } - } - - @Test - public void testSync() { - startWorkerFor(TestSyncWorkflowImpl.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - String result = workflowStub.execute(taskQueue); - assertEquals("activity10", result); - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "newThread null", - "sleep PT2S", - "executeActivity ActivityWithDelay", - "activity ActivityWithDelay", - "executeActivity Activity2", - "activity Activity2"); - } - - @WorkflowInterface - public interface TestMultipleTimers { - @WorkflowMethod - long execute(); - } - - public static class TestMultipleTimersImpl implements TestMultipleTimers { - - @Override - public long execute() { - Promise t1 = Async.procedure(() -> Workflow.sleep(Duration.ofSeconds(1))); - Promise t2 = Async.procedure(() -> Workflow.sleep(Duration.ofSeconds(2))); - long start = Workflow.currentTimeMillis(); - Promise.anyOf(t1, t2).get(); - long elapsed = Workflow.currentTimeMillis() - start; - return elapsed; - } - } - - @Test - public void testMultipleTimers() { - startWorkerFor(TestMultipleTimersImpl.class); - TestMultipleTimers workflowStub = - workflowClient.newWorkflowStub( - TestMultipleTimers.class, TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - long result = workflowStub.execute(); - assertTrue("should be around 1 second: " + result, result < 2000); - } - - interface EmptyInterface {} + public interface EmptyInterface {} - interface UnrelatedInterface { + public interface UnrelatedInterface { void unrelatedMethod(); } - public static class TestHeartbeatTimeoutDetails implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - ActivityOptions options = - ActivityOptions.newBuilder() - .setTaskQueue(taskQueue) - .setHeartbeatTimeout(Duration.ofSeconds(1)) // short heartbeat timeout; - .setScheduleToCloseTimeout(Duration.ofSeconds(5)) - .build(); - - TestActivities activities = Workflow.newActivityStub(TestActivities.class, options); - try { - // false for second argument means to heartbeat once to set details and then stop. - activities.activityWithDelay(5000, false); - } catch (ActivityFailure e) { - TimeoutFailure te = (TimeoutFailure) e.getCause(); - log.info("TestHeartbeatTimeoutDetails expected timeout", e); - assertEquals(TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_CLOSE, te.getTimeoutType()); - assertTrue(te.getCause() instanceof TimeoutFailure); - assertEquals( - TimeoutType.TIMEOUT_TYPE_HEARTBEAT, ((TimeoutFailure) te.getCause()).getTimeoutType()); - return (te.getLastHeartbeatDetails().get(String.class)); - } - throw new RuntimeException("unreachable"); - } - } - - @Test - public void testHeartbeatTimeoutDetails() { - startWorkerFor(TestHeartbeatTimeoutDetails.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - String result = workflowStub.execute(taskQueue); - assertEquals("heartbeatValue", result); - } - - @Test - public void testSyncUntypedAndStackTrace() { - startWorkerFor(TestSyncWorkflowImpl.class); - WorkflowStub workflowStub = - workflowClient.newUntypedWorkflowStub( - "TestWorkflow1", TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - WorkflowExecution execution = workflowStub.start(taskQueue); - sleep(Duration.ofMillis(500)); - String stackTrace = workflowStub.query(QUERY_TYPE_STACK_TRACE, String.class); - assertTrue(stackTrace, stackTrace.contains("WorkflowTest$TestSyncWorkflowImpl.execute")); - assertTrue(stackTrace, stackTrace.contains("activityWithDelay")); - // Test stub created from workflow execution. - workflowStub = workflowClient.newUntypedWorkflowStub(execution, workflowStub.getWorkflowType()); - stackTrace = workflowStub.query(QUERY_TYPE_STACK_TRACE, String.class); - assertTrue(stackTrace, stackTrace.contains("WorkflowTest$TestSyncWorkflowImpl.execute")); - assertTrue(stackTrace, stackTrace.contains("activityWithDelay")); - String result = workflowStub.getResult(String.class); - assertEquals("activity10", result); - } - - public static class TestCancellationForWorkflowsWithFailedPromises - implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - Async.function( - () -> { - throw new UncheckedExecutionException(new Exception("Oh noo!")); - }); - Async.function( - () -> { - throw new UncheckedExecutionException(new Exception("Oh noo again!")); - }); - Workflow.await(() -> false); - fail("unreachable"); - return "done"; - } - } - - @Test - public void workflowsWithFailedPromisesCanBeCanceled() { - startWorkerFor(TestCancellationForWorkflowsWithFailedPromises.class); - WorkflowStub client = - workflowClient.newUntypedWorkflowStub( - "TestWorkflow1", TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - client.start(taskQueue); - client.cancel(); - - try { - client.getResult(String.class); - fail("unreachable"); - } catch (WorkflowFailedException e) { - assertTrue(e.getCause() instanceof CanceledFailure); - } - } - - @Test - public void testWorkflowCancellation() { - startWorkerFor(TestSyncWorkflowImpl.class); - WorkflowStub client = - workflowClient.newUntypedWorkflowStub( - "TestWorkflow1", TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - client.start(taskQueue); - client.cancel(); - try { - client.getResult(String.class); - fail("unreachable"); - } catch (WorkflowFailedException e) { - assertTrue(e.getCause() instanceof CanceledFailure); - } - } - - @Test - public void testWorkflowTermination() throws InterruptedException { - startWorkerFor(TestSyncWorkflowImpl.class); - WorkflowStub client = - workflowClient.newUntypedWorkflowStub( - "TestWorkflow1", TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - client.start(taskQueue); - Thread.sleep(1000); - client.terminate("boo", "detail1", "detail2"); - try { - client.getResult(String.class); - fail("unreachable"); - } catch (WorkflowFailedException ignored) { - assertTrue(ignored.getCause() instanceof TerminatedFailure); - assertEquals("boo", ((TerminatedFailure) ignored.getCause()).getOriginalMessage()); - } - } - - public static class TestCancellationScopePromise implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - Promise cancellationRequest = CancellationScope.current().getCancellationRequest(); - cancellationRequest.get(); - return "done"; - } - } - - @Test - public void testWorkflowCancellationScopePromise() { - startWorkerFor(TestCancellationScopePromise.class); - WorkflowStub client = - workflowClient.newUntypedWorkflowStub( - "TestWorkflow1", TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - client.start(taskQueue); - client.cancel(); - try { - client.getResult(String.class); - fail("unreachable"); - } catch (WorkflowFailedException e) { - assertTrue(e.getCause() instanceof CanceledFailure); - } - } - - 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"; - } - } - - @Test - public void testDetachedScope() { - startWorkerFor(TestDetachedCancellationScope.class); - WorkflowStub client = - workflowClient.newUntypedWorkflowStub( - "TestWorkflow1", TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - client.start(taskQueue); - sleep(Duration.ofMillis(500)); // To let activityWithDelay start. - client.cancel(); - try { - client.getResult(String.class); - fail("unreachable"); - } catch (WorkflowFailedException e) { - assertTrue(e.getCause() instanceof CanceledFailure); - } - activitiesImpl.assertInvocations("activityWithDelay", "activity1", "activity2", "activity3"); - } - @WorkflowInterface public interface TestWorkflow { @WorkflowMethod @@ -552,479 +68,12 @@ public interface TestChildWorkflow { void execute(); } - 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"; - } - } - - @Test - public void testBinaryChecksumSetWhenTaskCompleted() { - startWorkerFor(SimpleTestWorkflow.class); - TestWorkflows.TestWorkflow1 client = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - WorkflowExecution execution = WorkflowClient.start(client::execute, taskQueue); - WorkflowStub stub = WorkflowStub.fromTyped(client); - SDKTestWorkflowRule.waitForOKQuery(stub); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(execution) - .build(); - GetWorkflowExecutionHistoryResponse response = - service.blockingStub().getWorkflowExecutionHistory(request); - - boolean foundCompletedTask = false; - for (HistoryEvent event : response.getHistory().getEventsList()) { - if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_COMPLETED) { - assertEquals( - SDKTestWorkflowRule.BINARY_CHECKSUM, - event.getWorkflowTaskCompletedEventAttributes().getBinaryChecksum()); - foundCompletedTask = true; - } - } - assertTrue(foundCompletedTask); - } - - @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 memo = new HashMap<>(); - memo.put("myKey", "MyValue"); - Map 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"); - } - } - - @Test - public void testContinueAsNew() { - Worker w2; - String continuedTaskQueue = this.taskQueue + "_continued"; - if (SDKTestWorkflowRule.useExternalService) { - w2 = workerFactory.newWorker(continuedTaskQueue); - } else { - w2 = testEnvironment.newWorker(continuedTaskQueue); - } - w2.registerWorkflowImplementationTypes(TestContinueAsNewImpl.class); - startWorkerFor(TestContinueAsNewImpl.class); - - TestContinueAsNew client = - workflowClient.newWorkflowStub( - TestContinueAsNew.class, TestOptions.newWorkflowOptionsWithTimeouts(this.taskQueue)); - int result = client.execute(4, continuedTaskQueue); - assertEquals(111, result); - tracer.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 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"; - } - } - } - - @Test - public void testContinueAsNewNoArgs() { - startWorkerFor(TestContinueAsNewNoArgsImpl.class); - - NoArgsWorkflow client = - workflowClient.newWorkflowStub( - NoArgsWorkflow.class, TestOptions.newWorkflowOptionsWithTimeouts(this.taskQueue)); - String result = client.execute(); - assertEquals("done", result); - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "continueAsNew", - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method"); - } - - private void assertResult(String expected, WorkflowExecution execution) { - String result = - workflowClient.newUntypedWorkflowStub(execution, Optional.empty()).getResult(String.class); - assertEquals(expected, result); - } - - private void assertResult(int expected, WorkflowExecution execution) { - int result = - workflowClient.newUntypedWorkflowStub(execution, Optional.empty()).getResult(int.class); - assertEquals(expected, result); - } - - private void waitForProc(WorkflowExecution execution) { - workflowClient.newUntypedWorkflowStub(execution, Optional.empty()).getResult(Void.class); - } - - @Test - public void testStart() { - startWorkerFor(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class); - WorkflowOptions workflowOptions = - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setWorkflowIdReusePolicy( - WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE) - .build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); - assertResult("func", WorkflowClient.start(stubF::func)); - assertEquals("func", stubF.func()); // Check that duplicated start just returns the result. - WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(taskQueue).build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, options); - - if (!SDKTestWorkflowRule.useExternalService) { - // Use worker that polls on a task queue configured through @WorkflowMethod annotation of - // func1 - assertResult(1, WorkflowClient.start(stubF1::func1, 1)); - assertEquals(1, stubF1.func1(1)); // Check that duplicated start just returns the result. - } - // Check that duplicated start is not allowed for AllowDuplicate IdReusePolicy - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2 stubF2 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setWorkflowIdReusePolicy( - WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE) - .build()); - assertResult("12", WorkflowClient.start(stubF2::func2, "1", 2)); - try { - stubF2.func2("1", 2); - fail("unreachable"); - } catch (IllegalStateException e) { - // expected - } - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc3 stubF3 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc3.class, workflowOptions); - assertResult("123", WorkflowClient.start(stubF3::func3, "1", 2, 3)); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc4 stubF4 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc4.class, workflowOptions); - assertResult("1234", WorkflowClient.start(stubF4::func4, "1", 2, 3, 4)); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc5 stubF5 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc5.class, workflowOptions); - assertResult("12345", WorkflowClient.start(stubF5::func5, "1", 2, 3, 4, 5)); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc6 stubF6 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc6.class, workflowOptions); - assertResult("123456", WorkflowClient.start(stubF6::func6, "1", 2, 3, 4, 5, 6)); - - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc stubP = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc.class, workflowOptions); - waitForProc(WorkflowClient.start(stubP::proc)); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc1 stubP1 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc1.class, workflowOptions); - waitForProc(WorkflowClient.start(stubP1::proc1, "1")); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc2 stubP2 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc2.class, workflowOptions); - waitForProc(WorkflowClient.start(stubP2::proc2, "1", 2)); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc3 stubP3 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc3.class, workflowOptions); - waitForProc(WorkflowClient.start(stubP3::proc3, "1", 2, 3)); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc4 stubP4 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc4.class, workflowOptions); - waitForProc(WorkflowClient.start(stubP4::proc4, "1", 2, 3, 4)); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc5 stubP5 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc5.class, workflowOptions); - waitForProc(WorkflowClient.start(stubP5::proc5, "1", 2, 3, 4, 5)); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc6 stubP6 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc6.class, workflowOptions); - waitForProc(WorkflowClient.start(stubP6::proc6, "1", 2, 3, 4, 5, 6)); - - assertEquals("proc", stubP.query()); - assertEquals("1", stubP1.query()); - assertEquals("12", stubP2.query()); - assertEquals("123", stubP3.query()); - assertEquals("1234", stubP4.query()); - assertEquals("12345", stubP5.query()); - assertEquals("123456", stubP6.query()); - } - - @Test - public void testMemo() { - if (testEnvironment != null) { - String testMemoKey = "testKey"; - String testMemoValue = "testValue"; - Map memo = new HashMap<>(); - memo.put(testMemoKey, testMemoValue); - - startWorkerFor(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class); - WorkflowOptions workflowOptions = - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue).toBuilder().setMemo(memo).build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); - WorkflowExecution executionF = WorkflowClient.start(stubF::func); - - GetWorkflowExecutionHistoryResponse historyResp = - WorkflowExecutionUtils.getHistoryPage( - testEnvironment.getWorkflowService(), - SDKTestWorkflowRule.NAMESPACE, - executionF, - ByteString.EMPTY, - new NoopScope()); - HistoryEvent startEvent = historyResp.getHistory().getEvents(0); - Memo memoFromEvent = startEvent.getWorkflowExecutionStartedEventAttributes().getMemo(); - Payload memoBytes = memoFromEvent.getFieldsMap().get(testMemoKey); - String memoRetrieved = - GsonJsonPayloadConverter.getInstance().fromData(memoBytes, String.class, String.class); - assertEquals(testMemoValue, memoRetrieved); - } - } - - @Test - public void testSearchAttributes() { - if (testEnvironment != null) { - String testKeyString = "CustomKeywordField"; - String testValueString = "testKeyword"; - String testKeyInteger = "CustomIntField"; - Integer testValueInteger = 1; - String testKeyDateTime = "CustomDateTimeField"; - LocalDateTime testValueDateTime = LocalDateTime.now(); - String testKeyBool = "CustomBoolField"; - Boolean testValueBool = true; - String testKeyDouble = "CustomDoubleField"; - Double testValueDouble = 1.23; - - // add more type to test - Map searchAttr = new HashMap<>(); - searchAttr.put(testKeyString, testValueString); - searchAttr.put(testKeyInteger, testValueInteger); - searchAttr.put(testKeyDateTime, testValueDateTime); - searchAttr.put(testKeyBool, testValueBool); - searchAttr.put(testKeyDouble, testValueDouble); - - startWorkerFor(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class); - WorkflowOptions workflowOptions = - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setSearchAttributes(searchAttr) - .build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); - WorkflowExecution executionF = WorkflowClient.start(stubF::func); - - GetWorkflowExecutionHistoryResponse historyResp = - WorkflowExecutionUtils.getHistoryPage( - testEnvironment.getWorkflowService(), - SDKTestWorkflowRule.NAMESPACE, - executionF, - ByteString.EMPTY, - new NoopScope()); - HistoryEvent startEvent = historyResp.getHistory().getEvents(0); - SearchAttributes searchAttrFromEvent = - startEvent.getWorkflowExecutionStartedEventAttributes().getSearchAttributes(); - - Map fieldsMap = searchAttrFromEvent.getIndexedFieldsMap(); - Payload searchAttrStringBytes = fieldsMap.get(testKeyString); - DataConverter converter = DataConverter.getDefaultInstance(); - String retrievedString = - converter.fromPayload(searchAttrStringBytes, String.class, String.class); - assertEquals(testValueString, retrievedString); - Payload searchAttrIntegerBytes = fieldsMap.get(testKeyInteger); - Integer retrievedInteger = - converter.fromPayload(searchAttrIntegerBytes, Integer.class, Integer.class); - assertEquals(testValueInteger, retrievedInteger); - Payload searchAttrDateTimeBytes = fieldsMap.get(testKeyDateTime); - LocalDateTime retrievedDateTime = - converter.fromPayload(searchAttrDateTimeBytes, LocalDateTime.class, LocalDateTime.class); - assertEquals(testValueDateTime, retrievedDateTime); - Payload searchAttrBoolBytes = fieldsMap.get(testKeyBool); - Boolean retrievedBool = - converter.fromPayload(searchAttrBoolBytes, Boolean.class, Boolean.class); - assertEquals(testValueBool, retrievedBool); - Payload searchAttrDoubleBytes = fieldsMap.get(testKeyDouble); - Double retrievedDouble = - converter.fromPayload(searchAttrDoubleBytes, Double.class, Double.class); - assertEquals(testValueDouble, retrievedDouble); - } - } - - @Test - public void testExecute() throws ExecutionException, InterruptedException { - startWorkerFor(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class); - WorkflowOptions workflowOptions = TestOptions.newWorkflowOptionsWithTimeouts(taskQueue); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); - assertEquals("func", WorkflowClient.execute(stubF::func).get()); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, workflowOptions); - assertEquals(1, (int) WorkflowClient.execute(stubF1::func1, 1).get()); - assertEquals(1, stubF1.func1(1)); // Check that duplicated start just returns the result. - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2 stubF2 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2.class, workflowOptions); - assertEquals("12", WorkflowClient.execute(stubF2::func2, "1", 2).get()); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc3 stubF3 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc3.class, workflowOptions); - assertEquals("123", WorkflowClient.execute(stubF3::func3, "1", 2, 3).get()); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc4 stubF4 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc4.class, workflowOptions); - assertEquals("1234", WorkflowClient.execute(stubF4::func4, "1", 2, 3, 4).get()); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc5 stubF5 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc5.class, workflowOptions); - assertEquals("12345", WorkflowClient.execute(stubF5::func5, "1", 2, 3, 4, 5).get()); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc6 stubF6 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc6.class, workflowOptions); - assertEquals("123456", WorkflowClient.execute(stubF6::func6, "1", 2, 3, 4, 5, 6).get()); - - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc stubP = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc.class, workflowOptions); - WorkflowClient.execute(stubP::proc).get(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc1 stubP1 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc1.class, workflowOptions); - WorkflowClient.execute(stubP1::proc1, "1").get(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc2 stubP2 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc2.class, workflowOptions); - WorkflowClient.execute(stubP2::proc2, "1", 2).get(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc3 stubP3 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc3.class, workflowOptions); - WorkflowClient.execute(stubP3::proc3, "1", 2, 3).get(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc4 stubP4 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc4.class, workflowOptions); - WorkflowClient.execute(stubP4::proc4, "1", 2, 3, 4).get(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc5 stubP5 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc5.class, workflowOptions); - WorkflowClient.execute(stubP5::proc5, "1", 2, 3, 4, 5).get(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc6 stubP6 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsProc6.class, workflowOptions); - WorkflowClient.execute(stubP6::proc6, "1", 2, 3, 4, 5, 6).get(); - - assertEquals("proc", stubP.query()); - assertEquals("1", stubP1.query()); - assertEquals("12", stubP2.query()); - assertEquals("123", stubP3.query()); - assertEquals("1234", stubP4.query()); - assertEquals("12345", stubP5.query()); - assertEquals("123456", stubP6.query()); - } - - @Test - public void testWorkflowIdResuePolicy() { - startWorkerFor(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class); - - // When WorkflowIdReusePolicy is not AllowDuplicate the semantics is to get result for the - // previous run. - String workflowId = UUID.randomUUID().toString(); - WorkflowOptions workflowOptions = - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setWorkflowIdReusePolicy( - WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY) - .setWorkflowId(workflowId) - .build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1_1 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, workflowOptions); - assertEquals(1, stubF1_1.func1(1)); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1_2 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, workflowOptions); - assertEquals(1, stubF1_2.func1(2)); - - // Setting WorkflowIdReusePolicy to AllowDuplicate will trigger new run. - workflowOptions = - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setWorkflowIdReusePolicy( - WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE) - .setWorkflowId(workflowId) - .build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1_3 = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, workflowOptions); - assertEquals(2, stubF1_3.func1(2)); - - // Setting WorkflowIdReusePolicy to RejectDuplicate or AllowDuplicateFailedOnly does not work as - // expected. See https://github.com/uber/cadence-java-client/issues/295. - } - public static class TestUntypedChildStubWorkflow implements TestWorkflows.TestWorkflow1 { @Override @@ -1078,241 +127,6 @@ public String execute(String taskQueue) { } } - public static class TestTimerWorkflowImpl implements TestWorkflows.TestWorkflow2 { - - @Override - public String execute(boolean useExternalService) { - Promise timer1; - Promise timer2; - Duration timeout1 = useExternalService ? Duration.ofMillis(700) : Duration.ofSeconds(700); - Duration timeout2 = useExternalService ? Duration.ofMillis(1300) : Duration.ofSeconds(1300); - timer1 = Workflow.newTimer(timeout1); - timer2 = Workflow.newTimer(timeout2); - long time = Workflow.currentTimeMillis(); - timer1 - .thenApply( - r -> { - // Testing that timer can be created from a callback thread. - if (useExternalService) { - Workflow.newTimer(Duration.ofSeconds(10)); - } else { - Workflow.newTimer(Duration.ofHours(10)); - } - Workflow.currentTimeMillis(); // Testing that time is available here. - return r; - }) - .get(); - timer1.get(); - long slept = Workflow.currentTimeMillis() - time; - // Also checks that rounding up to a second works. - assertTrue(slept + "<" + timeout1.toMillis(), slept >= timeout1.toMillis()); - timer2.get(); - slept = Workflow.currentTimeMillis() - time; - assertTrue(String.valueOf(slept), slept >= timeout2.toMillis()); - return "testTimer"; - } - - @Override - public List getTrace() { - throw new UnsupportedOperationException("not implemented"); - } - } - - @Test - public void testTimer() { - startWorkerFor(TestTimerWorkflowImpl.class); - WorkflowOptions options; - if (SDKTestWorkflowRule.useExternalService) { - options = TestOptions.newWorkflowOptionsWithTimeouts(taskQueue); - } else { - options = - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setWorkflowRunTimeout(Duration.ofDays(1)) - .build(); - } - TestWorkflows.TestWorkflow2 client = - workflowClient.newWorkflowStub(TestWorkflows.TestWorkflow2.class, options); - String result = client.execute(SDKTestWorkflowRule.useExternalService); - assertEquals("testTimer", result); - if (SDKTestWorkflowRule.useExternalService) { - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "registerQuery getTrace", - "newThread workflow-method", - "newTimer PT0.7S", - "newTimer PT1.3S", - "currentTimeMillis", - "newTimer PT10S", - "currentTimeMillis", - "currentTimeMillis", - "currentTimeMillis"); - } else { - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "registerQuery getTrace", - "newThread workflow-method", - "newTimer PT11M40S", - "newTimer PT21M40S", - "currentTimeMillis", - "newTimer PT10H", - "currentTimeMillis", - "currentTimeMillis", - "currentTimeMillis"); - } - } - - @WorkflowInterface - public interface TestExceptionPropagation { - @WorkflowMethod - void execute(String taskQueue); - } - - public static class ThrowingChild implements TestWorkflows.TestWorkflow1 { - - @Override - @SuppressWarnings("AssertionFailureIgnored") - public String execute(String taskQueue) { - TestActivities testActivities = - Workflow.newActivityStub( - TestActivities.class, - TestOptions.newActivityOptions20sScheduleToClose() - .toBuilder() - .setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build()) - .build()); - try { - testActivities.throwIO(); - fail("unreachable"); - return "ignored"; - } catch (ActivityFailure e) { - try { - assertTrue(e.getMessage().contains("ThrowIO")); - assertTrue(e.getCause() instanceof ApplicationFailure); - assertEquals(IOException.class.getName(), ((ApplicationFailure) e.getCause()).getType()); - assertEquals( - "message='simulated IO problem', type='java.io.IOException', nonRetryable=false", - e.getCause().getMessage()); - } catch (AssertionError ae) { - // Errors cause workflow task to fail. But we want workflow to fail in this case. - throw new RuntimeException(ae); - } - Exception ee = new NumberFormatException(); - ee.initCause(new Throwable("simulated throwable", e)); - throw Workflow.wrap(ee); - } - } - } - - public static class TestExceptionPropagationImpl implements TestExceptionPropagation { - - @Override - @SuppressWarnings("AssertionFailureIgnored") - public void execute(String taskQueue) { - ChildWorkflowOptions options = - ChildWorkflowOptions.newBuilder().setWorkflowRunTimeout(Duration.ofHours(1)).build(); - TestWorkflows.TestWorkflow1 child = - Workflow.newChildWorkflowStub(TestWorkflows.TestWorkflow1.class, options); - try { - child.execute(taskQueue); - fail("unreachable"); - } catch (RuntimeException e) { - Throwable c1 = e.getCause(); - Throwable c2 = c1.getCause(); - Throwable c3 = c2.getCause(); - Throwable c4 = c3.getCause(); - try { - assertNoEmptyStacks(e); - assertTrue(e.getMessage().contains("TestWorkflow1")); - assertTrue(e instanceof ChildWorkflowFailure); - assertTrue(c1 instanceof ApplicationFailure); - assertEquals(NumberFormatException.class.getName(), ((ApplicationFailure) c1).getType()); - assertEquals(Throwable.class.getName(), ((ApplicationFailure) c2).getType()); - assertTrue(c3 instanceof ActivityFailure); - assertTrue(c4 instanceof ApplicationFailure); - assertEquals(IOException.class.getName(), ((ApplicationFailure) c4).getType()); - assertEquals( - "message='simulated IO problem', type='java.io.IOException', nonRetryable=false", - c4.getMessage()); - } catch (AssertionError ae) { - // Errors cause workflow task to fail. But we want workflow to fail in this case. - throw new RuntimeException(ae); - } - Exception fnf = new FileNotFoundException("simulated exception"); - fnf.initCause(e); - throw Workflow.wrap(fnf); - } - } - } - - private static void assertNoEmptyStacks(RuntimeException e) { - // Check that there are no empty stacks - Throwable c = e; - while (c != null) { - assertTrue(c.getStackTrace().length > 0); - c = c.getCause(); - } - } - - /** - * Test that an NPE thrown in an activity executed from a child workflow results in the following - * chain of exceptions when an exception is received in an external client that executed workflow - * through a WorkflowClient: - * - *

-   * {@link WorkflowFailedException}
-   *     ->{@link ChildWorkflowFailure}
-   *         ->{@link ActivityFailure}
-   *             ->OriginalActivityException
-   * 
- * - *

This test also tests that Checked exception wrapping and unwrapping works producing a nice - * exception chain without the wrappers. - */ - @Test - public void testExceptionPropagation() { - startWorkerFor( - WorkflowImplementationOptions.newBuilder() - .setFailWorkflowExceptionTypes(NumberFormatException.class, FileNotFoundException.class) - .build(), - ThrowingChild.class, - TestExceptionPropagationImpl.class); - TestExceptionPropagation client = - workflowClient.newWorkflowStub( - TestExceptionPropagation.class, TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - try { - client.execute(taskQueue); - fail("Unreachable"); - } catch (WorkflowFailedException e) { - // Rethrow the assertion failure - Throwable c1 = e.getCause(); - Throwable c2 = c1.getCause(); - Throwable c3 = c2.getCause(); - Throwable c4 = c3.getCause(); - Throwable c5 = c4.getCause(); - Throwable c6 = c5.getCause(); - if (c2 instanceof AssertionError) { - throw (AssertionError) c2; - } - assertNoEmptyStacks(e); - // Uncomment to see the actual trace. - // e.printStackTrace(); - assertTrue(e.getMessage(), e.getMessage().contains("TestExceptionPropagation")); - assertTrue(e.getStackTrace().length > 0); - assertTrue(c1 instanceof ApplicationFailure); - assertEquals(FileNotFoundException.class.getName(), ((ApplicationFailure) c1).getType()); - assertTrue(c2 instanceof ChildWorkflowFailure); - assertTrue(c3 instanceof ApplicationFailure); - assertEquals(NumberFormatException.class.getName(), ((ApplicationFailure) c3).getType()); - assertEquals(Throwable.class.getName(), ((ApplicationFailure) c4).getType()); - assertTrue(c5 instanceof ActivityFailure); - assertTrue(c6 instanceof ApplicationFailure); - assertEquals(IOException.class.getName(), ((ApplicationFailure) c6).getType()); - assertEquals( - "message='simulated IO problem', type='java.io.IOException', nonRetryable=false", - c6.getMessage()); - } - } - @WorkflowInterface public interface QueryableWorkflow { @@ -1326,85 +140,6 @@ public interface QueryableWorkflow { void mySignal(String value); } - public static class TestNoQueryWorkflowImpl implements QueryableWorkflow { - - CompletablePromise promise = Workflow.newPromise(); - - @Override - public String execute() { - promise.get(); - return "done"; - } - - @Override - public String getState() { - return "some state"; - } - - @Override - public void mySignal(String value) { - promise.complete(null); - } - } - - @Test - public void testNoQueryThreadLeak() throws InterruptedException { - startWorkerFor(TestNoQueryWorkflowImpl.class); - int threadCount = ManagementFactory.getThreadMXBean().getThreadCount(); - QueryableWorkflow client = - workflowClient.newWorkflowStub( - QueryableWorkflow.class, TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - WorkflowClient.start(client::execute); - sleep(Duration.ofSeconds(1)); - // Calls query multiple times to check at the end of the method that if it doesn't leak threads - int queryCount = 100; - for (int i = 0; i < queryCount; i++) { - assertEquals("some state", client.getState()); - if (SDKTestWorkflowRule.useExternalService) { - // Sleep a little bit to avoid server throttling error. - Thread.sleep(50); - } - } - client.mySignal("Hello "); - WorkflowStub.fromTyped(client).getResult(String.class); - // Ensures that no threads were leaked due to query - int threadsCreated = ManagementFactory.getThreadMXBean().getThreadCount() - threadCount; - assertTrue("query leaks threads: " + threadsCreated, threadsCreated < queryCount); - } - - public static class TestTimerCallbackBlockedWorkflowImpl implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - Promise timer1 = Workflow.newTimer(Duration.ZERO); - Promise timer2 = Workflow.newTimer(Duration.ofSeconds(1)); - - return timer1 - .thenApply( - e -> { - timer2.get(); - return "timer2Fired"; - }) - .get(); - } - } - - /** Test that it is not allowed to block in the timer callback thread. */ - @Test - public void testTimerCallbackBlocked() { - startWorkerFor(TestTimerCallbackBlockedWorkflowImpl.class); - WorkflowOptions options = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofSeconds(10)) - .setWorkflowTaskTimeout(Duration.ofSeconds(1)) - .setTaskQueue(taskQueue) - .build(); - TestWorkflows.TestWorkflow1 client = - workflowClient.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); - String result = client.execute(taskQueue); - assertEquals("timer2Fired", result); - } - @WorkflowInterface public interface ITestChild { @@ -1416,1296 +151,147 @@ public interface ITestChild { public interface ITestNamedChild { @WorkflowMethod(name = "namedChild") - String execute(String arg); - } - - public static class TestChild implements ITestChild { - - @Override - public String execute(String arg, int delay) { - Workflow.sleep(delay); - return arg.toUpperCase(); - } - } - - public static class TestParentWorkflowContinueAsNew implements TestWorkflows.TestWorkflow1 { - - private final ITestChild child1 = - Workflow.newChildWorkflowStub( - ITestChild.class, - ChildWorkflowOptions.newBuilder() - .setWorkflowIdReusePolicy( - WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE) - .build()); - private final TestWorkflows.TestWorkflow1 self = - Workflow.newContinueAsNewStub(TestWorkflows.TestWorkflow1.class); - - @Override - public String execute(String arg) { - child1.execute("Hello", 0); - if (arg.length() > 0) { - self.execute(""); // continue as new - } - return "foo"; - } - } - - /** Reproduction of a bug when a child of continued as new workflow has the same UUID ID. */ - @Test - public void testParentContinueAsNew() { - startWorkerFor(TestParentWorkflowContinueAsNew.class, TestChild.class); - - WorkflowOptions options = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofSeconds(200)) - .setWorkflowTaskTimeout(Duration.ofSeconds(60)) - .setTaskQueue(taskQueue) - .build(); - TestWorkflows.TestWorkflow1 client = - workflowClient.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); - assertEquals("foo", client.execute("not empty")); - } - - public static class AngryChild implements ITestChild { - - @Override - public String execute(String taskQueue, int delay) { - TestActivities.AngryChildActivity activity = - Workflow.newActivityStub( - TestActivities.AngryChildActivity.class, - ActivityOptions.newBuilder() - .setTaskQueue(taskQueue) - .setScheduleToCloseTimeout(Duration.ofSeconds(5)) - .build()); - activity.execute(); - throw ApplicationFailure.newFailure("simulated failure", "test"); - } - } - - @WorkflowInterface - public interface SignalingChild { - - @WorkflowMethod - String execute(String arg, String parentWorkflowId); - } - - private static int testWorkflowTaskFailureBackoffReplayCount; - - public static class TestWorkflowTaskFailureBackoff implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - if (testWorkflowTaskFailureBackoffReplayCount++ < 2) { - throw new Error("simulated workflow task failure"); - } - return "result1"; - } - } - - @Test - public void testWorkflowTaskFailureBackoff() { - testWorkflowTaskFailureBackoffReplayCount = 0; - startWorkerFor(TestWorkflowTaskFailureBackoff.class); - WorkflowOptions o = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofSeconds(10)) - .setWorkflowTaskTimeout(Duration.ofSeconds(1)) - .setTaskQueue(taskQueue) - .build(); - - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub(TestWorkflows.TestWorkflow1.class, o); - long start = currentTimeMillis(); - String result = workflowStub.execute(taskQueue); - long elapsed = currentTimeMillis() - start; - assertTrue("spinned on fail workflow task", elapsed > 1000); - assertEquals("result1", result); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(WorkflowStub.fromTyped(workflowStub).getExecution()) - .build(); - GetWorkflowExecutionHistoryResponse response = - service.blockingStub().getWorkflowExecutionHistory(request); - - int failedTaskCount = 0; - for (HistoryEvent event : response.getHistory().getEventsList()) { - if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_FAILED) { - failedTaskCount++; - } - } - assertEquals(1, failedTaskCount); - } - - public static class TestWorkflowTaskNPEBackoff implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - if (testWorkflowTaskFailureBackoffReplayCount++ < 2) { - throw new NullPointerException("simulated workflow task failure"); - } - return "result1"; - } - } - - @Test - public void testWorkflowTaskNPEBackoff() { - testWorkflowTaskFailureBackoffReplayCount = 0; - startWorkerFor(TestWorkflowTaskNPEBackoff.class); - WorkflowOptions o = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofSeconds(10)) - .setWorkflowTaskTimeout(Duration.ofSeconds(1)) - .setTaskQueue(taskQueue) - .build(); - - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub(TestWorkflows.TestWorkflow1.class, o); - long start = currentTimeMillis(); - String result = workflowStub.execute(taskQueue); - long elapsed = currentTimeMillis() - start; - assertTrue("spinned on fail workflow task", elapsed > 1000); - assertEquals("result1", result); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(WorkflowStub.fromTyped(workflowStub).getExecution()) - .build(); - GetWorkflowExecutionHistoryResponse response = - service.blockingStub().getWorkflowExecutionHistory(request); - - int failedTaskCount = 0; - for (HistoryEvent event : response.getHistory().getEventsList()) { - if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_FAILED) { - failedTaskCount++; - } - } - assertEquals(1, failedTaskCount); - } - - private static final Map retryCount = new ConcurrentHashMap<>(); - - @WorkflowInterface - public interface TestWorkflowRetry { - - @WorkflowMethod - String execute(String testName); - } - - public static class TestWorkflowRetryImpl implements TestWorkflowRetry { - - @Override - public String execute(String testName) { - AtomicInteger count = retryCount.get(testName); - if (count == null) { - count = new AtomicInteger(); - retryCount.put(testName, count); - } - int attempt = Workflow.getInfo().getAttempt(); - assertEquals(count.get() + 1, attempt); - throw ApplicationFailure.newFailure("simulated " + count.incrementAndGet(), "test"); - } - } - - @Test - public void testWorkflowRetry() { - startWorkerFor(TestWorkflowRetryImpl.class); - RetryOptions workflowRetryOptions = - RetryOptions.newBuilder() - .setInitialInterval(Duration.ofSeconds(1)) - .setMaximumAttempts(3) - .setBackoffCoefficient(1.0) - .build(); - TestWorkflowRetry workflowStub = - workflowClient.newWorkflowStub( - TestWorkflowRetry.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setRetryOptions(workflowRetryOptions) - .build()); - long start = currentTimeMillis(); - try { - workflowStub.execute(testName.getMethodName()); - fail("unreachable"); - } catch (WorkflowException e) { - assertEquals( - e.toString(), - "message='simulated 3', type='test', nonRetryable=false", - e.getCause().getMessage()); - } finally { - long elapsed = currentTimeMillis() - start; - assertTrue(String.valueOf(elapsed), elapsed >= 2000); // Ensure that retry delays the restart - } - } - - public static class TestWorkflowRetryDoNotRetryException implements TestWorkflowRetry { - - @Override - public String execute(String testName) { - AtomicInteger count = retryCount.get(testName); - if (count == null) { - count = new AtomicInteger(); - retryCount.put(testName, count); - } - int c = count.incrementAndGet(); - if (c < 3) { - throw new IllegalArgumentException("simulated " + c); - } else { - throw ApplicationFailure.newFailure("simulated " + c, "NonRetryable"); - } - } - } - - @Test - public void testWorkflowRetryDoNotRetryException() { - startWorkerFor(TestWorkflowRetryDoNotRetryException.class); - RetryOptions workflowRetryOptions = - RetryOptions.newBuilder() - .setInitialInterval(Duration.ofSeconds(1)) - .setDoNotRetry("NonRetryable") - .setMaximumAttempts(100) - .setBackoffCoefficient(1.0) - .build(); - TestWorkflowRetry workflowStub = - workflowClient.newWorkflowStub( - TestWorkflowRetry.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setRetryOptions(workflowRetryOptions) - .build()); - try { - workflowStub.execute(testName.getMethodName()); - fail("unreachable"); - } catch (WorkflowException e) { - assertTrue(e.getCause() instanceof ApplicationFailure); - assertEquals("NonRetryable", ((ApplicationFailure) e.getCause()).getType()); - assertEquals( - "message='simulated 3', type='NonRetryable', nonRetryable=false", - e.getCause().getMessage()); - } - } - - public static class TestWorkflowNonRetryableFlag implements TestWorkflowRetry { - - @Override - public String execute(String testName) { - AtomicInteger count = retryCount.get(testName); - if (count == null) { - count = new AtomicInteger(); - retryCount.put(testName, count); - } - int c = count.incrementAndGet(); - ApplicationFailure f = - ApplicationFailure.newFailure("simulated " + c, "foo", "details1", 123); - if (c == 3) { - f.setNonRetryable(true); - } - throw f; - } - } - - @Test - public void testWorkflowFailureNonRetryableFlag() { - startWorkerFor(TestWorkflowNonRetryableFlag.class); - RetryOptions workflowRetryOptions = - RetryOptions.newBuilder() - .setInitialInterval(Duration.ofSeconds(1)) - .setMaximumAttempts(100) - .setBackoffCoefficient(1.0) - .build(); - TestWorkflowRetry workflowStub = - workflowClient.newWorkflowStub( - TestWorkflowRetry.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setRetryOptions(workflowRetryOptions) - .build()); - try { - workflowStub.execute(testName.getMethodName()); - fail("unreachable"); - } catch (WorkflowException e) { - assertTrue(e.getCause() instanceof ApplicationFailure); - assertEquals("foo", ((ApplicationFailure) e.getCause()).getType()); - assertEquals( - "details1", ((ApplicationFailure) e.getCause()).getDetails().get(0, String.class)); - assertEquals( - Integer.valueOf(123), - ((ApplicationFailure) e.getCause()).getDetails().get(1, Integer.class)); - assertEquals( - "message='simulated 3', type='foo', nonRetryable=true", e.getCause().getMessage()); - } - } - - @WorkflowInterface - public interface TestWorkflowRetryWithMethodRetry { - - @WorkflowMethod - @MethodRetry( - initialIntervalSeconds = 1, - maximumIntervalSeconds = 1, - maximumAttempts = 30, - doNotRetry = "java.lang.IllegalArgumentException") - String execute(String testName); - } - - public static class TestWorkflowRetryWithMethodRetryImpl - implements TestWorkflowRetryWithMethodRetry { - - @Override - public String execute(String testName) { - AtomicInteger count = retryCount.get(testName); - if (count == null) { - count = new AtomicInteger(); - retryCount.put(testName, count); - } - int c = count.incrementAndGet(); - if (c < 3) { - throw new IllegalStateException("simulated " + c); - } else { - throw new IllegalArgumentException("simulated " + c); - } - } - } - - @Test - public void testWorkflowRetryWithMethodRetryDoNotRetryException() { - startWorkerFor( - WorkflowImplementationOptions.newBuilder() - .setFailWorkflowExceptionTypes( - IllegalStateException.class, IllegalArgumentException.class) - .build(), - TestWorkflowRetryWithMethodRetryImpl.class); - TestWorkflowRetryWithMethodRetry workflowStub = - workflowClient.newWorkflowStub( - TestWorkflowRetryWithMethodRetry.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - try { - workflowStub.execute(testName.getMethodName()); - fail("unreachable"); - } catch (WorkflowException e) { - assertTrue(e.getCause() instanceof ApplicationFailure); - assertEquals( - IllegalArgumentException.class.getName(), ((ApplicationFailure) e.getCause()).getType()); - assertEquals( - "message='simulated 3', type='java.lang.IllegalArgumentException', nonRetryable=false", - e.getCause().getMessage()); - } - } - - @WorkflowInterface - public interface TestWorkflowWithCronSchedule { - @WorkflowMethod - @CronSchedule("0 * * * *") - String execute(String testName); - } - - static String lastCompletionResult; - static Optional lastFail; - - public static class TestWorkflowWithCronScheduleImpl implements TestWorkflowWithCronSchedule { - - @Override - public String execute(String testName) { - Logger log = Workflow.getLogger(TestWorkflowWithCronScheduleImpl.class); - - if (CancellationScope.current().isCancelRequested()) { - log.debug("TestWorkflowWithCronScheduleImpl run canceled."); - return null; - } - - lastCompletionResult = Workflow.getLastCompletionResult(String.class); - lastFail = Workflow.getPreviousRunFailure(); - - AtomicInteger count = retryCount.get(testName); - if (count == null) { - count = new AtomicInteger(); - retryCount.put(testName, count); - } - int c = count.incrementAndGet(); - - if (c == 3) { - throw ApplicationFailure.newFailure("simulated error", "test"); - } - - SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS"); - Date now = new Date(Workflow.currentTimeMillis()); - log.debug("TestWorkflowWithCronScheduleImpl run at " + sdf.format(now)); - return "run " + c; - } - } - - public static class TestCronParentWorkflow implements TestWorkflows.TestWorkflow1 { - - private final TestWorkflowWithCronSchedule cronChild = - Workflow.newChildWorkflowStub(TestWorkflowWithCronSchedule.class); - - @Override - public String execute(String taskQueue) { - return cronChild.execute(taskQueue); - } - } - - public interface ProcInvocationQueryable { - - @QueryMethod(name = "getTrace") - String query(); - } - - @WorkflowInterface - public interface TestGetAttemptWorkflowsFunc { - - @WorkflowMethod - int func(); - } - - public static class TestWorkflowLocals implements TestWorkflows.TestWorkflow1 { - - private final WorkflowThreadLocal threadLocal = - WorkflowThreadLocal.withInitial(() -> 2); - - private final WorkflowLocal workflowLocal = WorkflowLocal.withInitial(() -> 5); - - @Override - public String execute(String taskQueue) { - assertEquals(2, (int) threadLocal.get()); - assertEquals(5, (int) workflowLocal.get()); - Promise p1 = - Async.procedure( - () -> { - assertEquals(2, (int) threadLocal.get()); - threadLocal.set(10); - Workflow.sleep(Duration.ofSeconds(1)); - assertEquals(10, (int) threadLocal.get()); - assertEquals(100, (int) workflowLocal.get()); - }); - Promise p2 = - Async.procedure( - () -> { - assertEquals(2, (int) threadLocal.get()); - threadLocal.set(22); - workflowLocal.set(100); - assertEquals(22, (int) threadLocal.get()); - }); - p1.get(); - p2.get(); - return "result=" + threadLocal.get() + ", " + workflowLocal.get(); - } - } - - @Test - public void testWorkflowLocals() { - startWorkerFor(TestWorkflowLocals.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - String result = workflowStub.execute(taskQueue); - assertEquals("result=2, 100", result); - } - - public static class TestSideEffectWorkflowImpl implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - TestActivities testActivities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - - long workflowTime = Workflow.currentTimeMillis(); - long time1 = Workflow.sideEffect(long.class, () -> workflowTime); - long time2 = Workflow.sideEffect(long.class, () -> workflowTime); - assertEquals(time1, time2); - Workflow.sleep(Duration.ofSeconds(1)); - String result; - if (workflowTime == time1) { - result = "activity" + testActivities.activity1(1); - } else { - result = testActivities.activity2("activity2", 2); - } - return result; - } - } - - @Test - public void testSideEffect() { - startWorkerFor(TestSideEffectWorkflowImpl.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - String result = workflowStub.execute(taskQueue); - assertEquals("activity1", result); - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "currentTimeMillis", - "sideEffect", - "sideEffect", - "sleep PT1S", - "executeActivity customActivity1", - "activity customActivity1"); - } - - private static final Map> mutableSideEffectValue = - Collections.synchronizedMap(new HashMap<>()); - - public static class TestMutableSideEffectWorkflowImpl implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - StringBuilder result = new StringBuilder(); - for (int j = 0; j < 1; j++) { - for (int i = 0; i < 8; i++) { - long value = - Workflow.mutableSideEffect( - "id1", - Long.class, - (o, n) -> n > o, - () -> mutableSideEffectValue.get(taskQueue).poll()); - if (result.length() > 0) { - result.append(", "); - } - result.append(value); - // Sleep is here to ensure that mutableSideEffect works when replaying a history. - if (i >= 8) { - Workflow.sleep(Duration.ofSeconds(1)); - } - } - } - return result.toString(); - } - } - - @Test - public void testMutableSideEffect() { - startWorkerFor(TestMutableSideEffectWorkflowImpl.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - ArrayDeque values = new ArrayDeque<>(); - values.add(1234L); - values.add(1234L); - values.add(123L); // expected to be ignored as it is smaller than 1234. - values.add(3456L); - values.add(1234L); // expected to be ignored as it is smaller than 3456L. - values.add(4234L); - values.add(4234L); - values.add(3456L); // expected to be ignored as it is smaller than 4234L. - mutableSideEffectValue.put(taskQueue, values); - String result = workflowStub.execute(taskQueue); - assertEquals("1234, 1234, 1234, 3456, 3456, 4234, 4234, 4234", result); - } - - public static class TestGetVersionWorkflowImpl implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - TestActivities testActivities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - - // Test adding a version check in non-replay code. - int version = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 1); - assertEquals(version, 1); - String result = testActivities.activity2("activity2", 2); - - // Test version change in non-replay code. - version = Workflow.getVersion("test_change", 1, 2); - assertEquals(version, 1); - result += "activity" + testActivities.activity1(1); - - boolean replaying = false; - // Test adding a version check in replay code. - if (!Workflow.isReplaying()) { - result += "activity" + testActivities.activity1(1); // This is executed in non-replay mode. - } else { - replaying = true; - int version2 = Workflow.getVersion("test_change_2", Workflow.DEFAULT_VERSION, 1); - assertEquals(version2, Workflow.DEFAULT_VERSION); - result += "activity" + testActivities.activity1(1); - } - - // Test get version in replay mode. - Workflow.sleep(1000); - version = Workflow.getVersion("test_change", 1, 2); - assertEquals(version, 1); - result += "activity" + testActivities.activity1(1); - assertTrue(replaying); - return result; - } - } - - @Test - public void testGetVersion() { - startWorkerFor(TestGetVersionWorkflowImpl.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - String result = workflowStub.execute(taskQueue); - assertEquals("activity22activity1activity1activity1", result); - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "getVersion", - "executeActivity Activity2", - "activity Activity2", - "getVersion", - "executeActivity customActivity1", - "activity customActivity1", - "executeActivity customActivity1", - "activity customActivity1", - "sleep PT1S", - "getVersion", - "executeActivity customActivity1", - "activity customActivity1"); - } - - public static class TestGetVersionSameIdOnReplay implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - // Test adding a version check in replay code. - if (!Workflow.isReplaying()) { - Workflow.sleep(Duration.ofMinutes(1)); - } else { - int version2 = Workflow.getVersion("test_change_2", Workflow.DEFAULT_VERSION, 11); - Workflow.sleep(Duration.ofMinutes(1)); - int version3 = Workflow.getVersion("test_change_2", Workflow.DEFAULT_VERSION, 11); - - assertEquals(Workflow.DEFAULT_VERSION, version3); - assertEquals(version2, version3); - } - - return "test"; - } - } - - @Test - public void testGetVersionSameIdOnReplay() { - Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); - - startWorkerFor(TestGetVersionSameIdOnReplay.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - workflowStub.execute(taskQueue); - WorkflowExecution execution = WorkflowStub.fromTyped(workflowStub).getExecution(); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(execution) - .build(); - - // Validate that no marker is recorded - GetWorkflowExecutionHistoryResponse response = - service.blockingStub().getWorkflowExecutionHistory(request); - for (HistoryEvent event : response.getHistory().getEventsList()) { - assertFalse(EventType.EVENT_TYPE_MARKER_RECORDED == event.getEventType()); - } - } - - public static class TestGetVersionSameId implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - // Test adding a version check in replay code. - if (!Workflow.isReplaying()) { - int version2 = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 11); - Workflow.sleep(Duration.ofMinutes(1)); - } else { - int version2 = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 11); - Workflow.sleep(Duration.ofMinutes(1)); - int version3 = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 11); - - assertEquals(11, version3); - assertEquals(version2, version3); - } - - return "test"; - } - } - - @Test - public void testGetVersionSameId() { - Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); - - startWorkerFor(TestGetVersionSameId.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - workflowStub.execute(taskQueue); - } - - public static class TestGetVersionWorkflowAddNewBefore implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - log.info("TestGetVersionWorkflow3Impl this=" + this.hashCode()); - // Test adding a version check in replay code. - if (!Workflow.isReplaying()) { - // The first version of the code - int changeFoo = Workflow.getVersion("changeFoo", Workflow.DEFAULT_VERSION, 1); - if (changeFoo != 1) { - throw new IllegalStateException("Unexpected version: " + 1); - } - } else { - // The updated code - int changeBar = Workflow.getVersion("changeBar", Workflow.DEFAULT_VERSION, 1); - if (changeBar != Workflow.DEFAULT_VERSION) { - throw new IllegalStateException("Unexpected version: " + changeBar); - } - int changeFoo = Workflow.getVersion("changeFoo", Workflow.DEFAULT_VERSION, 1); - if (changeFoo != 1) { - throw new IllegalStateException("Unexpected version: " + changeFoo); - } - } - Workflow.sleep(1000); // forces new workflow task - return "test"; - } - } - - @Test - public void testGetVersionAddNewBefore() { - Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); - - startWorkerFor(TestGetVersionWorkflowAddNewBefore.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - workflowStub.execute(taskQueue); - } - - public static class TestGetVersionWorkflowReplaceGetVersionId - implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - log.info("TestGetVersionWorkflow3Impl this=" + this.hashCode()); - // Test adding a version check in replay code. - if (!Workflow.isReplaying()) { - // The first version of the code - int changeFoo1 = Workflow.getVersion("changeFoo0", Workflow.DEFAULT_VERSION, 2); - if (changeFoo1 != 2) { - throw new IllegalStateException("Unexpected version: " + changeFoo1); - } - int changeFoo2 = Workflow.getVersion("changeFoo1", Workflow.DEFAULT_VERSION, 111); - if (changeFoo2 != 111) { - throw new IllegalStateException("Unexpected version: " + changeFoo2); - } - } else { - // The updated code - int changeBar = Workflow.getVersion("changeBar", Workflow.DEFAULT_VERSION, 1); - if (changeBar != Workflow.DEFAULT_VERSION) { - throw new IllegalStateException("Unexpected version: " + changeBar); - } - int changeFoo = Workflow.getVersion("changeFoo1", Workflow.DEFAULT_VERSION, 123); - if (changeFoo != 111) { - throw new IllegalStateException("Unexpected version: " + changeFoo); - } - } - Workflow.sleep(1000); // forces new workflow task - return "test"; - } - } - - @Test - public void testGetVersionWorkflowReplaceGetVersionId() { - Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); - - startWorkerFor(TestGetVersionWorkflowReplaceGetVersionId.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - workflowStub.execute(taskQueue); - } - - public static class TestGetVersionWorkflowReplaceCompletely - implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - log.info("TestGetVersionWorkflow3Impl this=" + this.hashCode()); - // Test adding a version check in replay code. - if (!Workflow.isReplaying()) { - // The first version of the code - Workflow.getVersion("changeFoo0", Workflow.DEFAULT_VERSION, 2); - Workflow.getVersion("changeFoo1", Workflow.DEFAULT_VERSION, 111); - Workflow.getVersion("changeFoo2", Workflow.DEFAULT_VERSION, 101); - } else { - // The updated code - int changeBar = Workflow.getVersion("changeBar", Workflow.DEFAULT_VERSION, 1); - if (changeBar != Workflow.DEFAULT_VERSION) { - throw new IllegalStateException("Unexpected version: " + changeBar); - } - int changeFoo = Workflow.getVersion("changeFoo10", Workflow.DEFAULT_VERSION, 123); - if (changeFoo != Workflow.DEFAULT_VERSION) { - throw new IllegalStateException("Unexpected version: " + changeFoo); - } - } - Workflow.sleep(1000); // forces new workflow task - return "test"; - } - } - - @Test - public void testGetVersionWorkflowReplaceCompletely() { - Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); - - startWorkerFor(TestGetVersionWorkflowReplaceCompletely.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - workflowStub.execute(taskQueue); - } - - public static class TestGetVersionWorkflowRemove implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - TestActivities activities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - String result; - // Test adding a version check in replay code. - if (!Workflow.isReplaying()) { - // The first version of the code - int changeFoo = Workflow.getVersion("changeFoo", Workflow.DEFAULT_VERSION, 1); - if (changeFoo != 1) { - throw new IllegalStateException("Unexpected version: " + 1); - } - result = activities.activity2("foo", 10); - } else { - // No getVersionCall - result = activities.activity2("foo", 10); - } - Workflow.sleep(1000); // forces new workflow task - return result; - } - } - - @Test - public void testGetVersionWorkflowRemove() { - Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); - - startWorkerFor(TestGetVersionWorkflowRemove.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - assertEquals("foo10", workflowStub.execute(taskQueue)); - } - - static CompletableFuture executionStarted = new CompletableFuture<>(); - - public static class TestGetVersionWithoutCommandEventWorkflowImpl - implements TestWorkflowSignaled { - - CompletablePromise signalReceived = Workflow.newPromise(); - - @Override - public String execute() { - try { - if (!Workflow.isReplaying()) { - executionStarted.complete(true); - signalReceived.get(); - } else { - // Execute getVersion in replay mode. In this case we have no command event, only a - // signal. - int version = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 1); - if (version == Workflow.DEFAULT_VERSION) { - signalReceived.get(); - return "result 1"; - } else { - return "result 2"; - } - } - Workflow.sleep(1000); - } catch (Exception e) { - throw new RuntimeException("failed to get from signal"); - } - - throw new RuntimeException("unreachable"); - } - - @Override - public void signal1(String arg) { - signalReceived.complete(true); - } - } - - @Test - public void testGetVersionWithoutCommandEvent() throws Exception { - executionStarted = new CompletableFuture<>(); - startWorkerFor(TestGetVersionWithoutCommandEventWorkflowImpl.class); - TestWorkflowSignaled workflowStub = - workflowClient.newWorkflowStub( - TestWorkflowSignaled.class, TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - WorkflowClient.start(workflowStub::execute); - executionStarted.get(); - workflowStub.signal1("test signal"); - String result = WorkflowStub.fromTyped(workflowStub).getResult(String.class); - assertEquals("result 1", result); - } - - // The following test covers the scenario where getVersion call is removed before a - // non-version-marker command. - public static class TestGetVersionRemovedInReplay implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - TestActivities testActivities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - String result; - // Test removing a version check in replay code. - if (!Workflow.isReplaying()) { - int version = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 13); - assertEquals(13, version); - result = testActivities.activity2("activity2", 2); - } else { - result = testActivities.activity2("activity2", 2); - } - result += testActivities.activity(); - return result; - } + String execute(String arg); } - @Test - public void testGetVersionRemovedInReplay() { - startWorkerFor(TestGetVersionRemovedInReplay.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - String result = workflowStub.execute(taskQueue); - assertEquals("activity22activity", result); - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "getVersion", - "executeActivity Activity2", - "activity Activity2", - "executeActivity Activity", - "activity Activity"); + public static class TestChild implements ITestChild { + + @Override + public String execute(String arg, int delay) { + Workflow.sleep(delay); + return arg.toUpperCase(); + } } - // The following test covers the scenario where getVersion call is removed before another - // version-marker command. - public static class TestGetVersionRemovedBefore implements TestWorkflows.TestWorkflow1 { + public static class AngryChild implements ITestChild { @Override - public String execute(String taskQueue) { - TestActivities testActivities = + public String execute(String taskQueue, int delay) { + TestActivities.AngryChildActivity activity = Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - // Test removing a version check in replay code. - if (!Workflow.isReplaying()) { - Workflow.getVersion("test_change1", Workflow.DEFAULT_VERSION, 11); - Workflow.getVersion("test_change2", Workflow.DEFAULT_VERSION, 12); - Workflow.getVersion("test_change3", Workflow.DEFAULT_VERSION, 13); - Workflow.getVersion("test_change4", Workflow.DEFAULT_VERSION, 14); - } else { - int version = Workflow.getVersion("test_change3", Workflow.DEFAULT_VERSION, 22); - assertEquals(13, version); - } - return testActivities.activity(); + TestActivities.AngryChildActivity.class, + ActivityOptions.newBuilder() + .setTaskQueue(taskQueue) + .setScheduleToCloseTimeout(Duration.ofSeconds(5)) + .build()); + activity.execute(); + throw ApplicationFailure.newFailure("simulated failure", "test"); } } - @Test - public void testGetVersionRemovedBefore() { - startWorkerFor(TestGetVersionRemovedBefore.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - String result = workflowStub.execute(taskQueue); - assertEquals("activity", result); - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "getVersion", - "getVersion", - "getVersion", - "getVersion", - "executeActivity Activity", - "activity Activity"); - } + @WorkflowInterface + public interface SignalingChild { - public static class TestVersionNotSupportedWorkflowImpl implements TestWorkflows.TestWorkflow1 { + @WorkflowMethod + String execute(String arg, String parentWorkflowId); + } - @Override - public String execute(String taskQueue) { - TestActivities testActivities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + private static final Map retryCount = new ConcurrentHashMap<>(); - // Test adding a version check in non-replay code. - int version = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 1); - String result = ""; - if (version == Workflow.DEFAULT_VERSION) { - result += "activity" + testActivities.activity1(1); - } else { - result += testActivities.activity2("activity2", 2); // This is executed. - } + @WorkflowInterface + public interface TestWorkflowRetry { - // Catching error from getVersion is only for unit test purpose. - // Do not ever do it in production code. - try { - Workflow.getVersion("test_change", 2, 3); - } catch (Error e) { - throw Workflow.wrap(ApplicationFailure.newFailure("unsupported change version", "test")); - } - return result; - } + @WorkflowMethod + String execute(String testName); } - @Test - public void testVersionNotSupported() { - startWorkerFor(TestVersionNotSupportedWorkflowImpl.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - - try { - workflowStub.execute(taskQueue); - fail("unreachable"); - } catch (WorkflowException e) { - assertEquals( - "message='unsupported change version', type='test', nonRetryable=false", - e.getCause().getMessage()); - } + @WorkflowInterface + public interface TestWorkflowRetryWithMethodRetry { + + @WorkflowMethod + @MethodRetry( + initialIntervalSeconds = 1, + maximumIntervalSeconds = 1, + maximumAttempts = 30, + doNotRetry = "java.lang.IllegalArgumentException") + String execute(String testName); } @WorkflowInterface - public interface DeterminismFailingWorkflow { + public interface TestWorkflowWithCronSchedule { @WorkflowMethod - void execute(String taskQueue); + @CronSchedule("0 * * * *") + String execute(String testName); } - public static class DeterminismFailingWorkflowImpl implements DeterminismFailingWorkflow { + public static String lastCompletionResult; + static Optional lastFail; + + public static class TestWorkflowWithCronScheduleImpl implements TestWorkflowWithCronSchedule { @Override - public void execute(String taskQueue) { - TestActivities activities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - if (!Workflow.isReplaying()) { - activities.activity1(1); + public String execute(String testName) { + Logger log = Workflow.getLogger(TestWorkflowWithCronScheduleImpl.class); + + if (CancellationScope.current().isCancelRequested()) { + log.debug("TestWorkflowWithCronScheduleImpl run canceled."); + return null; } - } - } - @Test - public void testNonDeterministicWorkflowPolicyBlockWorkflow() { - startWorkerFor(DeterminismFailingWorkflowImpl.class); - WorkflowOptions options = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofSeconds(5)) - .setWorkflowTaskTimeout(Duration.ofSeconds(1)) - .setTaskQueue(taskQueue) - .build(); - DeterminismFailingWorkflow workflowStub = - workflowClient.newWorkflowStub(DeterminismFailingWorkflow.class, options); - try { - workflowStub.execute(taskQueue); - fail("unreachable"); - } catch (WorkflowFailedException e) { - // expected to timeout as workflow is going get blocked. - assertTrue(e.getCause() instanceof TimeoutFailure); - } + lastCompletionResult = Workflow.getLastCompletionResult(String.class); + lastFail = Workflow.getPreviousRunFailure(); - int workflowRootThreads = 0; - ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false); - for (ThreadInfo thread : threads) { - if (thread.getThreadName().contains("workflow-root")) { - workflowRootThreads++; + AtomicInteger count = retryCount.get(testName); + if (count == null) { + count = new AtomicInteger(); + retryCount.put(testName, count); } - } + int c = count.incrementAndGet(); - assertTrue("workflow threads might leak", workflowRootThreads < 10); - } + if (c == 3) { + throw ApplicationFailure.newFailure("simulated error", "test"); + } - @Test - public void testNonDeterministicWorkflowPolicyFailWorkflow() { - WorkflowImplementationOptions implementationOptions = - WorkflowImplementationOptions.newBuilder() - .setFailWorkflowExceptionTypes(Throwable.class) - .build(); - worker.registerWorkflowImplementationTypes( - implementationOptions, DeterminismFailingWorkflowImpl.class); - if (SDKTestWorkflowRule.useExternalService) { - workerFactory.start(); - } else { - testEnvironment.start(); - } - WorkflowOptions options = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofSeconds(1)) - .setWorkflowTaskTimeout(Duration.ofSeconds(1)) - .setTaskQueue(taskQueue) - .build(); - DeterminismFailingWorkflow workflowStub = - workflowClient.newWorkflowStub(DeterminismFailingWorkflow.class, options); - try { - workflowStub.execute(taskQueue); - fail("unreachable"); - } catch (WorkflowFailedException e) { - // expected to fail on non deterministic error - assertTrue(e.getCause() instanceof ApplicationFailure); - assertEquals( - InternalWorkflowTaskException.class.getName(), - ((ApplicationFailure) e.getCause()).getType()); + SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS"); + Date now = new Date(Workflow.currentTimeMillis()); + log.debug("TestWorkflowWithCronScheduleImpl run at " + sdf.format(now)); + return "run " + c; } } - public static class TestUUIDAndRandom implements TestWorkflows.TestWorkflow1 { + public static class TestCronParentWorkflow implements TestWorkflows.TestWorkflow1 { + + private final TestWorkflowWithCronSchedule cronChild = + Workflow.newChildWorkflowStub(TestWorkflowWithCronSchedule.class); @Override public String execute(String taskQueue) { - TestActivities activities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - Random rand1 = Workflow.newRandom(); - int r11 = rand1.nextInt(); - int r12 = r11 + rand1.nextInt(); - int savedInt = Workflow.sideEffect(int.class, () -> r12); - String id = Workflow.randomUUID().toString() + "-" + Workflow.randomUUID().toString(); - String savedId = Workflow.sideEffect(String.class, () -> id); - // Invoke activity in a blocking mode to ensure that asserts run after replay. - String result = activities.activity2("foo", 10); - // Assert that during replay values didn't change. - assertEquals(savedId, id); - assertEquals(savedInt, r12); - return result; + return cronChild.execute(taskQueue); } } - @Test - public void testUUIDAndRandom() { - startWorkerFor(TestUUIDAndRandom.class); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub( - TestWorkflows.TestWorkflow1.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - String result = workflowStub.execute(taskQueue); - assertEquals("foo10", result); - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "sideEffect", - "sideEffect", - "executeActivity Activity2", - "activity Activity2"); - } - - @ActivityInterface - public interface GenericParametersActivity { + public interface ProcInvocationQueryable { - List execute(List arg1, Set arg2); + @QueryMethod(name = "getTrace") + String query(); } - public static class GenericParametersActivityImpl implements GenericParametersActivity { + @WorkflowInterface + public interface TestGetAttemptWorkflowsFunc { - @Override - public List execute(List arg1, Set arg2) { - List result = new ArrayList<>(); - result.addAll(arg1); - result.addAll(arg2); - return result; - } + @WorkflowMethod + int func(); } @WorkflowInterface - public interface GenericParametersWorkflow { - + public interface DeterminismFailingWorkflow { @WorkflowMethod - List execute(String taskQueue, List arg1, Set arg2); - - @SignalMethod - void signal(List arg); - - @QueryMethod - List query(List arg); + void execute(String taskQueue); } - public static class GenericParametersWorkflowImpl implements GenericParametersWorkflow { - - private List signaled; - private GenericParametersActivity activity; + public static class DeterminismFailingWorkflowImpl implements DeterminismFailingWorkflow { @Override - public List execute(String taskQueue, List arg1, Set arg2) { - Workflow.await(() -> signaled != null && signaled.size() == 0); - activity = + public void execute(String taskQueue) { + TestActivities activities = Workflow.newActivityStub( - GenericParametersActivity.class, - TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - return activity.execute(arg1, arg2); - } - - @Override - public void signal(List arg) { - signaled = arg; - } - - @Override - public List query(List arg) { - List result = new ArrayList<>(); - result.addAll(arg); - result.addAll(signaled); - return result; + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + if (!Workflow.isReplaying()) { + activities.activity1(1); + } } } - @Test - public void testGenericParametersWorkflow() throws ExecutionException, InterruptedException { - worker.registerActivitiesImplementations(new GenericParametersActivityImpl()); - startWorkerFor(GenericParametersWorkflowImpl.class); - GenericParametersWorkflow workflowStub = - workflowClient.newWorkflowStub( - GenericParametersWorkflow.class, TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - List uuidList = new ArrayList<>(); - uuidList.add(UUID.randomUUID()); - uuidList.add(UUID.randomUUID()); - Set uuidSet = new HashSet<>(); - uuidSet.add(UUID.randomUUID()); - uuidSet.add(UUID.randomUUID()); - uuidSet.add(UUID.randomUUID()); - CompletableFuture> resultF = - WorkflowClient.execute(workflowStub::execute, taskQueue, uuidList, uuidSet); - // Test signal and query serialization - workflowStub.signal(uuidList); - sleep(Duration.ofSeconds(1)); - List queryArg = new ArrayList<>(); - queryArg.add(UUID.randomUUID()); - queryArg.add(UUID.randomUUID()); - List queryResult = workflowStub.query(queryArg); - List expectedQueryResult = new ArrayList<>(); - expectedQueryResult.addAll(queryArg); - expectedQueryResult.addAll(uuidList); - expectedQueryResult.sort(UUID::compareTo); - queryResult.sort(UUID::compareTo); - assertEquals(expectedQueryResult, queryResult); - workflowStub.signal(new ArrayList<>()); // empty list unblocks workflow await. - // test workflow result serialization - List expectedResult = new ArrayList<>(); - expectedResult.addAll(uuidList); - expectedResult.addAll(uuidSet); - List result = resultF.get(); - result.sort(UUID::compareTo); - expectedResult.sort(UUID::compareTo); - assertEquals(expectedResult, result); - } - public static class NonSerializableException extends RuntimeException { @SuppressWarnings("unused") private final InputStream file; // gson chokes on this field @@ -2763,92 +349,15 @@ public interface TestLargeWorkflowActivity { String activity(); } - public static class TestLargeWorkflowActivityImpl implements TestLargeWorkflowActivity { - @Override - public String activity() { - return "done"; - } - } - - public static class TestLargeHistory implements TestLargeWorkflow { - - @Override - public String execute(int activityCount, String taskQueue) { - TestLargeWorkflowActivity activities = - Workflow.newActivityStub( - TestLargeWorkflowActivity.class, - TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - List> results = new ArrayList<>(); - for (int i = 0; i < activityCount; i++) { - Promise result = Async.function(activities::activity); - results.add(result); - } - Promise.allOf(results).get(); - return "done"; - } - } - - @Test - @Ignore // Requires DEBUG_TIMEOUTS=true - public void testLargeHistory() { - final int activityCount = 1000; - worker.registerActivitiesImplementations(new TestLargeWorkflowActivityImpl()); - startWorkerFor(TestLargeHistory.class); - TestLargeWorkflow workflowStub = - workflowClient.newWorkflowStub( - TestLargeWorkflow.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setWorkflowTaskTimeout(Duration.ofSeconds(30)) - .build()); - long start = System.currentTimeMillis(); - String result = workflowStub.execute(activityCount, taskQueue); - long duration = System.currentTimeMillis() - start; - log.info(testName.toString() + " duration is " + duration); - assertEquals("done", result); - } - @WorkflowInterface public interface WorkflowTaskTimeoutWorkflow { @WorkflowMethod String execute(String testName) throws InterruptedException; } - public static class WorkflowTaskTimeoutWorkflowImpl implements WorkflowTaskTimeoutWorkflow { - - @Override - public String execute(String testName) throws InterruptedException { - - AtomicInteger count = retryCount.get(testName); - if (count == null) { - count = new AtomicInteger(); - retryCount.put(testName, count); - Thread.sleep(2000); - } - - return "some result"; - } - } - - @Test - public void testWorkflowTaskTimeoutWorkflow() throws InterruptedException { - startWorkerFor(WorkflowTaskTimeoutWorkflowImpl.class); - - WorkflowOptions options = - WorkflowOptions.newBuilder() - .setTaskQueue(taskQueue) - .setWorkflowTaskTimeout(Duration.ofSeconds(1)) - .build(); - - WorkflowTaskTimeoutWorkflow stub = - workflowClient.newWorkflowStub(WorkflowTaskTimeoutWorkflow.class, options); - String result = stub.execute(testName.getMethodName()); - assertEquals("some result", result); - } - public static class TestParallelLocalActivitiesWorkflowImpl implements TestWorkflows.TestWorkflow1 { - static final int COUNT = 100; + public static final int COUNT = 100; @Override public String execute(String taskQueue) { @@ -2880,31 +389,6 @@ public String execute(String taskQueue) { } } - @Test - public void testLocalActivitiesWorkflowTaskHeartbeat() - throws ExecutionException, InterruptedException { - startWorkerFor(TestLocalActivitiesWorkflowTaskHeartbeatWorkflowImpl.class); - WorkflowOptions options = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofMinutes(5)) - .setWorkflowTaskTimeout(Duration.ofSeconds(4)) - .setTaskQueue(taskQueue) - .build(); - int count = 5; - Future[] result = new Future[count]; - for (int i = 0; i < count; i++) { - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); - result[i] = WorkflowClient.execute(workflowStub::execute, taskQueue); - } - for (int i = 0; i < count; i++) { - assertEquals( - "sleepActivity0sleepActivity1sleepActivity2sleepActivity3sleepActivity4", - result[i].get()); - } - assertEquals(activitiesImpl.toString(), 5 * count, activitiesImpl.invocations.size()); - } - public static class TestLongLocalActivityWorkflowTaskHeartbeatWorkflowImpl implements TestWorkflows.TestWorkflow1 { @Override @@ -2916,108 +400,6 @@ public String execute(String taskQueue) { } } - @Test - public void testLongLocalActivityWorkflowTaskHeartbeat() { - startWorkerFor(TestLongLocalActivityWorkflowTaskHeartbeatWorkflowImpl.class); - WorkflowOptions options = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofMinutes(5)) - .setWorkflowTaskTimeout(Duration.ofSeconds(2)) - .setTaskQueue(taskQueue) - .build(); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); - String result = workflowStub.execute(taskQueue); - assertEquals("sleepActivity123", result); - assertEquals(activitiesImpl.toString(), 1, activitiesImpl.invocations.size()); - } - - public static class TestLongLocalActivityWorkflowTaskHeartbeatFailureWorkflowImpl - implements TestWorkflows.TestWorkflow1 { - - static boolean invoked; - - @Override - public String execute(String taskQueue) { - TestActivities localActivities = - Workflow.newLocalActivityStub( - TestActivities.class, TestOptions.newLocalActivityOptions()); - String result = localActivities.sleepActivity(5000, 123); - if (!invoked) { - invoked = true; - throw new Error("Simulate decision failure to force replay"); - } - return result; - } - } - - /** - * Test that local activity is not lost during replay if it was started before forced - * WorkflowTask. - */ - @Test - public void testLongLocalActivityWorkflowTaskHeartbeatFailure() { - startWorkerFor(TestLongLocalActivityWorkflowTaskHeartbeatFailureWorkflowImpl.class); - WorkflowOptions options = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofMinutes(5)) - .setWorkflowTaskTimeout(Duration.ofSeconds(2)) - .setTaskQueue(taskQueue) - .build(); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); - String result = workflowStub.execute(taskQueue); - assertEquals("sleepActivity123", result); - assertEquals(activitiesImpl.toString(), 2, activitiesImpl.invocations.size()); - } - - public static class TestParallelLocalActivityExecutionWorkflowImpl - implements TestWorkflows.TestWorkflow1 { - @Override - public String execute(String taskQueue) { - TestActivities localActivities = - Workflow.newLocalActivityStub( - TestActivities.class, TestOptions.newLocalActivityOptions()); - List> results = new ArrayList<>(4); - for (int i = 1; i <= 4; i++) { - results.add(Async.function(localActivities::sleepActivity, (long) 1000 * i, i)); - } - - Promise result2 = - Async.function( - () -> { - String result = ""; - for (int i = 0; i < 3; i++) { - result += localActivities.sleepActivity(1000, 21); - } - return result; - }); - - return results.get(0).get() - + results.get(1).get() - + results.get(2).get() - + results.get(3).get() - + result2.get(); - } - } - - @Test - public void testParallelLocalActivityExecutionWorkflow() { - startWorkerFor(TestParallelLocalActivityExecutionWorkflowImpl.class); - WorkflowOptions options = - WorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofMinutes(5)) - .setWorkflowTaskTimeout(Duration.ofSeconds(5)) - .setTaskQueue(taskQueue) - .build(); - TestWorkflows.TestWorkflow1 workflowStub = - workflowClient.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); - String result = workflowStub.execute(taskQueue); - assertEquals( - "sleepActivity1sleepActivity2sleepActivity3sleepActivity4sleepActivity21sleepActivity21sleepActivity21", - result); - } - @WorkflowInterface public interface TestWorkflowQuery { @@ -3120,136 +502,6 @@ public String execute(String taskQueue, boolean parallelCompensation) { } } - @Test - public void testSaga() { - startWorkerFor( - TestSagaWorkflowImpl.class, - TestMultiargsWorkflowsFuncImpl.class, - TestCompensationWorkflowImpl.class); - TestSagaWorkflow sagaWorkflow = - workflowClient.newWorkflowStub( - TestSagaWorkflow.class, TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - sagaWorkflow.execute(taskQueue, false); - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "executeActivity customActivity1", - "activity customActivity1", - "executeChildWorkflow TestMultiargsWorkflowsFunc", - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "executeActivity ThrowIO", - "activity ThrowIO", - "executeChildWorkflow TestCompensationWorkflow", - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "executeActivity Activity2", - "activity Activity2"); - } - - @Test - public void testSagaParallelCompensation() { - startWorkerFor( - TestSagaWorkflowImpl.class, - TestMultiargsWorkflowsFuncImpl.class, - TestCompensationWorkflowImpl.class); - TestSagaWorkflow sagaWorkflow = - workflowClient.newWorkflowStub( - TestSagaWorkflow.class, TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - sagaWorkflow.execute(taskQueue, true); - String trace = tracer.getTrace(); - assertTrue(trace, trace.contains("executeChildWorkflow TestCompensationWorkflow")); - assertTrue(trace, trace.contains("executeActivity Activity2")); - } - - @WorkflowInterface - public interface TestUpsertSearchAttributes { - @WorkflowMethod - String execute(String taskQueue, String keyword); - } - - public static class TestUpsertSearchAttributesImpl implements TestUpsertSearchAttributes { - - @Override - public String execute(String taskQueue, String keyword) { - SearchAttributes searchAttributes = Workflow.getInfo().getSearchAttributes(); - assertNull(searchAttributes); - - Map searchAttrMap = new HashMap<>(); - searchAttrMap.put("CustomKeywordField", keyword); - Workflow.upsertSearchAttributes(searchAttrMap); - - searchAttributes = Workflow.getInfo().getSearchAttributes(); - assertEquals( - "testKey", - SearchAttributesUtil.getValueFromSearchAttributes( - searchAttributes, "CustomKeywordField", String.class)); - - // Running the activity below ensures that we have one more workflow task to be executed after - // adding the search attributes. This helps with replaying the history one more time to check - // against a possible NonDeterminisicWorkflowError which could be caused by missing - // UpsertWorkflowSearchAttributes event in history. - TestActivities activities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - activities.activity(); - - return "done"; - } - } - - @Test - public void testUpsertSearchAttributes() { - startWorkerFor(TestUpsertSearchAttributesImpl.class); - TestUpsertSearchAttributes testWorkflow = - workflowClient.newWorkflowStub( - TestUpsertSearchAttributes.class, - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue)); - WorkflowExecution execution = WorkflowClient.start(testWorkflow::execute, taskQueue, "testKey"); - String result = testWorkflow.execute(taskQueue, "testKey"); - assertEquals("done", result); - tracer.setExpected( - "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, - "newThread workflow-method", - "upsertSearchAttributes", - "executeActivity Activity", - "activity Activity"); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(execution) - .build(); - GetWorkflowExecutionHistoryResponse response = - service.blockingStub().getWorkflowExecutionHistory(request); - - boolean found = false; - for (HistoryEvent event : response.getHistory().getEventsList()) { - if (EventType.EVENT_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES == event.getEventType()) { - found = true; - break; - } - } - assertTrue("EVENT_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES found in the history", found); - } - - public static class TestMultiargsWorkflowsFuncChild - implements TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2 { - @Override - public String func2(String s, int i) { - WorkflowInfo wi = Workflow.getInfo(); - Optional parentId = wi.getParentWorkflowId(); - return parentId.get(); - } - } - - public static class TestAttemptReturningWorkflowFunc implements TestGetAttemptWorkflowsFunc { - @Override - public int func() { - WorkflowInfo wi = Workflow.getInfo(); - return wi.getAttempt(); - } - } - public static class TestMultiargsWorkflowsFuncParent implements TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc { @Override @@ -3272,78 +524,11 @@ public String func() { } } - @Test - public void testParentWorkflowInfoInChildWorkflows() { - startWorkerFor(TestMultiargsWorkflowsFuncParent.class, TestMultiargsWorkflowsFuncChild.class); - - String workflowId = "testParentWorkflowInfoInChildWorkflows"; - WorkflowOptions workflowOptions = - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setWorkflowId(workflowId) - .build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc parent = - workflowClient.newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); - - String result = parent.func(); - String expected = String.format("%s - %s", false, workflowId); - assertEquals(expected, result); - } - - @Test - public void testGetAttemptFromWorkflowInfo() { - startWorkerFor(TestMultiargsWorkflowsFuncParent.class, TestAttemptReturningWorkflowFunc.class); - String workflowId = "testGetAttemptWorkflow"; - WorkflowOptions workflowOptions = - TestOptions.newWorkflowOptionsWithTimeouts(taskQueue) - .toBuilder() - .setWorkflowId(workflowId) - .build(); - TestGetAttemptWorkflowsFunc workflow = - workflowClient.newWorkflowStub(TestGetAttemptWorkflowsFunc.class, workflowOptions); - int attempt = workflow.func(); - assertEquals(1, attempt); - } - public interface WorkflowBase { @WorkflowMethod String execute(String arg); } - @WorkflowInterface - public interface WorkflowA extends WorkflowBase {} - - @WorkflowInterface - public interface WorkflowB extends WorkflowBase {} - - public static class WorkflowAImpl implements WorkflowA { - @Override - public String execute(String arg) { - return "WorkflowAImpl" + arg; - } - } - - public static class WorkflowBImpl implements WorkflowB { - @Override - public String execute(String arg) { - return "WorkflowBImpl" + arg; - } - } - - @Test - public void testPolymorphicStart() { - startWorkerFor(WorkflowBImpl.class, WorkflowAImpl.class); - WorkflowOptions options = TestOptions.newWorkflowOptionsWithTimeouts(taskQueue); - WorkflowBase[] stubs = - new WorkflowBase[] { - workflowClient.newWorkflowStub(WorkflowA.class, options), - workflowClient.newWorkflowStub(WorkflowB.class, options), - }; - String results = stubs[0].execute("0") + ", " + stubs[1].execute("1"); - assertEquals("WorkflowAImpl0, WorkflowBImpl1", results); - } - public interface SignalQueryBase { @SignalMethod void signal(String arg); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java new file mode 100644 index 0000000000..12b4cde813 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java @@ -0,0 +1,79 @@ +/* + * 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.fail; + +import com.google.common.util.concurrent.UncheckedExecutionException; +import io.temporal.client.WorkflowFailedException; +import io.temporal.client.WorkflowStub; +import io.temporal.failure.CanceledFailure; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class WorkflowsWithFailedPromisesCanBeCanceledTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestCancellationForWorkflowsWithFailedPromises.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void workflowsWithFailedPromisesCanBeCanceled() { + WorkflowStub client = testWorkflowRule.newUntypedWorkflowStubTimeoutOptions("TestWorkflow1"); + client.start(testWorkflowRule.getTaskQueue()); + client.cancel(); + + try { + client.getResult(String.class); + Assert.fail("unreachable"); + } catch (WorkflowFailedException e) { + Assert.assertTrue(e.getCause() instanceof CanceledFailure); + } + } + + public static class TestCancellationForWorkflowsWithFailedPromises + implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + Async.function( + () -> { + throw new UncheckedExecutionException(new Exception("Oh noo!")); + }); + Async.function( + () -> { + throw new UncheckedExecutionException(new Exception("Oh noo again!")); + }); + Workflow.await(() -> false); + fail("unreachable"); + return "done"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AbandonOnCancelActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java similarity index 98% rename from temporal-sdk/src/test/java/io/temporal/workflow/AbandonOnCancelActivityTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java index 78ed806a02..7454b730fd 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AbandonOnCancelActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityCancellationType; import io.temporal.activity.ActivityOptions; @@ -30,6 +30,7 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationFailureNonRetryableTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureNonRetryableTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationFailureNonRetryableTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureNonRetryableTest.java index ece0f9c028..01a67c9834 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationFailureNonRetryableTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureNonRetryableTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.api.enums.v1.RetryState; @@ -25,6 +25,7 @@ import io.temporal.common.RetryOptions; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationFailureRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureRetryTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationFailureRetryTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureRetryTest.java index ac972d5a90..a296f40ee0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationFailureRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureRetryTest.java @@ -17,13 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowException; import io.temporal.common.RetryOptions; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationNoSpecifiedRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationNoSpecifiedRetryTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationNoSpecifiedRetryTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationNoSpecifiedRetryTest.java index 722c2e83a1..15a4451101 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationNoSpecifiedRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationNoSpecifiedRetryTest.java @@ -17,12 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowException; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationOptOutOfRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationOptOutOfRetryTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationOptOutOfRetryTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationOptOutOfRetryTest.java index 89964faa8e..cb4e4467ee 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityApplicationOptOutOfRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationOptOutOfRetryTest.java @@ -17,13 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowException; import io.temporal.common.RetryOptions; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityPollerPrefetchingTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityPollerPrefetchingTest.java similarity index 98% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityPollerPrefetchingTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityPollerPrefetchingTest.java index 40544e51c2..91954a12c8 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityPollerPrefetchingTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityPollerPrefetchingTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.Activity; import io.temporal.activity.ActivityInterface; @@ -25,6 +25,7 @@ import io.temporal.activity.ActivityOptions; import io.temporal.common.RetryOptions; import io.temporal.worker.WorkerOptions; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import java.time.Duration; import java.util.ArrayList; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryAnnotatedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryAnnotatedTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryAnnotatedTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryAnnotatedTest.java index 67e7b91eef..327b61af05 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryAnnotatedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryAnnotatedTest.java @@ -17,12 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowException; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryOnTimeoutTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOnTimeoutTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryOnTimeoutTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOnTimeoutTest.java index d59b2cd1ab..7ecb9610f2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryOnTimeoutTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOnTimeoutTest.java @@ -17,13 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowException; import io.temporal.common.RetryOptions; import io.temporal.failure.ActivityFailure; import io.temporal.failure.TimeoutFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryOptionsChangeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOptionsChangeTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryOptionsChangeTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOptionsChangeTest.java index 7831ecb489..8701895dfd 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryOptionsChangeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOptionsChangeTest.java @@ -17,12 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowException; import io.temporal.common.RetryOptions; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryWithExpirationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryWithExpirationTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java index 533daa1f09..c9acd64bce 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryWithExpirationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import static org.junit.Assert.fail; @@ -26,6 +26,8 @@ import io.temporal.common.RetryOptions; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryWithMaxAttemptsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithMaxAttemptsTest.java similarity index 98% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryWithMaxAttemptsTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithMaxAttemptsTest.java index 9f0fb7d4e9..6ebb5fa6de 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryWithMaxAttemptsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithMaxAttemptsTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import static org.junit.Assert.*; @@ -27,6 +27,7 @@ import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityThrowingErrorTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityThrowingErrorTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ActivityThrowingErrorTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityThrowingErrorTest.java index 775fea0279..d9685e74b2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ActivityThrowingErrorTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityThrowingErrorTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -34,6 +34,9 @@ import io.temporal.testing.TestEnvironmentOptions; import io.temporal.testing.TestWorkflowEnvironment; import io.temporal.worker.Worker; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import java.time.Duration; import java.util.UUID; import org.junit.After; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityCompleteWithErrorTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityCompleteWithErrorTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityCompleteWithErrorTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityCompleteWithErrorTest.java index ae1d59f3d3..4a3725aa5a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityCompleteWithErrorTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityCompleteWithErrorTest.java @@ -17,12 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.*; import io.temporal.activity.ManualActivityCompletionClient; import io.temporal.common.RetryOptions; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import java.time.Duration; import java.util.concurrent.ForkJoinPool; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityRetryOptionsChangeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryOptionsChangeTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityRetryOptionsChangeTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryOptionsChangeTest.java index 8b5f978d2a..23ddc89784 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityRetryOptionsChangeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryOptionsChangeTest.java @@ -17,13 +17,15 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowException; import io.temporal.common.RetryOptions; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Async; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityRetry.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityRetry.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryTest.java index a16830aace..b2cd16038b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityRetry.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.api.common.v1.WorkflowExecution; @@ -26,6 +26,8 @@ import io.temporal.common.RetryOptions; import io.temporal.failure.ApplicationFailure; import io.temporal.testing.WorkflowReplayer; +import io.temporal.workflow.Async; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; @@ -36,7 +38,7 @@ import org.junit.Rule; import org.junit.Test; -public class AsyncActivityRetry { +public class AsyncActivityRetryTest { private final TestActivities.TestActivitiesImpl activitiesImpl = new TestActivities.TestActivitiesImpl(null); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java index 7892566bc8..5fda44dc72 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java @@ -17,10 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import static org.junit.Assert.assertEquals; +import io.temporal.workflow.Async; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncRetryOptionsChangeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/AsyncRetryOptionsChangeTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java index 1fc3569b6e..e63c03eebb 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncRetryOptionsChangeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java @@ -17,13 +17,15 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.client.WorkflowException; import io.temporal.common.RetryOptions; import io.temporal.failure.ApplicationFailure; import io.temporal.internal.sync.DeterministicRunnerTest; import io.temporal.worker.WorkflowImplementationOptions; +import io.temporal.workflow.Async; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/AsyncRetryTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java index a53bd61451..a07244dd3d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java @@ -17,12 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.client.WorkflowException; import io.temporal.common.RetryOptions; import io.temporal.failure.ApplicationFailure; import io.temporal.internal.sync.DeterministicRunnerTest; +import io.temporal.workflow.Async; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncUntyped2ActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/AsyncUntyped2ActivityTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java index 068b1a1f0d..1b77cd10ba 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncUntyped2ActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java @@ -17,10 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import static org.junit.Assert.assertEquals; +import io.temporal.workflow.ActivityStub; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncUntypedActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/AsyncUntypedActivityTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java index 95780e2c96..70cdb63036 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AsyncUntypedActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java @@ -17,10 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import static org.junit.Assert.assertEquals; +import io.temporal.workflow.ActivityStub; +import io.temporal.workflow.Async; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java new file mode 100644 index 0000000000..25613e2d34 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java @@ -0,0 +1,73 @@ +/* + * 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.activityTests; + +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class LocalActivitiesWorkflowTaskHeartbeatTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(WorkflowTest.TestLocalActivitiesWorkflowTaskHeartbeatWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .setTestTimeoutSeconds(15) + .build(); + + @Test + public void testLocalActivitiesWorkflowTaskHeartbeat() + throws ExecutionException, InterruptedException { + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofMinutes(5)) + .setWorkflowTaskTimeout(Duration.ofSeconds(4)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + int count = 5; + Future[] result = new Future[count]; + for (int i = 0; i < count; i++) { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); + result[i] = WorkflowClient.execute(workflowStub::execute, testWorkflowRule.getTaskQueue()); + } + for (int i = 0; i < count; i++) { + Assert.assertEquals( + "sleepActivity0sleepActivity1sleepActivity2sleepActivity3sleepActivity4", + result[i].get()); + } + Assert.assertEquals(activitiesImpl.toString(), 5 * count, activitiesImpl.invocations.size()); + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityAndQueryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityAndQueryTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityAndQueryTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityAndQueryTest.java index eaefb60db1..bd9f25f2b3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityAndQueryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityAndQueryTest.java @@ -17,12 +17,16 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.testing.TestWorkflowRule; +import io.temporal.workflow.QueryMethod; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityManyWorkflowsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityManyWorkflowsTest.java similarity index 94% rename from temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityManyWorkflowsTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityManyWorkflowsTest.java index 7c8500a47d..7f1f7c95ea 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityManyWorkflowsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityManyWorkflowsTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import static org.junit.Assert.assertEquals; @@ -28,6 +28,9 @@ import io.temporal.testing.TestEnvironmentOptions; import io.temporal.testing.TestWorkflowEnvironment; import io.temporal.worker.Worker; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import java.time.Duration; import org.junit.After; import org.junit.Before; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityRetryTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityRetryTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityRetryTest.java index accae29ccc..1945db1977 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityRetryTest.java @@ -17,13 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.LocalActivityOptions; import io.temporal.client.WorkflowException; import io.temporal.common.RetryOptions; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java similarity index 98% rename from temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java index 80e2f70587..1e930ff9da 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/LocalActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -25,6 +25,7 @@ import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java new file mode 100644 index 0000000000..c4324e40a7 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java @@ -0,0 +1,85 @@ +/* + * 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.activityTests; + +import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.Workflow; +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 LongLocalActivityWorkflowTaskHeartbeatFailureTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestLongLocalActivityWorkflowTaskHeartbeatFailureWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .setTestTimeoutSeconds(15) + .build(); + + /** + * Test that local activity is not lost during replay if it was started before forced + * WorkflowTask. + */ + @Test + public void testLongLocalActivityWorkflowTaskHeartbeatFailure() { + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofMinutes(5)) + .setWorkflowTaskTimeout(Duration.ofSeconds(2)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("sleepActivity123", result); + Assert.assertEquals(activitiesImpl.toString(), 2, activitiesImpl.invocations.size()); + } + + public static class TestLongLocalActivityWorkflowTaskHeartbeatFailureWorkflowImpl + implements TestWorkflows.TestWorkflow1 { + + static boolean invoked; + + @Override + public String execute(String taskQueue) { + TestActivities localActivities = + Workflow.newLocalActivityStub( + TestActivities.class, TestOptions.newLocalActivityOptions()); + String result = localActivities.sleepActivity(5000, 123); + if (!invoked) { + invoked = true; + throw new Error("Simulate decision failure to force replay"); + } + return result; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java new file mode 100644 index 0000000000..f88c0afd02 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java @@ -0,0 +1,61 @@ +/* + * 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.activityTests; + +import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class LongLocalActivityWorkflowTaskHeartbeatTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes( + WorkflowTest.TestLongLocalActivityWorkflowTaskHeartbeatWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testLongLocalActivityWorkflowTaskHeartbeat() { + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofMinutes(5)) + .setWorkflowTaskTimeout(Duration.ofSeconds(2)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("sleepActivity123", result); + Assert.assertEquals(activitiesImpl.toString(), 1, activitiesImpl.invocations.size()); + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonSerializableArgumentsInActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableArgumentsInActivityTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/NonSerializableArgumentsInActivityTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableArgumentsInActivityTest.java index 236876f6d5..1a84816fb9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonSerializableArgumentsInActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableArgumentsInActivityTest.java @@ -17,13 +17,16 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.activity.LocalActivityOptions; import io.temporal.common.RetryOptions; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.ActivityStub; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonSerializableExceptionInActivityWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/NonSerializableExceptionInActivityWorkflowTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java index 3261344727..78d2ee06ab 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonSerializableExceptionInActivityWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java @@ -17,10 +17,12 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.failure.ActivityFailure; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ParallelLocalActivitiesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/ParallelLocalActivitiesTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java index be79b7544a..bdc560316e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ParallelLocalActivitiesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java @@ -17,10 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.client.*; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.Async; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java new file mode 100644 index 0000000000..cd492d8a8d --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java @@ -0,0 +1,96 @@ +/* + * 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.activityTests; + +import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.Async; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; +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 java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class ParallelLocalActivityExecutionWorkflowTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestParallelLocalActivityExecutionWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testParallelLocalActivityExecutionWorkflow() { + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofMinutes(5)) + .setWorkflowTaskTimeout(Duration.ofSeconds(5)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(TestWorkflows.TestWorkflow1.class, options); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals( + "sleepActivity1sleepActivity2sleepActivity3sleepActivity4sleepActivity21sleepActivity21sleepActivity21", + result); + } + + public static class TestParallelLocalActivityExecutionWorkflowImpl + implements TestWorkflows.TestWorkflow1 { + @Override + public String execute(String taskQueue) { + TestActivities localActivities = + Workflow.newLocalActivityStub( + TestActivities.class, TestOptions.newLocalActivityOptions()); + List> results = new ArrayList<>(4); + for (int i = 1; i <= 4; i++) { + results.add(Async.function(localActivities::sleepActivity, (long) 1000 * i, i)); + } + + Promise result2 = + Async.function( + () -> { + String result = ""; + for (int i = 0; i < 3; i++) { + result += localActivities.sleepActivity(1000, 21); + } + return result; + }); + + return results.get(0).get() + + results.get(1).get() + + results.get(2).get() + + results.get(3).get() + + result2.get(); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/TryCancelActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/TryCancelActivityTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java index 6a31dcef64..f37a4877fe 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/TryCancelActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityCancellationType; import io.temporal.activity.ActivityOptions; @@ -25,6 +25,7 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedActivityRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/UntypedActivityRetryTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java index f3b21efc02..197e147a32 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedActivityRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java @@ -17,13 +17,15 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.activityTests; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowException; import io.temporal.common.RetryOptions; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.ActivityStub; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ChildAsyncLambdaWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ChildAsyncLambdaWorkflowTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java index 2836210a4d..280fae9f3c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ChildAsyncLambdaWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java @@ -17,12 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import io.temporal.api.common.v1.WorkflowExecution; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ChildAsyncWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/ChildAsyncWorkflowTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java index 58bd082fa7..9907c03fcf 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ChildAsyncWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java @@ -17,10 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static org.junit.Assert.assertEquals; +import io.temporal.workflow.Async; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; @@ -59,7 +62,7 @@ public String execute(String taskQueue) { TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = Workflow.newChildWorkflowStub( TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); - assertEquals("func", Async.function(stubF::func).get()); + Assert.assertEquals("func", Async.function(stubF::func).get()); TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1 stubF1 = Workflow.newChildWorkflowStub( TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc1.class, workflowOptions); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowAsyncRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowAsyncRetryTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java index d194d4a5aa..4e7c9a55f7 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowAsyncRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static org.junit.Assert.*; @@ -27,6 +27,10 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.failure.ChildWorkflowFailure; import io.temporal.testing.WorkflowReplayer; +import io.temporal.workflow.Async; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowCancellationTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java index 92c0f261cc..212ea54c7b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.api.enums.v1.EventType; @@ -27,6 +27,10 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; +import io.temporal.workflow.ChildWorkflowCancellationType; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowExecutionPromiseHandlerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowExecutionPromiseHandlerTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java index 3f45ed6d36..6ddc2818a6 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowExecutionPromiseHandlerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static org.junit.Assert.assertEquals; @@ -25,6 +25,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.testing.TestWorkflowRule; +import io.temporal.workflow.*; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowRetryTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java index c9e575ab53..acaf63abe5 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static io.temporal.workflow.shared.SDKTestWorkflowRule.NAMESPACE; import static io.temporal.workflow.shared.SDKTestWorkflowRule.regenerateHistoryForReplay; @@ -34,6 +34,9 @@ import io.temporal.failure.ChildWorkflowFailure; import io.temporal.testing.WorkflowReplayer; import io.temporal.worker.WorkflowImplementationOptions; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java index a90cd811e5..1ae5b9d459 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java @@ -17,10 +17,11 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static org.junit.Assert.assertEquals; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowTimeoutTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java similarity index 93% rename from temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowTimeoutTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java index 0e73c10df4..2a47a6b441 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowTimeoutTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java @@ -17,11 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static org.junit.Assert.assertTrue; import com.google.common.base.Throwables; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowWithCronScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowWithCronScheduleTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java index 6bee4c05a3..765128cb2c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowWithCronScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static io.temporal.workflow.WorkflowTest.lastCompletionResult; import static io.temporal.workflow.shared.TestOptions.newWorkflowOptionsWithTimeouts; @@ -27,6 +27,8 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NamedChildTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java similarity index 98% rename from temporal-sdk/src/test/java/io/temporal/workflow/NamedChildTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java index eb65b639b5..307eed51d8 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NamedChildTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java @@ -17,13 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static org.junit.Assert.*; import io.temporal.api.enums.v1.WorkflowIdReusePolicy; import io.temporal.client.WorkflowFailedException; import io.temporal.failure.ChildWorkflowFailure; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import java.util.UUID; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonSerializableExceptionInChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/NonSerializableExceptionInChildWorkflowTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java index e7fd9848dd..33f003a470 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonSerializableExceptionInChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java @@ -17,10 +17,12 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import io.temporal.failure.ChildWorkflowFailure; import io.temporal.worker.WorkflowImplementationOptions; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java new file mode 100644 index 0000000000..e73de461a7 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java @@ -0,0 +1,78 @@ +/* + * 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.childWorkflowTests; + +import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInfo; +import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; +import io.temporal.workflow.shared.TestOptions; +import java.util.Optional; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class ParentWorkflowInfoInChildWorkflowsTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes( + WorkflowTest.TestMultiargsWorkflowsFuncParent.class, + TestMultiargsWorkflowsFuncChild.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testParentWorkflowInfoInChildWorkflows() { + + String workflowId = "testParentWorkflowInfoInChildWorkflows"; + WorkflowOptions workflowOptions = + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setWorkflowId(workflowId) + .build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc parent = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); + + String result = parent.func(); + String expected = String.format("%s - %s", false, workflowId); + Assert.assertEquals(expected, result); + } + + public static class TestMultiargsWorkflowsFuncChild + implements TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2 { + @Override + public String func2(String s, int i) { + WorkflowInfo wi = Workflow.getInfo(); + Optional parentId = wi.getParentWorkflowId(); + return parentId.get(); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java index 2f17acc40e..0426465e13 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -25,6 +25,7 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import java.util.ArrayList; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedChildStubWorkflowAsyncInvokeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/UntypedChildStubWorkflowAsyncInvokeTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java index 95da7815e5..2d253e694a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedChildStubWorkflowAsyncInvokeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java @@ -17,8 +17,12 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; +import io.temporal.workflow.Async; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.ChildWorkflowStub; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedChildStubWorkflowAsyncTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/UntypedChildStubWorkflowAsyncTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java index d39d9a912d..1ab0076214 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedChildStubWorkflowAsyncTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java @@ -17,8 +17,11 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.ChildWorkflowStub; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedChildStubWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/UntypedChildStubWorkflowTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java index 0f13bc1543..f33b8a25de 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedChildStubWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java @@ -17,8 +17,9 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.childWorkflowTests; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionInSignalTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java similarity index 95% rename from temporal-sdk/src/test/java/io/temporal/workflow/ExceptionInSignalTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java index 8489137598..0d8e968089 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionInSignalTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java @@ -17,12 +17,15 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import io.temporal.client.WorkflowClient; +import io.temporal.workflow.Async; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import java.lang.management.ManagementFactory; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SignalAndQueryInterfaceTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java similarity index 92% rename from temporal-sdk/src/test/java/io/temporal/workflow/SignalAndQueryInterfaceTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java index 33de90f1af..fab92dfb70 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SignalAndQueryInterfaceTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java @@ -17,11 +17,15 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowStub; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import org.junit.Assert; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SignalAndQueryListenerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java similarity index 98% rename from temporal-sdk/src/test/java/io/temporal/workflow/SignalAndQueryListenerTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java index f90630ab75..e5a456e399 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SignalAndQueryListenerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java @@ -17,13 +17,14 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowQueryException; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SignalDuringLastWorkflowTaskTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/SignalDuringLastWorkflowTaskTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java index 0e824beff1..ba566e1e90 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SignalDuringLastWorkflowTaskTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java @@ -17,11 +17,12 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SignalExternalWorkflowFailureTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java similarity index 96% rename from temporal-sdk/src/test/java/io/temporal/workflow/SignalExternalWorkflowFailureTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java index 6a41d864a3..b641c601a8 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SignalExternalWorkflowFailureTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import static org.junit.Assert.*; @@ -25,6 +25,8 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowOptions; import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SignalExternalWorkflowImmediateCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/SignalExternalWorkflowImmediateCancellationTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java index 7af55d2339..4dfa20835f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SignalExternalWorkflowImmediateCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java @@ -17,12 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowOptions; import io.temporal.failure.CanceledFailure; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java similarity index 98% rename from temporal-sdk/src/test/java/io/temporal/workflow/SignalExternalWorkflowTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java index 27c6a38a78..ec09bdf791 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java @@ -17,12 +17,13 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SignalOrderingWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java similarity index 93% rename from temporal-sdk/src/test/java/io/temporal/workflow/SignalOrderingWorkflowTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java index bf914e56ee..70f392c988 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SignalOrderingWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java @@ -17,12 +17,16 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import com.google.common.reflect.TypeToken; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.workflow.SignalMethod; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SignalTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java similarity index 98% rename from temporal-sdk/src/test/java/io/temporal/workflow/SignalTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java index 8b703e35bb..b996391a70 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SignalTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java @@ -17,7 +17,7 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -27,6 +27,9 @@ import io.temporal.api.enums.v1.WorkflowExecutionStatus; import io.temporal.api.enums.v1.WorkflowIdReusePolicy; import io.temporal.client.*; +import io.temporal.workflow.CompletablePromise; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedSignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java similarity index 97% rename from temporal-sdk/src/test/java/io/temporal/workflow/UntypedSignalExternalWorkflowTest.java rename to temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java index ce20b7111e..4b5326c884 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UntypedSignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java @@ -17,9 +17,10 @@ * permissions and limitations under the License. */ -package io.temporal.workflow; +package io.temporal.workflow.signalTests; import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java new file mode 100644 index 0000000000..5b8b9aec6d --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java @@ -0,0 +1,80 @@ +/* + * 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.versionTests; + +import io.temporal.workflow.Workflow; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import org.junit.Assume; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GetVersionAddNewBeforeTest { + + private static final Logger log = LoggerFactory.getLogger(GetVersionAddNewBeforeTest.class); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionWorkflowAddNewBefore.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testGetVersionAddNewBefore() { + Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + workflowStub.execute(testWorkflowRule.getTaskQueue()); + } + + public static class TestGetVersionWorkflowAddNewBefore implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + log.info("TestGetVersionWorkflow3Impl this=" + this.hashCode()); + // Test adding a version check in replay code. + if (!Workflow.isReplaying()) { + // The first version of the code + int changeFoo = Workflow.getVersion("changeFoo", Workflow.DEFAULT_VERSION, 1); + if (changeFoo != 1) { + throw new IllegalStateException("Unexpected version: " + 1); + } + } else { + // The updated code + int changeBar = Workflow.getVersion("changeBar", Workflow.DEFAULT_VERSION, 1); + if (changeBar != Workflow.DEFAULT_VERSION) { + throw new IllegalStateException("Unexpected version: " + changeBar); + } + int changeFoo = Workflow.getVersion("changeFoo", Workflow.DEFAULT_VERSION, 1); + if (changeFoo != 1) { + throw new IllegalStateException("Unexpected version: " + changeFoo); + } + } + Workflow.sleep(1000); // forces new workflow task + return "test"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java new file mode 100644 index 0000000000..ef504cd803 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java @@ -0,0 +1,89 @@ +/* + * 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.versionTests; + +import static org.junit.Assert.assertEquals; + +import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.Workflow; +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 org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class GetVersionRemovedBeforeTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionRemovedBefore.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testGetVersionRemovedBefore() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("activity", result); + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "getVersion", + "getVersion", + "getVersion", + "getVersion", + "executeActivity Activity", + "activity Activity"); + } + + // The following test covers the scenario where getVersion call is removed before another + // version-marker command. + public static class TestGetVersionRemovedBefore implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + TestActivities testActivities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + // Test removing a version check in replay code. + if (!Workflow.isReplaying()) { + Workflow.getVersion("test_change1", Workflow.DEFAULT_VERSION, 11); + Workflow.getVersion("test_change2", Workflow.DEFAULT_VERSION, 12); + Workflow.getVersion("test_change3", Workflow.DEFAULT_VERSION, 13); + Workflow.getVersion("test_change4", Workflow.DEFAULT_VERSION, 14); + } else { + int version = Workflow.getVersion("test_change3", Workflow.DEFAULT_VERSION, 22); + assertEquals(13, version); + } + return testActivities.activity(); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java new file mode 100644 index 0000000000..994b57de7a --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java @@ -0,0 +1,88 @@ +/* + * 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.versionTests; + +import static org.junit.Assert.assertEquals; + +import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.Workflow; +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 org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class GetVersionRemovedInReplayTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionRemovedInReplay.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testGetVersionRemovedInReplay() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("activity22activity", result); + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "getVersion", + "executeActivity Activity2", + "activity Activity2", + "executeActivity Activity", + "activity Activity"); + } + + // The following test covers the scenario where getVersion call is removed before a + // non-version-marker command. + public static class TestGetVersionRemovedInReplay implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + TestActivities testActivities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + String result; + // Test removing a version check in replay code. + if (!Workflow.isReplaying()) { + int version = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 13); + assertEquals(13, version); + result = testActivities.activity2("activity2", 2); + } else { + result = testActivities.activity2("activity2", 2); + } + result += testActivities.activity(); + return result; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java new file mode 100644 index 0000000000..6e4d00caa8 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java @@ -0,0 +1,97 @@ +/* + * 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.versionTests; + +import static org.junit.Assert.assertEquals; + +import io.temporal.api.common.v1.WorkflowExecution; +import io.temporal.api.enums.v1.EventType; +import io.temporal.api.history.v1.HistoryEvent; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; +import io.temporal.client.WorkflowStub; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Rule; +import org.junit.Test; + +public class GetVersionSameIdOnReplayTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionSameIdOnReplay.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testGetVersionSameIdOnReplay() { + Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); + + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + workflowStub.execute(testWorkflowRule.getTaskQueue()); + WorkflowExecution execution = WorkflowStub.fromTyped(workflowStub).getExecution(); + GetWorkflowExecutionHistoryRequest request = + GetWorkflowExecutionHistoryRequest.newBuilder() + .setNamespace(SDKTestWorkflowRule.NAMESPACE) + .setExecution(execution) + .build(); + + // Validate that no marker is recorded + GetWorkflowExecutionHistoryResponse response = + testWorkflowRule + .getTestEnvironment() + .getWorkflowService() + .blockingStub() + .getWorkflowExecutionHistory(request); + for (HistoryEvent event : response.getHistory().getEventsList()) { + Assert.assertFalse(EventType.EVENT_TYPE_MARKER_RECORDED == event.getEventType()); + } + } + + public static class TestGetVersionSameIdOnReplay implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + // Test adding a version check in replay code. + if (!Workflow.isReplaying()) { + Workflow.sleep(Duration.ofMinutes(1)); + } else { + int version2 = Workflow.getVersion("test_change_2", Workflow.DEFAULT_VERSION, 11); + Workflow.sleep(Duration.ofMinutes(1)); + int version3 = Workflow.getVersion("test_change_2", Workflow.DEFAULT_VERSION, 11); + + assertEquals(Workflow.DEFAULT_VERSION, version3); + assertEquals(version2, version3); + } + + return "test"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java new file mode 100644 index 0000000000..d6390b30f7 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java @@ -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.versionTests; + +import static org.junit.Assert.assertEquals; + +import io.temporal.workflow.Workflow; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import org.junit.Assume; +import org.junit.Rule; +import org.junit.Test; + +public class GetVersionSameIdTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionSameId.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testGetVersionSameId() { + Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); + + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + workflowStub.execute(testWorkflowRule.getTaskQueue()); + } + + public static class TestGetVersionSameId implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + // Test adding a version check in replay code. + if (!Workflow.isReplaying()) { + int version2 = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 11); + Workflow.sleep(Duration.ofMinutes(1)); + } else { + int version2 = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 11); + Workflow.sleep(Duration.ofMinutes(1)); + int version3 = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 11); + + assertEquals(11, version3); + assertEquals(version2, version3); + } + + return "test"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java new file mode 100644 index 0000000000..280f90b122 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java @@ -0,0 +1,112 @@ +/* + * 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.versionTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.Workflow; +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 org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class GetVersionTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testGetVersion() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("activity22activity1activity1activity1", result); + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "getVersion", + "executeActivity Activity2", + "activity Activity2", + "getVersion", + "executeActivity customActivity1", + "activity customActivity1", + "executeActivity customActivity1", + "activity customActivity1", + "sleep PT1S", + "getVersion", + "executeActivity customActivity1", + "activity customActivity1"); + } + + public static class TestGetVersionWorkflowImpl implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + TestActivities testActivities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + + // Test adding a version check in non-replay code. + int version = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 1); + assertEquals(version, 1); + String result = testActivities.activity2("activity2", 2); + + // Test version change in non-replay code. + version = Workflow.getVersion("test_change", 1, 2); + assertEquals(version, 1); + result += "activity" + testActivities.activity1(1); + + boolean replaying = false; + // Test adding a version check in replay code. + if (!Workflow.isReplaying()) { + result += "activity" + testActivities.activity1(1); // This is executed in non-replay mode. + } else { + replaying = true; + int version2 = Workflow.getVersion("test_change_2", Workflow.DEFAULT_VERSION, 1); + assertEquals(version2, Workflow.DEFAULT_VERSION); + result += "activity" + testActivities.activity1(1); + } + + // Test get version in replay mode. + Workflow.sleep(1000); + version = Workflow.getVersion("test_change", 1, 2); + assertEquals(version, 1); + result += "activity" + testActivities.activity1(1); + assertTrue(replaying); + return result; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java new file mode 100644 index 0000000000..3669cc5763 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java @@ -0,0 +1,80 @@ +/* + * 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.versionTests; + +import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.Workflow; +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 org.junit.Assert; +import org.junit.Assume; +import org.junit.Rule; +import org.junit.Test; + +public class GetVersionWorkflowRemoveTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionWorkflowRemove.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testGetVersionWorkflowRemove() { + Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); + + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + Assert.assertEquals("foo10", workflowStub.execute(testWorkflowRule.getTaskQueue())); + } + + public static class TestGetVersionWorkflowRemove implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + TestActivities activities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + String result; + // Test adding a version check in replay code. + if (!Workflow.isReplaying()) { + // The first version of the code + int changeFoo = Workflow.getVersion("changeFoo", Workflow.DEFAULT_VERSION, 1); + if (changeFoo != 1) { + throw new IllegalStateException("Unexpected version: " + 1); + } + result = activities.activity2("foo", 10); + } else { + // No getVersionCall + result = activities.activity2("foo", 10); + } + Workflow.sleep(1000); // forces new workflow task + return result; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java new file mode 100644 index 0000000000..0a3d17a102 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java @@ -0,0 +1,82 @@ +/* + * 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.versionTests; + +import io.temporal.workflow.Workflow; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import org.junit.Assume; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GetVersionWorkflowReplaceCompletelyTest { + + private static final Logger log = + LoggerFactory.getLogger(GetVersionWorkflowReplaceCompletelyTest.class); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionWorkflowReplaceCompletely.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testGetVersionWorkflowReplaceCompletely() { + Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); + + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + workflowStub.execute(testWorkflowRule.getTaskQueue()); + } + + public static class TestGetVersionWorkflowReplaceCompletely + implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + log.info("TestGetVersionWorkflow3Impl this=" + this.hashCode()); + // Test adding a version check in replay code. + if (!Workflow.isReplaying()) { + // The first version of the code + Workflow.getVersion("changeFoo0", Workflow.DEFAULT_VERSION, 2); + Workflow.getVersion("changeFoo1", Workflow.DEFAULT_VERSION, 111); + Workflow.getVersion("changeFoo2", Workflow.DEFAULT_VERSION, 101); + } else { + // The updated code + int changeBar = Workflow.getVersion("changeBar", Workflow.DEFAULT_VERSION, 1); + if (changeBar != Workflow.DEFAULT_VERSION) { + throw new IllegalStateException("Unexpected version: " + changeBar); + } + int changeFoo = Workflow.getVersion("changeFoo10", Workflow.DEFAULT_VERSION, 123); + if (changeFoo != Workflow.DEFAULT_VERSION) { + throw new IllegalStateException("Unexpected version: " + changeFoo); + } + } + Workflow.sleep(1000); // forces new workflow task + return "test"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java new file mode 100644 index 0000000000..5feaae3451 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java @@ -0,0 +1,87 @@ +/* + * 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.versionTests; + +import io.temporal.workflow.Workflow; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import org.junit.Assume; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GetVersionWorkflowReplaceGetVersionIdTest { + + private static final Logger log = + LoggerFactory.getLogger(GetVersionWorkflowReplaceGetVersionIdTest.class); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionWorkflowReplaceGetVersionId.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testGetVersionWorkflowReplaceGetVersionId() { + Assume.assumeFalse("skipping for docker tests", SDKTestWorkflowRule.useExternalService); + + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + workflowStub.execute(testWorkflowRule.getTaskQueue()); + } + + public static class TestGetVersionWorkflowReplaceGetVersionId + implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + log.info("TestGetVersionWorkflow3Impl this=" + this.hashCode()); + // Test adding a version check in replay code. + if (!Workflow.isReplaying()) { + // The first version of the code + int changeFoo1 = Workflow.getVersion("changeFoo0", Workflow.DEFAULT_VERSION, 2); + if (changeFoo1 != 2) { + throw new IllegalStateException("Unexpected version: " + changeFoo1); + } + int changeFoo2 = Workflow.getVersion("changeFoo1", Workflow.DEFAULT_VERSION, 111); + if (changeFoo2 != 111) { + throw new IllegalStateException("Unexpected version: " + changeFoo2); + } + } else { + // The updated code + int changeBar = Workflow.getVersion("changeBar", Workflow.DEFAULT_VERSION, 1); + if (changeBar != Workflow.DEFAULT_VERSION) { + throw new IllegalStateException("Unexpected version: " + changeBar); + } + int changeFoo = Workflow.getVersion("changeFoo1", Workflow.DEFAULT_VERSION, 123); + if (changeFoo != 111) { + throw new IllegalStateException("Unexpected version: " + changeFoo); + } + } + Workflow.sleep(1000); // forces new workflow task + return "test"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java new file mode 100644 index 0000000000..644e774da7 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java @@ -0,0 +1,87 @@ +/* + * 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.versionTests; + +import io.temporal.client.WorkflowException; +import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; +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 org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class VersionNotSupportedTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestVersionNotSupportedWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testVersionNotSupported() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + + try { + workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.fail("unreachable"); + } catch (WorkflowException e) { + Assert.assertEquals( + "message='unsupported change version', type='test', nonRetryable=false", + e.getCause().getMessage()); + } + } + + public static class TestVersionNotSupportedWorkflowImpl implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + TestActivities testActivities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + + // Test adding a version check in non-replay code. + int version = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 1); + String result = ""; + if (version == Workflow.DEFAULT_VERSION) { + result += "activity" + testActivities.activity1(1); + } else { + result += testActivities.activity2("activity2", 2); // This is executed. + } + + // Catching error from getVersion is only for unit test purpose. + // Do not ever do it in production code. + try { + Workflow.getVersion("test_change", 2, 3); + } catch (Error e) { + throw Workflow.wrap(ApplicationFailure.newFailure("unsupported change version", "test")); + } + return result; + } + } +} From 62ba73529f885d46967ad951938e9f851bf5b549 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Thu, 18 Mar 2021 12:09:23 -0700 Subject: [PATCH 05/21] Moved classes/methods into places where they're used. --- .../workflow/ContinueAsNewNoArgsTest.java | 14 +- .../GetAttemptFromWorkflowInfoTest.java | 14 +- .../temporal/workflow/LargeHistoryTest.java | 25 +- .../workflow/PolymorphicStartTest.java | 13 +- .../java/io/temporal/workflow/SagaTest.java | 86 +++- .../temporal/workflow/WorkflowLocalsTest.java | 7 +- ...ithMethodRetryDoNotRetryExceptionTest.java | 20 +- .../WorkflowTaskTimeoutWorkflowTest.java | 13 +- .../io/temporal/workflow/WorkflowTest.java | 405 +++--------------- .../ActivityRetryWithExpirationTest.java | 11 +- .../activityTests/AsyncActivityTest.java | 2 - .../AsyncUntyped2ActivityTest.java | 2 - .../AsyncUntypedActivityTest.java | 2 - ...alActivitiesWorkflowTaskHeartbeatTest.java | 20 +- ...ocalActivityWorkflowTaskHeartbeatTest.java | 17 +- ...onSerializableArgumentsInActivityTest.java | 13 +- ...izableExceptionInActivityWorkflowTest.java | 23 +- .../ParallelLocalActivitiesTest.java | 7 +- .../ChildWorkflowWithCronScheduleTest.java | 1 - ...ializableExceptionInChildWorkflowTest.java | 15 +- .../UntypedChildStubWorkflowTest.java | 61 ++- .../TestMultiargdsWorkflowFunctions.java | 22 +- 22 files changed, 359 insertions(+), 434 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java index 2ac2e4dd30..4c4b2048fa 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java @@ -43,8 +43,7 @@ public class ContinueAsNewNoArgsTest { @Test public void testContinueAsNewNoArgs() { - WorkflowTest.NoArgsWorkflow client = - testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.NoArgsWorkflow.class); + NoArgsWorkflow client = testWorkflowRule.newWorkflowStubTimeoutOptions(NoArgsWorkflow.class); String result = client.execute(); Assert.assertEquals("done", result); testWorkflowRule @@ -57,12 +56,17 @@ public void testContinueAsNewNoArgs() { "newThread workflow-method"); } - public static class TestContinueAsNewNoArgsImpl implements WorkflowTest.NoArgsWorkflow { + @WorkflowInterface + public interface NoArgsWorkflow { + @WorkflowMethod + String execute(); + } + + public static class TestContinueAsNewNoArgsImpl implements NoArgsWorkflow { @Override public String execute() { - WorkflowTest.NoArgsWorkflow next = - Workflow.newContinueAsNewStub(WorkflowTest.NoArgsWorkflow.class); + NoArgsWorkflow next = Workflow.newContinueAsNewStub(NoArgsWorkflow.class); WorkflowInfo info = Workflow.getInfo(); if (!info.getContinuedExecutionRunId().isPresent()) { next.execute(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java index 57e13b3fc5..cd85c06adc 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java @@ -49,16 +49,22 @@ public void testGetAttemptFromWorkflowInfo() { .toBuilder() .setWorkflowId(workflowId) .build(); - WorkflowTest.TestGetAttemptWorkflowsFunc workflow = + TestGetAttemptWorkflowsFunc workflow = testWorkflowRule .getWorkflowClient() - .newWorkflowStub(WorkflowTest.TestGetAttemptWorkflowsFunc.class, workflowOptions); + .newWorkflowStub(TestGetAttemptWorkflowsFunc.class, workflowOptions); int attempt = workflow.func(); Assert.assertEquals(1, attempt); } - public static class TestAttemptReturningWorkflowFunc - implements WorkflowTest.TestGetAttemptWorkflowsFunc { + @WorkflowInterface + public interface TestGetAttemptWorkflowsFunc { + + @WorkflowMethod + int func(); + } + + public static class TestAttemptReturningWorkflowFunc implements TestGetAttemptWorkflowsFunc { @Override public int func() { WorkflowInfo wi = Workflow.getInfo(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/LargeHistoryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/LargeHistoryTest.java index e5ac5bdb01..d219b1e3e6 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/LargeHistoryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/LargeHistoryTest.java @@ -19,6 +19,7 @@ package io.temporal.workflow; +import io.temporal.activity.ActivityInterface; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestOptions; import java.time.Duration; @@ -47,11 +48,11 @@ public class LargeHistoryTest { @Ignore // Requires DEBUG_TIMEOUTS=true public void testLargeHistory() { final int activityCount = 1000; - WorkflowTest.TestLargeWorkflow workflowStub = + TestLargeWorkflow workflowStub = testWorkflowRule .getWorkflowClient() .newWorkflowStub( - WorkflowTest.TestLargeWorkflow.class, + TestLargeWorkflow.class, TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) .toBuilder() .setWorkflowTaskTimeout(Duration.ofSeconds(30)) @@ -63,21 +64,31 @@ public void testLargeHistory() { Assert.assertEquals("done", result); } - public static class TestLargeWorkflowActivityImpl - implements WorkflowTest.TestLargeWorkflowActivity { + @WorkflowInterface + public interface TestLargeWorkflow { + @WorkflowMethod + String execute(int activityCount, String taskQueue); + } + + @ActivityInterface + public interface TestLargeWorkflowActivity { + String activity(); + } + + public static class TestLargeWorkflowActivityImpl implements TestLargeWorkflowActivity { @Override public String activity() { return "done"; } } - public static class TestLargeHistory implements WorkflowTest.TestLargeWorkflow { + public static class TestLargeHistory implements TestLargeWorkflow { @Override public String execute(int activityCount, String taskQueue) { - WorkflowTest.TestLargeWorkflowActivity activities = + TestLargeWorkflowActivity activities = Workflow.newActivityStub( - WorkflowTest.TestLargeWorkflowActivity.class, + TestLargeWorkflowActivity.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); List> results = new ArrayList<>(); for (int i = 0; i < activityCount; i++) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java index b7321c38a2..f109e40aa3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java @@ -39,8 +39,8 @@ public class PolymorphicStartTest { @Test public void testPolymorphicStart() { - WorkflowTest.WorkflowBase[] stubs = - new WorkflowTest.WorkflowBase[] { + WorkflowBase[] stubs = + new WorkflowBase[] { testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowA.class), testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowB.class) }; @@ -48,11 +48,16 @@ public void testPolymorphicStart() { Assert.assertEquals("WorkflowAImpl0, WorkflowBImpl1", results); } + public interface WorkflowBase { + @WorkflowMethod + String execute(String arg); + } + @WorkflowInterface - public interface WorkflowA extends WorkflowTest.WorkflowBase {} + public interface WorkflowA extends WorkflowBase {} @WorkflowInterface - public interface WorkflowB extends WorkflowTest.WorkflowBase {} + public interface WorkflowB extends WorkflowBase {} public static class WorkflowBImpl implements WorkflowB { @Override diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java index ec6b5cc88f..843f0745f8 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java @@ -19,9 +19,12 @@ package io.temporal.workflow; +import io.temporal.common.RetryOptions; import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; +import io.temporal.workflow.shared.TestOptions; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -35,9 +38,9 @@ public class SagaTest { public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( - WorkflowTest.TestSagaWorkflowImpl.class, - WorkflowTest.TestMultiargsWorkflowsFuncImpl.class, - WorkflowTest.TestCompensationWorkflowImpl.class) + TestSagaWorkflowImpl.class, + TestCompensationWorkflowImpl.class, + TestMultiargsWorkflowsFuncImpl.class) .setActivityImplementations(activitiesImpl) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) @@ -45,8 +48,8 @@ public class SagaTest { @Test public void testSaga() { - WorkflowTest.TestSagaWorkflow sagaWorkflow = - testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.TestSagaWorkflow.class); + TestSagaWorkflow sagaWorkflow = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestSagaWorkflow.class); sagaWorkflow.execute(testWorkflowRule.getTaskQueue(), false); testWorkflowRule .getInterceptor(TracingWorkerInterceptor.class) @@ -69,11 +72,80 @@ public void testSaga() { @Test public void testSagaParallelCompensation() { - WorkflowTest.TestSagaWorkflow sagaWorkflow = - testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.TestSagaWorkflow.class); + TestSagaWorkflow sagaWorkflow = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestSagaWorkflow.class); sagaWorkflow.execute(testWorkflowRule.getTaskQueue(), true); String trace = testWorkflowRule.getInterceptor(TracingWorkerInterceptor.class).getTrace(); Assert.assertTrue(trace, trace.contains("executeChildWorkflow TestCompensationWorkflow")); Assert.assertTrue(trace, trace.contains("executeActivity Activity2")); } + + @WorkflowInterface + public interface TestSagaWorkflow { + @WorkflowMethod + String execute(String taskQueue, boolean parallelCompensation); + } + + @WorkflowInterface + public interface TestCompensationWorkflow { + @WorkflowMethod + void compensate(); + } + + public static class TestCompensationWorkflowImpl implements TestCompensationWorkflow { + @Override + public void compensate() {} + } + + public static class TestSagaWorkflowImpl implements TestSagaWorkflow { + + @Override + public String execute(String taskQueue, boolean parallelCompensation) { + TestActivities testActivities = + Workflow.newActivityStub( + TestActivities.class, + TestOptions.newActivityOptionsForTaskQueue(taskQueue) + .toBuilder() + .setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build()) + .build()); + + ChildWorkflowOptions workflowOptions = + ChildWorkflowOptions.newBuilder().setTaskQueue(taskQueue).build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF1 = + Workflow.newChildWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); + + Saga saga = + new Saga( + new Saga.Options.Builder().setParallelCompensation(parallelCompensation).build()); + try { + testActivities.activity1(10); + saga.addCompensation(testActivities::activity2, "compensate", -10); + + stubF1.func(); + + TestCompensationWorkflow compensationWorkflow = + Workflow.newChildWorkflowStub(TestCompensationWorkflow.class, workflowOptions); + saga.addCompensation(compensationWorkflow::compensate); + + testActivities.throwIO(); + saga.addCompensation( + () -> { + throw new RuntimeException("unreachable"); + }); + } catch (Exception e) { + saga.compensate(); + } + return "done"; + } + } + + public static class TestMultiargsWorkflowsFuncImpl + implements TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc { + + @Override + public String func() { + return "done"; + } + } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java index bce8d2b0d4..43d1917078 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java @@ -19,17 +19,16 @@ package io.temporal.workflow; +import static org.junit.Assert.assertEquals; + import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import java.time.Duration; - -import static org.junit.Assert.assertEquals; - public class WorkflowLocalsTest { private final TestActivities.TestActivitiesImpl activitiesImpl = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java index 54530ef4f5..48ec61f27f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java @@ -20,6 +20,7 @@ package io.temporal.workflow; import io.temporal.client.WorkflowException; +import io.temporal.common.MethodRetry; import io.temporal.failure.ApplicationFailure; import io.temporal.worker.WorkflowImplementationOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; @@ -54,9 +55,8 @@ public class WorkflowRetryWithMethodRetryDoNotRetryExceptionTest { @Test public void testWorkflowRetryWithMethodRetryDoNotRetryException() { - WorkflowTest.TestWorkflowRetryWithMethodRetry workflowStub = - testWorkflowRule.newWorkflowStubTimeoutOptions( - WorkflowTest.TestWorkflowRetryWithMethodRetry.class); + TestWorkflowRetryWithMethodRetry workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflowRetryWithMethodRetry.class); try { workflowStub.execute(testName.getMethodName()); Assert.fail("unreachable"); @@ -70,8 +70,20 @@ public void testWorkflowRetryWithMethodRetryDoNotRetryException() { } } + @WorkflowInterface + public interface TestWorkflowRetryWithMethodRetry { + + @WorkflowMethod + @MethodRetry( + initialIntervalSeconds = 1, + maximumIntervalSeconds = 1, + maximumAttempts = 30, + doNotRetry = "java.lang.IllegalArgumentException") + String execute(String testName); + } + public static class TestWorkflowRetryWithMethodRetryImpl - implements WorkflowTest.TestWorkflowRetryWithMethodRetry { + implements TestWorkflowRetryWithMethodRetry { @Override public String execute(String testName) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java index 291f9ae806..f18a3044fb 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java @@ -55,16 +55,21 @@ public void testWorkflowTaskTimeoutWorkflow() throws InterruptedException { .setWorkflowTaskTimeout(Duration.ofSeconds(1)) .build(); - WorkflowTest.WorkflowTaskTimeoutWorkflow stub = + WorkflowTaskTimeoutWorkflow stub = testWorkflowRule .getWorkflowClient() - .newWorkflowStub(WorkflowTest.WorkflowTaskTimeoutWorkflow.class, options); + .newWorkflowStub(WorkflowTaskTimeoutWorkflow.class, options); String result = stub.execute(testName.getMethodName()); Assert.assertEquals("some result", result); } - public static class WorkflowTaskTimeoutWorkflowImpl - implements WorkflowTest.WorkflowTaskTimeoutWorkflow { + @WorkflowInterface + public interface WorkflowTaskTimeoutWorkflow { + @WorkflowMethod + String execute(String testName) throws InterruptedException; + } + + public static class WorkflowTaskTimeoutWorkflowImpl implements WorkflowTaskTimeoutWorkflow { @Override public String execute(String testName) throws InterruptedException { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java index cf1a1db930..49f5c24d98 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java @@ -19,27 +19,32 @@ package io.temporal.workflow; -import static org.junit.Assert.*; - -import io.temporal.activity.*; +import io.temporal.activity.Activity; +import io.temporal.activity.ActivityOptions; import io.temporal.common.CronSchedule; -import io.temporal.common.MethodRetry; -import io.temporal.common.RetryOptions; -import io.temporal.failure.*; -import io.temporal.workflow.shared.*; +import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; -import io.temporal.workflow.shared.TestWorkflows; -import java.io.*; +import io.temporal.workflow.shared.TestOptions; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.text.SimpleDateFormat; import java.time.Duration; -import java.util.*; -import java.util.concurrent.*; +import java.util.Date; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import org.slf4j.Logger; public class WorkflowTest { + private static final Map retryCount = new ConcurrentHashMap<>(); + public static String lastCompletionResult; + static Optional lastFail; + @WorkflowInterface public interface TestWorkflowSignaled { @@ -50,12 +55,6 @@ public interface TestWorkflowSignaled { void signal1(String arg); } - public interface EmptyInterface {} - - public interface UnrelatedInterface { - void unrelatedMethod(); - } - @WorkflowInterface public interface TestWorkflow { @WorkflowMethod @@ -68,65 +67,6 @@ public interface TestChildWorkflow { void execute(); } - @WorkflowInterface - public interface NoArgsWorkflow { - @WorkflowMethod - String execute(); - } - - public static class TestUntypedChildStubWorkflow implements TestWorkflows.TestWorkflow1 { - - @Override - public String execute(String taskQueue) { - ChildWorkflowOptions workflowOptions = - ChildWorkflowOptions.newBuilder().setTaskQueue(taskQueue).build(); - ChildWorkflowStub stubF = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc", workflowOptions); - assertEquals("func", stubF.execute(String.class)); - // Workflow type overridden through the @WorkflowMethod.name - ChildWorkflowStub stubF1 = Workflow.newUntypedChildWorkflowStub("func1", workflowOptions); - assertEquals("1", stubF1.execute(String.class, "1")); - ChildWorkflowStub stubF2 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc2", workflowOptions); - assertEquals("12", stubF2.execute(String.class, "1", 2)); - ChildWorkflowStub stubF3 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc3", workflowOptions); - assertEquals("123", stubF3.execute(String.class, "1", 2, 3)); - ChildWorkflowStub stubF4 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc4", workflowOptions); - assertEquals("1234", stubF4.execute(String.class, "1", 2, 3, 4)); - ChildWorkflowStub stubF5 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc5", workflowOptions); - assertEquals("12345", stubF5.execute(String.class, "1", 2, 3, 4, 5)); - ChildWorkflowStub stubF6 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc6", workflowOptions); - assertEquals("123456", stubF6.execute(String.class, "1", 2, 3, 4, 5, 6)); - - ChildWorkflowStub stubP = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc", workflowOptions); - stubP.execute(Void.class); - ChildWorkflowStub stubP1 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc1", workflowOptions); - stubP1.execute(Void.class, "1"); - ChildWorkflowStub stubP2 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc2", workflowOptions); - stubP2.execute(Void.class, "1", 2); - ChildWorkflowStub stubP3 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc3", workflowOptions); - stubP3.execute(Void.class, "1", 2, 3); - ChildWorkflowStub stubP4 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc4", workflowOptions); - stubP4.execute(Void.class, "1", 2, 3, 4); - ChildWorkflowStub stubP5 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc5", workflowOptions); - stubP5.execute(Void.class, "1", 2, 3, 4, 5); - ChildWorkflowStub stubP6 = - Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc6", workflowOptions); - stubP6.execute(Void.class, "1", 2, 3, 4, 5, 6); - return null; - } - } - @WorkflowInterface public interface QueryableWorkflow { @@ -154,6 +94,41 @@ public interface ITestNamedChild { String execute(String arg); } + @WorkflowInterface + public interface SignalingChild { + + @WorkflowMethod + String execute(String arg, String parentWorkflowId); + } + + @WorkflowInterface + public interface TestWorkflowRetry { + + @WorkflowMethod + String execute(String testName); + } + + @WorkflowInterface + public interface TestWorkflowWithCronSchedule { + @WorkflowMethod + @CronSchedule("0 * * * *") + String execute(String testName); + } + + @WorkflowInterface + public interface DeterminismFailingWorkflow { + @WorkflowMethod + void execute(String taskQueue); + } + + public interface SignalQueryBase { + @SignalMethod + void signal(String arg); + + @QueryMethod + String getSignal(); + } + public static class TestChild implements ITestChild { @Override @@ -179,44 +154,6 @@ public String execute(String taskQueue, int delay) { } } - @WorkflowInterface - public interface SignalingChild { - - @WorkflowMethod - String execute(String arg, String parentWorkflowId); - } - - private static final Map retryCount = new ConcurrentHashMap<>(); - - @WorkflowInterface - public interface TestWorkflowRetry { - - @WorkflowMethod - String execute(String testName); - } - - @WorkflowInterface - public interface TestWorkflowRetryWithMethodRetry { - - @WorkflowMethod - @MethodRetry( - initialIntervalSeconds = 1, - maximumIntervalSeconds = 1, - maximumAttempts = 30, - doNotRetry = "java.lang.IllegalArgumentException") - String execute(String testName); - } - - @WorkflowInterface - public interface TestWorkflowWithCronSchedule { - @WorkflowMethod - @CronSchedule("0 * * * *") - String execute(String testName); - } - - public static String lastCompletionResult; - static Optional lastFail; - public static class TestWorkflowWithCronScheduleImpl implements TestWorkflowWithCronSchedule { @Override @@ -249,36 +186,6 @@ public String execute(String testName) { } } - public static class TestCronParentWorkflow implements TestWorkflows.TestWorkflow1 { - - private final TestWorkflowWithCronSchedule cronChild = - Workflow.newChildWorkflowStub(TestWorkflowWithCronSchedule.class); - - @Override - public String execute(String taskQueue) { - return cronChild.execute(taskQueue); - } - } - - public interface ProcInvocationQueryable { - - @QueryMethod(name = "getTrace") - String query(); - } - - @WorkflowInterface - public interface TestGetAttemptWorkflowsFunc { - - @WorkflowMethod - int func(); - } - - @WorkflowInterface - public interface DeterminismFailingWorkflow { - @WorkflowMethod - void execute(String taskQueue); - } - public static class DeterminismFailingWorkflowImpl implements DeterminismFailingWorkflow { @Override @@ -305,203 +212,6 @@ public NonSerializableException() { } } - @ActivityInterface - public interface NonSerializableExceptionActivity { - void execute(); - } - - public static class NonSerializableExceptionActivityImpl - implements NonSerializableExceptionActivity { - - @Override - public void execute() { - throw new NonSerializableException(); - } - } - - @ActivityInterface - public interface NonDeserializableArgumentsActivity { - void execute(int arg); - } - - public static class NonDeserializableExceptionActivityImpl - implements NonDeserializableArgumentsActivity { - - @Override - public void execute(int arg) {} - } - - @WorkflowInterface - public interface NonSerializableExceptionChildWorkflow { - - @WorkflowMethod - String execute(String taskQueue); - } - - @WorkflowInterface - public interface TestLargeWorkflow { - @WorkflowMethod - String execute(int activityCount, String taskQueue); - } - - @ActivityInterface - public interface TestLargeWorkflowActivity { - String activity(); - } - - @WorkflowInterface - public interface WorkflowTaskTimeoutWorkflow { - @WorkflowMethod - String execute(String testName) throws InterruptedException; - } - - public static class TestParallelLocalActivitiesWorkflowImpl - implements TestWorkflows.TestWorkflow1 { - public static final int COUNT = 100; - - @Override - public String execute(String taskQueue) { - TestActivities localActivities = - Workflow.newLocalActivityStub( - TestActivities.class, TestOptions.newLocalActivityOptions()); - List> laResults = new ArrayList<>(); - Random r = Workflow.newRandom(); - for (int i = 0; i < COUNT; i++) { - laResults.add(Async.function(localActivities::sleepActivity, (long) r.nextInt(3000), i)); - } - Promise.allOf(laResults).get(); - return "done"; - } - } - - public static class TestLocalActivitiesWorkflowTaskHeartbeatWorkflowImpl - implements TestWorkflows.TestWorkflow1 { - @Override - public String execute(String taskQueue) { - TestActivities localActivities = - Workflow.newLocalActivityStub( - TestActivities.class, TestOptions.newLocalActivityOptions()); - String result = ""; - for (int i = 0; i < 5; i++) { - result += localActivities.sleepActivity(2000, i); - } - return result; - } - } - - public static class TestLongLocalActivityWorkflowTaskHeartbeatWorkflowImpl - implements TestWorkflows.TestWorkflow1 { - @Override - public String execute(String taskQueue) { - TestActivities localActivities = - Workflow.newLocalActivityStub( - TestActivities.class, TestOptions.newLocalActivityOptions()); - return localActivities.sleepActivity(5000, 123); - } - } - - @WorkflowInterface - public interface TestWorkflowQuery { - - @WorkflowMethod() - String execute(String taskQueue); - - @QueryMethod() - String query(); - } - - public interface GreetingWorkflow { - - @WorkflowMethod - void createGreeting(String name); - } - - public interface GreetingActivities { - @ActivityMethod - String composeGreeting(String string); - } - - static class GreetingActivitiesImpl implements GreetingActivities { - @Override - public String composeGreeting(String string) { - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - throw new Error("Unexpected", e); - } - return "greetings: " + string; - } - } - - @WorkflowInterface - public interface TestCompensationWorkflow { - @WorkflowMethod - void compensate(); - } - - public static class TestMultiargsWorkflowsFuncImpl - implements TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc { - - @Override - public String func() { - return "done"; - } - } - - public static class TestCompensationWorkflowImpl implements TestCompensationWorkflow { - @Override - public void compensate() {} - } - - @WorkflowInterface - public interface TestSagaWorkflow { - @WorkflowMethod - String execute(String taskQueue, boolean parallelCompensation); - } - - public static class TestSagaWorkflowImpl implements TestSagaWorkflow { - - @Override - public String execute(String taskQueue, boolean parallelCompensation) { - TestActivities testActivities = - Workflow.newActivityStub( - TestActivities.class, - TestOptions.newActivityOptionsForTaskQueue(taskQueue) - .toBuilder() - .setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build()) - .build()); - - ChildWorkflowOptions workflowOptions = - ChildWorkflowOptions.newBuilder().setTaskQueue(taskQueue).build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF1 = - Workflow.newChildWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); - - Saga saga = - new Saga( - new Saga.Options.Builder().setParallelCompensation(parallelCompensation).build()); - try { - testActivities.activity1(10); - saga.addCompensation(testActivities::activity2, "compensate", -10); - - stubF1.func(); - - TestCompensationWorkflow compensationWorkflow = - Workflow.newChildWorkflowStub(TestCompensationWorkflow.class, workflowOptions); - saga.addCompensation(compensationWorkflow::compensate); - - testActivities.throwIO(); - saga.addCompensation( - () -> { - throw new RuntimeException("unreachable"); - }); - } catch (Exception e) { - saga.compensate(); - } - return "done"; - } - } - public static class TestMultiargsWorkflowsFuncParent implements TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc { @Override @@ -523,17 +233,4 @@ public String func() { return result; } } - - public interface WorkflowBase { - @WorkflowMethod - String execute(String arg); - } - - public interface SignalQueryBase { - @SignalMethod - void signal(String arg); - - @QueryMethod - String getSignal(); - } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java index c9acd64bce..02fce8c944 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java @@ -27,7 +27,6 @@ import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; @@ -65,10 +64,14 @@ public void testActivityRetryWithExpiration() { Assert.assertEquals(activitiesImpl.toString(), 3, activitiesImpl.invocations.size()); } + public interface EmptyInterface {} + + public interface UnrelatedInterface { + void unrelatedMethod(); + } + public static class TestActivityRetryWithExpiration - implements TestWorkflows.TestWorkflow1, - WorkflowTest.EmptyInterface, - WorkflowTest.UnrelatedInterface { + implements TestWorkflows.TestWorkflow1, EmptyInterface, UnrelatedInterface { @Override @SuppressWarnings("Finally") diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java index 5fda44dc72..586b64612f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java @@ -48,8 +48,6 @@ public class AsyncActivityTest { @Test public void testAsyncActivity() { - // TODO: (vkoby) See if this activityImpl could be constructed from within the rule with the - // right completion client. activitiesImpl.completionClient = testWorkflowRule.getWorkflowClient().newActivityCompletionClient(); TestWorkflows.TestWorkflow1 client = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java index 1b77cd10ba..85ee51d62a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java @@ -46,8 +46,6 @@ public class AsyncUntyped2ActivityTest { @Test public void testAsyncUntyped2Activity() { - // TODO: (vkoby) See if this activityImpl could be constructed from within the rule with the - // right completion client. activitiesImpl.completionClient = testWorkflowRule.getWorkflowClient().newActivityCompletionClient(); TestWorkflows.TestWorkflow1 client = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java index 70cdb63036..62b81a28fd 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java @@ -47,8 +47,6 @@ public class AsyncUntypedActivityTest { @Test public void testAsyncUntypedActivity() { - // TODO: (vkoby) See if this activityImpl could be constructed from within the rule with the - // right completion client. activitiesImpl.completionClient = testWorkflowRule.getWorkflowClient().newActivityCompletionClient(); TestWorkflows.TestWorkflow1 client = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java index 25613e2d34..6aaee3b943 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java @@ -21,9 +21,10 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; -import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.Workflow; 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 java.util.concurrent.ExecutionException; @@ -40,7 +41,7 @@ public class LocalActivitiesWorkflowTaskHeartbeatTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(WorkflowTest.TestLocalActivitiesWorkflowTaskHeartbeatWorkflowImpl.class) + .setWorkflowTypes(TestLocalActivitiesWorkflowTaskHeartbeatWorkflowImpl.class) .setActivityImplementations(activitiesImpl) .setTestTimeoutSeconds(15) .build(); @@ -70,4 +71,19 @@ public void testLocalActivitiesWorkflowTaskHeartbeat() } Assert.assertEquals(activitiesImpl.toString(), 5 * count, activitiesImpl.invocations.size()); } + + public static class TestLocalActivitiesWorkflowTaskHeartbeatWorkflowImpl + implements TestWorkflows.TestWorkflow1 { + @Override + public String execute(String taskQueue) { + TestActivities localActivities = + Workflow.newLocalActivityStub( + TestActivities.class, TestOptions.newLocalActivityOptions()); + String result = ""; + for (int i = 0; i < 5; i++) { + result += localActivities.sleepActivity(2000, i); + } + return result; + } + } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java index f88c0afd02..0aa9a99d96 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java @@ -20,9 +20,10 @@ package io.temporal.workflow.activityTests; import io.temporal.client.WorkflowOptions; -import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.Workflow; 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; @@ -37,8 +38,7 @@ public class LongLocalActivityWorkflowTaskHeartbeatTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes( - WorkflowTest.TestLongLocalActivityWorkflowTaskHeartbeatWorkflowImpl.class) + .setWorkflowTypes(TestLongLocalActivityWorkflowTaskHeartbeatWorkflowImpl.class) .setActivityImplementations(activitiesImpl) .build(); @@ -58,4 +58,15 @@ public void testLongLocalActivityWorkflowTaskHeartbeat() { Assert.assertEquals("sleepActivity123", result); Assert.assertEquals(activitiesImpl.toString(), 1, activitiesImpl.invocations.size()); } + + public static class TestLongLocalActivityWorkflowTaskHeartbeatWorkflowImpl + implements TestWorkflows.TestWorkflow1 { + @Override + public String execute(String taskQueue) { + TestActivities localActivities = + Workflow.newLocalActivityStub( + TestActivities.class, TestOptions.newLocalActivityOptions()); + return localActivities.sleepActivity(5000, 123); + } + } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableArgumentsInActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableArgumentsInActivityTest.java index 1a84816fb9..8c74d8e1cc 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableArgumentsInActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableArgumentsInActivityTest.java @@ -19,6 +19,7 @@ package io.temporal.workflow.activityTests; +import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityOptions; import io.temporal.activity.LocalActivityOptions; import io.temporal.common.RetryOptions; @@ -26,7 +27,6 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.ActivityStub; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; @@ -36,8 +36,8 @@ public class NonSerializableArgumentsInActivityTest { - private final WorkflowTest.NonDeserializableExceptionActivityImpl activitiesImpl = - new WorkflowTest.NonDeserializableExceptionActivityImpl(); + private final NonDeserializableExceptionActivityImpl activitiesImpl = + new NonDeserializableExceptionActivityImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = @@ -56,6 +56,11 @@ public void testNonSerializableArgumentsInActivity() { "ApplicationFailure-io.temporal.common.converter.DataConverterException", result); } + @ActivityInterface + public interface NonDeserializableArgumentsActivity { + void execute(int arg); + } + public static class TestNonSerializableArgumentsInActivityWorkflow implements TestWorkflows.TestWorkflow1 { @@ -89,7 +94,7 @@ public String execute(String taskQueue) { } public class NonDeserializableExceptionActivityImpl - implements WorkflowTest.NonDeserializableArgumentsActivity { + implements NonDeserializableArgumentsActivity { @Override public void execute(int arg) {} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java index 78d2ee06ab..510116e607 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java @@ -19,6 +19,7 @@ package io.temporal.workflow.activityTests; +import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityOptions; import io.temporal.failure.ActivityFailure; import io.temporal.workflow.Workflow; @@ -32,8 +33,8 @@ public class NonSerializableExceptionInActivityWorkflowTest { - private final WorkflowTest.NonSerializableExceptionActivityImpl activitiesImpl = - new WorkflowTest.NonSerializableExceptionActivityImpl(); + private final NonSerializableExceptionActivityImpl activitiesImpl = + new NonSerializableExceptionActivityImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = @@ -51,14 +52,28 @@ public void testNonSerializableExceptionInActivity() { Assert.assertTrue(result.contains("NonSerializableException")); } + @ActivityInterface + public interface NonSerializableExceptionActivity { + void execute(); + } + + public static class NonSerializableExceptionActivityImpl + implements NonSerializableExceptionActivity { + + @Override + public void execute() { + throw new WorkflowTest.NonSerializableException(); + } + } + public static class TestNonSerializableExceptionInActivityWorkflow implements TestWorkflows.TestWorkflow1 { @Override public String execute(String taskQueue) { - WorkflowTest.NonSerializableExceptionActivity activity = + NonSerializableExceptionActivity activity = Workflow.newActivityStub( - WorkflowTest.NonSerializableExceptionActivity.class, + NonSerializableExceptionActivity.class, ActivityOptions.newBuilder() .setScheduleToCloseTimeout(Duration.ofSeconds(5)) .build()); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java index bdc560316e..e91f9fac37 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java @@ -19,12 +19,11 @@ package io.temporal.workflow.activityTests; -import io.temporal.client.*; +import io.temporal.client.WorkflowOptions; import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.Async; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; @@ -70,11 +69,11 @@ public void testParallelLocalActivities() { List expected = new ArrayList(); expected.add("interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP); expected.add("newThread workflow-method"); - for (int i = 0; i < WorkflowTest.TestParallelLocalActivitiesWorkflowImpl.COUNT; i++) { + for (int i = 0; i < TestParallelLocalActivitiesWorkflowImpl.COUNT; i++) { expected.add("executeLocalActivity SleepActivity"); expected.add("currentTimeMillis"); } - for (int i = 0; i < WorkflowTest.TestParallelLocalActivitiesWorkflowImpl.COUNT; i++) { + for (int i = 0; i < TestParallelLocalActivitiesWorkflowImpl.COUNT; i++) { expected.add("local activity SleepActivity"); } testWorkflowRule diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java index 765128cb2c..3269fe9c8f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java @@ -22,7 +22,6 @@ import static io.temporal.workflow.WorkflowTest.lastCompletionResult; import static io.temporal.workflow.shared.TestOptions.newWorkflowOptionsWithTimeouts; import static org.junit.Assert.*; -import static org.junit.Assert.assertTrue; import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowStub; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java index 33f003a470..5807e166ae 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java @@ -22,6 +22,8 @@ import io.temporal.failure.ChildWorkflowFailure; import io.temporal.worker.WorkflowImplementationOptions; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; @@ -55,8 +57,15 @@ public void testNonSerializableExceptionInChildWorkflow() { Assert.assertTrue(result.contains("NonSerializableException")); } + @WorkflowInterface + public interface NonSerializableExceptionChildWorkflow { + + @WorkflowMethod + String execute(String taskQueue); + } + public static class NonSerializableExceptionChildWorkflowImpl - implements WorkflowTest.NonSerializableExceptionChildWorkflow { + implements NonSerializableExceptionChildWorkflow { @Override public String execute(String taskQueue) { @@ -69,8 +78,8 @@ public static class TestNonSerializableExceptionInChildWorkflow @Override public String execute(String taskQueue) { - WorkflowTest.NonSerializableExceptionChildWorkflow child = - Workflow.newChildWorkflowStub(WorkflowTest.NonSerializableExceptionChildWorkflow.class); + NonSerializableExceptionChildWorkflow child = + Workflow.newChildWorkflowStub(NonSerializableExceptionChildWorkflow.class); try { child.execute(taskQueue); } catch (ChildWorkflowFailure e) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java index f33b8a25de..dd875be64b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java @@ -19,7 +19,11 @@ package io.temporal.workflow.childWorkflowTests; -import io.temporal.workflow.WorkflowTest; +import static org.junit.Assert.assertEquals; + +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.ChildWorkflowStub; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; @@ -37,7 +41,7 @@ public class UntypedChildStubWorkflowTest { public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( - WorkflowTest.TestUntypedChildStubWorkflow.class, + TestUntypedChildStubWorkflow.class, TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) .setActivityImplementations(activitiesImpl) .build(); @@ -48,4 +52,57 @@ public void testUntypedChildStubWorkflow() { testWorkflowRule.newWorkflowStub200sTimeoutOptions(TestWorkflows.TestWorkflow1.class); Assert.assertEquals(null, client.execute(testWorkflowRule.getTaskQueue())); } + + public static class TestUntypedChildStubWorkflow implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + ChildWorkflowOptions workflowOptions = + ChildWorkflowOptions.newBuilder().setTaskQueue(taskQueue).build(); + ChildWorkflowStub stubF = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc", workflowOptions); + assertEquals("func", stubF.execute(String.class)); + // Workflow type overridden through the @WorkflowMethod.name + ChildWorkflowStub stubF1 = Workflow.newUntypedChildWorkflowStub("func1", workflowOptions); + assertEquals("1", stubF1.execute(String.class, "1")); + ChildWorkflowStub stubF2 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc2", workflowOptions); + assertEquals("12", stubF2.execute(String.class, "1", 2)); + ChildWorkflowStub stubF3 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc3", workflowOptions); + assertEquals("123", stubF3.execute(String.class, "1", 2, 3)); + ChildWorkflowStub stubF4 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc4", workflowOptions); + assertEquals("1234", stubF4.execute(String.class, "1", 2, 3, 4)); + ChildWorkflowStub stubF5 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc5", workflowOptions); + assertEquals("12345", stubF5.execute(String.class, "1", 2, 3, 4, 5)); + ChildWorkflowStub stubF6 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsFunc6", workflowOptions); + assertEquals("123456", stubF6.execute(String.class, "1", 2, 3, 4, 5, 6)); + + ChildWorkflowStub stubP = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc", workflowOptions); + stubP.execute(Void.class); + ChildWorkflowStub stubP1 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc1", workflowOptions); + stubP1.execute(Void.class, "1"); + ChildWorkflowStub stubP2 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc2", workflowOptions); + stubP2.execute(Void.class, "1", 2); + ChildWorkflowStub stubP3 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc3", workflowOptions); + stubP3.execute(Void.class, "1", 2, 3); + ChildWorkflowStub stubP4 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc4", workflowOptions); + stubP4.execute(Void.class, "1", 2, 3, 4); + ChildWorkflowStub stubP5 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc5", workflowOptions); + stubP5.execute(Void.class, "1", 2, 3, 4, 5); + ChildWorkflowStub stubP6 = + Workflow.newUntypedChildWorkflowStub("TestMultiargsWorkflowsProc6", workflowOptions); + stubP6.execute(Void.class, "1", 2, 3, 4, 5, 6); + return null; + } + } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestMultiargdsWorkflowFunctions.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestMultiargdsWorkflowFunctions.java index 669b1bfa68..5c1d53a768 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestMultiargdsWorkflowFunctions.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestMultiargdsWorkflowFunctions.java @@ -19,9 +19,9 @@ package io.temporal.workflow.shared; +import io.temporal.workflow.QueryMethod; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; -import io.temporal.workflow.WorkflowTest; public class TestMultiargdsWorkflowFunctions { @@ -74,50 +74,56 @@ public interface TestMultiargsWorkflowsFunc6 { String func6(String a1, int a2, int a3, int a4, int a5, int a6); } + public interface ProcInvocationQueryable { + + @QueryMethod(name = "getTrace") + String query(); + } + @WorkflowInterface - public interface TestMultiargsWorkflowsProc extends WorkflowTest.ProcInvocationQueryable { + public interface TestMultiargsWorkflowsProc extends ProcInvocationQueryable { @WorkflowMethod void proc(); } @WorkflowInterface - public interface TestMultiargsWorkflowsProc1 extends WorkflowTest.ProcInvocationQueryable { + public interface TestMultiargsWorkflowsProc1 extends ProcInvocationQueryable { @WorkflowMethod void proc1(String input); } @WorkflowInterface - public interface TestMultiargsWorkflowsProc2 extends WorkflowTest.ProcInvocationQueryable { + public interface TestMultiargsWorkflowsProc2 extends ProcInvocationQueryable { @WorkflowMethod void proc2(String a1, int a2); } @WorkflowInterface - public interface TestMultiargsWorkflowsProc3 extends WorkflowTest.ProcInvocationQueryable { + public interface TestMultiargsWorkflowsProc3 extends ProcInvocationQueryable { @WorkflowMethod void proc3(String a1, int a2, int a3); } @WorkflowInterface - public interface TestMultiargsWorkflowsProc4 extends WorkflowTest.ProcInvocationQueryable { + public interface TestMultiargsWorkflowsProc4 extends ProcInvocationQueryable { @WorkflowMethod void proc4(String a1, int a2, int a3, int a4); } @WorkflowInterface - public interface TestMultiargsWorkflowsProc5 extends WorkflowTest.ProcInvocationQueryable { + public interface TestMultiargsWorkflowsProc5 extends ProcInvocationQueryable { @WorkflowMethod void proc5(String a1, int a2, int a3, int a4, int a5); } @WorkflowInterface - public interface TestMultiargsWorkflowsProc6 extends WorkflowTest.ProcInvocationQueryable { + public interface TestMultiargsWorkflowsProc6 extends ProcInvocationQueryable { @WorkflowMethod void proc6(String a1, int a2, int a3, int a4, int a5, int a6); From 91f8ea082c8b0e3da657052380ba056be0ab5e64 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Thu, 18 Mar 2021 15:27:01 -0700 Subject: [PATCH 06/21] These tests fail at the moment. Pushing to PR to get hints --- ...inaryChecksumSetWhenTaskCompletedTest.java | 97 +++++++++++++ .../temporal/workflow/ContinueAsNewTest.java | 108 ++++++++++++++ .../workflow/HeartbeatTimeoutDetailsTest.java | 87 +++++++++++ ...nisticWorkflowPolicyBlockWorkflowTest.java | 76 ++++++++++ ...inisticWorkflowPolicyFailWorkflowTest.java | 73 ++++++++++ .../java/io/temporal/workflow/SyncTest.java | 137 ++++++++++++++++++ .../GetVersionWithoutCommandEventTest.java | 95 ++++++++++++ 7 files changed, 673 insertions(+) create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/HeartbeatTimeoutDetailsTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java new file mode 100644 index 0000000000..dca9a2ffba --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java @@ -0,0 +1,97 @@ +/* + * 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.HistoryEvent; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowStub; +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 org.junit.Rule; +import org.junit.Test; + +public class BinaryChecksumSetWhenTaskCompletedTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(SimpleTestWorkflow.class) + .setActivityImplementations(activitiesImpl) + .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); + GetWorkflowExecutionHistoryRequest request = + GetWorkflowExecutionHistoryRequest.newBuilder() + .setNamespace(SDKTestWorkflowRule.NAMESPACE) + .setExecution(execution) + .build(); + GetWorkflowExecutionHistoryResponse response = + testWorkflowRule + .getTestEnvironment() + .getWorkflowService() + .blockingStub() + .getWorkflowExecutionHistory(request); + + boolean foundCompletedTask = false; + for (HistoryEvent event : response.getHistory().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"; + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java new file mode 100644 index 0000000000..396c915b6f --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java @@ -0,0 +1,108 @@ +/* + * 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 io.temporal.workflow.shared.TestActivities; +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class ContinueAsNewTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestContinueAsNewImpl.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .setDoNotStart(true) + .build(); + + @Test + public void testContinueAsNew() { + String continuedTaskQueue = testWorkflowRule.getTaskQueue() + "_continued"; + testWorkflowRule.getTestEnvironment().newWorker(continuedTaskQueue); + testWorkflowRule.getTestEnvironment().start(); + + TestContinueAsNew client = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestContinueAsNew.class); + int result = client.execute(4, continuedTaskQueue); + 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 memo = new HashMap<>(); + memo.put("myKey", "MyValue"); + Map 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"); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/HeartbeatTimeoutDetailsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/HeartbeatTimeoutDetailsTest.java new file mode 100644 index 0000000000..85da1f6e4c --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/HeartbeatTimeoutDetailsTest.java @@ -0,0 +1,87 @@ +/* + * 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.enums.v1.TimeoutType; +import io.temporal.failure.ActivityFailure; +import io.temporal.failure.TimeoutFailure; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HeartbeatTimeoutDetailsTest { + + private static final Logger log = LoggerFactory.getLogger(HeartbeatTimeoutDetailsTest.class); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestHeartbeatTimeoutDetails.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testHeartbeatTimeoutDetails() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("heartbeatValue", result); + } + + public static class TestHeartbeatTimeoutDetails implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + ActivityOptions options = + ActivityOptions.newBuilder() + .setTaskQueue(taskQueue) + .setHeartbeatTimeout(Duration.ofSeconds(1)) // short heartbeat timeout; + .setScheduleToCloseTimeout(Duration.ofSeconds(5)) + .build(); + + TestActivities activities = Workflow.newActivityStub(TestActivities.class, options); + try { + // false for second argument means to heartbeat once to set details and then stop. + activities.activityWithDelay(5000, false); + } catch (ActivityFailure e) { + TimeoutFailure te = (TimeoutFailure) e.getCause(); + log.info("TestHeartbeatTimeoutDetails expected timeout", e); + assertEquals(TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_CLOSE, te.getTimeoutType()); + assertTrue(te.getCause() instanceof TimeoutFailure); + assertEquals( + TimeoutType.TIMEOUT_TYPE_HEARTBEAT, ((TimeoutFailure) te.getCause()).getTimeoutType()); + return (te.getLastHeartbeatDetails().get(String.class)); + } + throw new RuntimeException("unreachable"); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java new file mode 100644 index 0000000000..ba7fb3dee8 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java @@ -0,0 +1,76 @@ +/* + * 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.client.WorkflowFailedException; +import io.temporal.client.WorkflowOptions; +import io.temporal.failure.TimeoutFailure; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import java.lang.management.ManagementFactory; +import java.lang.management.ThreadInfo; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class NonDeterministicWorkflowPolicyBlockWorkflowTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(WorkflowTest.DeterminismFailingWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testNonDeterministicWorkflowPolicyBlockWorkflow() { + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofSeconds(5)) + .setWorkflowTaskTimeout(Duration.ofSeconds(1)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + WorkflowTest.DeterminismFailingWorkflow workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(WorkflowTest.DeterminismFailingWorkflow.class, options); + try { + workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.fail("unreachable"); + } catch (WorkflowFailedException e) { + // expected to timeout as workflow is going get blocked. + Assert.assertTrue(e.getCause() instanceof TimeoutFailure); + } + + int workflowRootThreads = 0; + ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false); + for (ThreadInfo thread : threads) { + if (thread.getThreadName().contains("workflow-root")) { + workflowRootThreads++; + } + } + + Assert.assertTrue("workflow threads might leak", workflowRootThreads < 10); + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java new file mode 100644 index 0000000000..475c900c74 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java @@ -0,0 +1,73 @@ +/* + * 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.client.WorkflowFailedException; +import io.temporal.client.WorkflowOptions; +import io.temporal.failure.ApplicationFailure; +import io.temporal.internal.replay.InternalWorkflowTaskException; +import io.temporal.worker.WorkflowImplementationOptions; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import java.time.Duration; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class NonDeterministicWorkflowPolicyFailWorkflowTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes( + WorkflowImplementationOptions.newBuilder() + .setFailWorkflowExceptionTypes(Throwable.class) + .build(), + WorkflowTest.DeterminismFailingWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .build(); + + @Test + public void testNonDeterministicWorkflowPolicyFailWorkflow() { + WorkflowOptions options = + WorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofSeconds(1)) + .setWorkflowTaskTimeout(Duration.ofSeconds(1)) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build(); + WorkflowTest.DeterminismFailingWorkflow workflowStub = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub(WorkflowTest.DeterminismFailingWorkflow.class, options); + try { + workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.fail("unreachable"); + } catch (WorkflowFailedException e) { + // expected to fail on non deterministic error + Assert.assertTrue(e.getCause() instanceof ApplicationFailure); + Assert.assertEquals( + InternalWorkflowTaskException.class.getName(), + ((ApplicationFailure) e.getCause()).getType()); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java new file mode 100644 index 0000000000..213dafa9ff --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java @@ -0,0 +1,137 @@ +/* + * 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 io.temporal.client.WorkflowClient.QUERY_TYPE_STACK_TRACE; +import static org.junit.Assert.*; + +import io.temporal.api.common.v1.WorkflowExecution; +import io.temporal.client.WorkflowFailedException; +import io.temporal.client.WorkflowStub; +import io.temporal.failure.CanceledFailure; +import io.temporal.failure.TerminatedFailure; +import io.temporal.testing.TracingWorkerInterceptor; +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 SyncTest { + + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestSyncWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .setWorkerInterceptors( + new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) + .build(); + + @Test + public void testSync() { + TestWorkflows.TestWorkflow1 workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); + String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); + Assert.assertEquals("activity10", result); + testWorkflowRule + .getInterceptor(TracingWorkerInterceptor.class) + .setExpected( + "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "newThread workflow-method", + "newThread null", + "sleep PT2S", + "executeActivity ActivityWithDelay", + "activity ActivityWithDelay", + "executeActivity Activity2", + "activity Activity2"); + } + + @Test + public void testSyncUntypedAndStackTrace() { + WorkflowStub workflowStub = + testWorkflowRule.newUntypedWorkflowStubTimeoutOptions("TestWorkflow1"); + WorkflowExecution execution = workflowStub.start(testWorkflowRule.getTaskQueue()); + testWorkflowRule.sleep(Duration.ofMillis(500)); + String stackTrace = workflowStub.query(QUERY_TYPE_STACK_TRACE, String.class); + assertTrue(stackTrace, stackTrace.contains("WorkflowTest$TestSyncWorkflowImpl.execute")); + assertTrue(stackTrace, stackTrace.contains("activityWithDelay")); + // Test stub created from workflow execution. + workflowStub = + testWorkflowRule + .getWorkflowClient() + .newUntypedWorkflowStub(execution, workflowStub.getWorkflowType()); + stackTrace = workflowStub.query(QUERY_TYPE_STACK_TRACE, String.class); + assertTrue(stackTrace, stackTrace.contains("WorkflowTest$TestSyncWorkflowImpl.execute")); + assertTrue(stackTrace, stackTrace.contains("activityWithDelay")); + String result = workflowStub.getResult(String.class); + assertEquals("activity10", result); + } + + @Test + public void testWorkflowCancellation() { + WorkflowStub client = testWorkflowRule.newUntypedWorkflowStubTimeoutOptions("TestWorkflow1"); + client.start(testWorkflowRule.getTaskQueue()); + client.cancel(); + try { + client.getResult(String.class); + fail("unreachable"); + } catch (WorkflowFailedException e) { + assertTrue(e.getCause() instanceof CanceledFailure); + } + } + + @Test + public void testWorkflowTermination() throws InterruptedException { + WorkflowStub client = testWorkflowRule.newUntypedWorkflowStubTimeoutOptions("TestWorkflow1"); + client.start(testWorkflowRule.getTaskQueue()); + Thread.sleep(1000); + client.terminate("boo", "detail1", "detail2"); + try { + client.getResult(String.class); + fail("unreachable"); + } catch (WorkflowFailedException ignored) { + assertTrue(ignored.getCause() instanceof TerminatedFailure); + assertEquals("boo", ((TerminatedFailure) ignored.getCause()).getOriginalMessage()); + } + } + + public static class TestSyncWorkflowImpl implements TestWorkflows.TestWorkflow1 { + + @Override + public String execute(String taskQueue) { + TestActivities activities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + // Invoke synchronously in a separate thread for testing purposes only. + // In real workflows use + // Async.procedure(activities::activityWithDelay, 1000, true) + Promise a1 = Async.function(() -> activities.activityWithDelay(1000, true)); + Workflow.sleep(2000); + return activities.activity2(a1.get(), 10); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java new file mode 100644 index 0000000000..499db2b6eb --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java @@ -0,0 +1,95 @@ +/* + * 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.versionTests; + +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowStub; +import io.temporal.workflow.CompletablePromise; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import java.util.concurrent.CompletableFuture; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class GetVersionWithoutCommandEventTest { + + private static CompletableFuture executionStarted = new CompletableFuture<>(); + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(null); + + @Rule + public SDKTestWorkflowRule testWorkflowRule = + SDKTestWorkflowRule.newBuilder() + .setWorkflowTypes(TestGetVersionWithoutCommandEventWorkflowImpl.class) + .setActivityImplementations(activitiesImpl) + .setTestTimeoutSeconds(20) + .build(); + + @Test + public void testGetVersionWithoutCommandEvent() throws Exception { + executionStarted = new CompletableFuture(); + WorkflowTest.TestWorkflowSignaled workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.TestWorkflowSignaled.class); + WorkflowClient.start(workflowStub::execute); + executionStarted.get(); + workflowStub.signal1("test signal"); + String result = WorkflowStub.fromTyped(workflowStub).getResult(String.class); + Assert.assertEquals("result 1", result); + } + + public static class TestGetVersionWithoutCommandEventWorkflowImpl + implements WorkflowTest.TestWorkflowSignaled { + + CompletablePromise signalReceived = Workflow.newPromise(); + + @Override + public String execute() { + try { + if (!Workflow.isReplaying()) { + executionStarted.complete(true); + signalReceived.get(); + } else { + // Execute getVersion in replay mode. In this case we have no command event, only a + // signal. + int version = Workflow.getVersion("test_change", Workflow.DEFAULT_VERSION, 1); + if (version == Workflow.DEFAULT_VERSION) { + signalReceived.get(); + return "result 1"; + } else { + return "result 2"; + } + } + Workflow.sleep(1000); + } catch (Exception e) { + throw new RuntimeException("failed to get from signal"); + } + + throw new RuntimeException("unreachable"); + } + + @Override + public void signal1(String arg) { + signalReceived.complete(true); + } + } +} From 4d3c90cef717373f8d8b115713ac1581e394a7dd Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Sat, 27 Mar 2021 01:35:29 -0700 Subject: [PATCH 07/21] Fixed ContinueAsNewTest --- .../test/java/io/temporal/workflow/ContinueAsNewTest.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java index 396c915b6f..9af05ba002 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java @@ -42,18 +42,13 @@ public class ContinueAsNewTest { .setActivityImplementations(activitiesImpl) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) - .setDoNotStart(true) .build(); @Test public void testContinueAsNew() { - String continuedTaskQueue = testWorkflowRule.getTaskQueue() + "_continued"; - testWorkflowRule.getTestEnvironment().newWorker(continuedTaskQueue); - testWorkflowRule.getTestEnvironment().start(); - TestContinueAsNew client = testWorkflowRule.newWorkflowStubTimeoutOptions(TestContinueAsNew.class); - int result = client.execute(4, continuedTaskQueue); + int result = client.execute(4, testWorkflowRule.getTaskQueue()); Assert.assertEquals(111, result); testWorkflowRule .getInterceptor(TracingWorkerInterceptor.class) From 43115ed5c0ee9cb5a7f50bcfbdfd0f3f869b28e4 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Mon, 29 Mar 2021 12:58:58 -0700 Subject: [PATCH 08/21] Fixed testHeartbeatTimeoutDetails() --- .../src/test/java/io/temporal/workflow/AwaitTest.java | 2 +- .../workflow/BinaryChecksumSetWhenTaskCompletedTest.java | 2 +- .../java/io/temporal/workflow/ContinueAsNewNoArgsTest.java | 2 +- .../src/test/java/io/temporal/workflow/ContinueAsNewTest.java | 2 +- .../src/test/java/io/temporal/workflow/DetachedScopeTest.java | 2 +- .../java/io/temporal/workflow/ExceptionPropagationTest.java | 2 +- .../src/test/java/io/temporal/workflow/ExecuteTest.java | 2 +- .../io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java | 2 +- .../io/temporal/workflow/HeartbeatTimeoutDetailsTest.java | 4 +++- temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java | 2 +- .../test/java/io/temporal/workflow/MultipleTimersTest.java | 2 +- .../test/java/io/temporal/workflow/MutableSideEffectTest.java | 2 +- .../test/java/io/temporal/workflow/NoQueryThreadLeakTest.java | 2 +- .../NonDeterministicWorkflowPolicyBlockWorkflowTest.java | 2 +- .../NonDeterministicWorkflowPolicyFailWorkflowTest.java | 2 +- .../java/io/temporal/workflow/ParentContinueAsNewTest.java | 2 +- .../test/java/io/temporal/workflow/PolymorphicStartTest.java | 2 +- temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java | 2 +- .../test/java/io/temporal/workflow/SearchAttributesTest.java | 2 +- .../src/test/java/io/temporal/workflow/SideEffectTest.java | 2 +- .../src/test/java/io/temporal/workflow/StartTest.java | 2 +- temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java | 2 +- .../java/io/temporal/workflow/TimerCallbackBlockedTest.java | 2 +- .../src/test/java/io/temporal/workflow/TimerTest.java | 2 +- .../src/test/java/io/temporal/workflow/UUIDAndRandomTest.java | 2 +- .../java/io/temporal/workflow/UpsertSearchAttributesTest.java | 2 +- .../workflow/WorkflowCancellationScopePromiseTest.java | 2 +- .../workflow/WorkflowFailureNonRetryableFlagTest.java | 2 +- .../java/io/temporal/workflow/WorkflowIdResuePolicyTest.java | 2 +- .../test/java/io/temporal/workflow/WorkflowLocalsTest.java | 2 +- .../workflow/WorkflowRetryDoNotRetryExceptionTest.java | 2 +- .../src/test/java/io/temporal/workflow/WorkflowRetryTest.java | 2 +- .../WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java | 2 +- .../io/temporal/workflow/WorkflowTaskFailureBackoffTest.java | 2 +- .../java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java | 2 +- .../io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java | 2 +- .../io/temporal/workflow/WorkflowWithCronScheduleTest.java | 2 +- .../WorkflowsWithFailedPromisesCanBeCanceledTest.java | 2 +- .../workflow/activityTests/AbandonOnCancelActivityTest.java | 2 +- .../ActivityApplicationFailureNonRetryableTest.java | 2 +- .../activityTests/ActivityApplicationFailureRetryTest.java | 2 +- .../ActivityApplicationNoSpecifiedRetryTest.java | 2 +- .../activityTests/ActivityApplicationOptOutOfRetryTest.java | 2 +- .../workflow/activityTests/ActivityRetryAnnotatedTest.java | 2 +- .../workflow/activityTests/ActivityRetryOnTimeoutTest.java | 2 +- .../activityTests/ActivityRetryOptionsChangeTest.java | 2 +- .../activityTests/ActivityRetryWithExpirationTest.java | 2 +- .../activityTests/ActivityRetryWithMaxAttemptsTest.java | 2 +- .../activityTests/AsyncActivityRetryOptionsChangeTest.java | 2 +- .../workflow/activityTests/AsyncActivityRetryTest.java | 2 +- .../io/temporal/workflow/activityTests/AsyncActivityTest.java | 2 +- .../workflow/activityTests/AsyncRetryOptionsChangeTest.java | 2 +- .../io/temporal/workflow/activityTests/AsyncRetryTest.java | 2 +- .../workflow/activityTests/AsyncUntyped2ActivityTest.java | 2 +- .../workflow/activityTests/AsyncUntypedActivityTest.java | 2 +- .../LocalActivitiesWorkflowTaskHeartbeatTest.java | 2 +- .../workflow/activityTests/LocalActivityAndQueryTest.java | 2 +- .../workflow/activityTests/LocalActivityRetryTest.java | 2 +- .../io/temporal/workflow/activityTests/LocalActivityTest.java | 2 +- .../LongLocalActivityWorkflowTaskHeartbeatFailureTest.java | 2 +- .../LongLocalActivityWorkflowTaskHeartbeatTest.java | 2 +- .../workflow/activityTests/ParallelLocalActivitiesTest.java | 2 +- .../ParallelLocalActivityExecutionWorkflowTest.java | 2 +- .../workflow/activityTests/TryCancelActivityTest.java | 2 +- .../workflow/activityTests/UntypedActivityRetryTest.java | 2 +- .../childWorkflowTests/ChildAsyncLambdaWorkflowTest.java | 2 +- .../workflow/childWorkflowTests/ChildAsyncWorkflowTest.java | 2 +- .../childWorkflowTests/ChildWorkflowCancellationTest.java | 2 +- .../ChildWorkflowExecutionPromiseHandlerTest.java | 2 +- .../workflow/childWorkflowTests/ChildWorkflowTest.java | 2 +- .../workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java | 2 +- .../childWorkflowTests/ChildWorkflowWithCronScheduleTest.java | 2 +- .../temporal/workflow/childWorkflowTests/NamedChildTest.java | 2 +- .../NonSerializableExceptionInChildWorkflowTest.java | 2 +- .../ParentWorkflowInfoInChildWorkflowsTest.java | 2 +- ...ChildWorkflowWithCancellationScopeAndCancelParentTest.java | 2 +- .../UntypedChildStubWorkflowAsyncInvokeTest.java | 2 +- .../childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java | 2 +- .../childWorkflowTests/UntypedChildStubWorkflowTest.java | 2 +- .../test/java/io/temporal/workflow/shared/TestActivities.java | 2 +- .../temporal/workflow/signalTests/ExceptionInSignalTest.java | 2 +- .../workflow/signalTests/SignalAndQueryInterfaceTest.java | 2 +- .../workflow/signalTests/SignalAndQueryListenerTest.java | 2 +- .../signalTests/SignalDuringLastWorkflowTaskTest.java | 2 +- .../signalTests/SignalExternalWorkflowFailureTest.java | 2 +- .../SignalExternalWorkflowImmediateCancellationTest.java | 2 +- .../workflow/signalTests/SignalExternalWorkflowTest.java | 2 +- .../workflow/signalTests/SignalOrderingWorkflowTest.java | 2 +- .../java/io/temporal/workflow/signalTests/SignalTest.java | 2 +- .../signalTests/UntypedSignalExternalWorkflowTest.java | 2 +- .../workflow/versionTests/GetVersionAddNewBeforeTest.java | 2 +- .../workflow/versionTests/GetVersionRemovedBeforeTest.java | 2 +- .../workflow/versionTests/GetVersionRemovedInReplayTest.java | 2 +- .../workflow/versionTests/GetVersionSameIdOnReplayTest.java | 2 +- .../temporal/workflow/versionTests/GetVersionSameIdTest.java | 2 +- .../io/temporal/workflow/versionTests/GetVersionTest.java | 2 +- .../versionTests/GetVersionWithoutCommandEventTest.java | 2 +- .../workflow/versionTests/GetVersionWorkflowRemoveTest.java | 2 +- .../versionTests/GetVersionWorkflowReplaceCompletelyTest.java | 2 +- .../GetVersionWorkflowReplaceGetVersionIdTest.java | 2 +- .../workflow/versionTests/VersionNotSupportedTest.java | 2 +- 101 files changed, 103 insertions(+), 101 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AwaitTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/AwaitTest.java index 3096f4cfd5..ad61270f61 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AwaitTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/AwaitTest.java @@ -32,7 +32,7 @@ public class AwaitTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java index dca9a2ffba..73d026675a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java @@ -40,7 +40,7 @@ public class BinaryChecksumSetWhenTaskCompletedTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java index 4c4b2048fa..c04f3c3d6f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java @@ -29,7 +29,7 @@ public class ContinueAsNewNoArgsTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java index 9af05ba002..82f95bbcca 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java @@ -33,7 +33,7 @@ public class ContinueAsNewTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java index d68806a62f..76f4b83ac4 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java @@ -37,7 +37,7 @@ public class DetachedScopeTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java index 3ca66f22a1..747aa779d9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java @@ -41,7 +41,7 @@ public class ExceptionPropagationTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java index 769065949b..68fec1e945 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java @@ -31,7 +31,7 @@ public class ExecuteTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java index cd85c06adc..06d8d666f4 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java @@ -30,7 +30,7 @@ public class GetAttemptFromWorkflowInfoTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/HeartbeatTimeoutDetailsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/HeartbeatTimeoutDetailsTest.java index 85da1f6e4c..100193e5db 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/HeartbeatTimeoutDetailsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/HeartbeatTimeoutDetailsTest.java @@ -40,7 +40,7 @@ public class HeartbeatTimeoutDetailsTest { private static final Logger log = LoggerFactory.getLogger(HeartbeatTimeoutDetailsTest.class); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = @@ -51,6 +51,8 @@ public class HeartbeatTimeoutDetailsTest { @Test public void testHeartbeatTimeoutDetails() { + activitiesImpl.setCompletionClient( + testWorkflowRule.getWorkflowClient().newActivityCompletionClient()); TestWorkflows.TestWorkflow1 workflowStub = testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java index 3c1fe83d4f..077abf9fa1 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java @@ -43,7 +43,7 @@ public class MemoTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java index 2fa1f1846d..99089738f2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java @@ -29,7 +29,7 @@ public class MultipleTimersTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java index 6ae3960e11..4d66340849 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java @@ -33,7 +33,7 @@ public class MutableSideEffectTest { private static final Map> mutableSideEffectValue = Collections.synchronizedMap(new HashMap<>()); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java index e618014eca..8eab35ac06 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java @@ -32,7 +32,7 @@ public class NoQueryThreadLeakTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java index ba7fb3dee8..82939b1413 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java @@ -34,7 +34,7 @@ public class NonDeterministicWorkflowPolicyBlockWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java index 475c900c74..effbc43397 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java @@ -34,7 +34,7 @@ public class NonDeterministicWorkflowPolicyFailWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java index 1288c9b9bc..c59cb0f286 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java @@ -32,7 +32,7 @@ public class ParentContinueAsNewTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java index f109e40aa3..5bbc234d27 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java @@ -28,7 +28,7 @@ public class PolymorphicStartTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java index 843f0745f8..5cbb9d1c62 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java @@ -32,7 +32,7 @@ public class SagaTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java index 2da852cb25..5a34570720 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java @@ -44,7 +44,7 @@ public class SearchAttributesTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java index b6bf1a6f98..3101a76652 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java @@ -34,7 +34,7 @@ public class SideEffectTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java index 96f64752fd..984ec6df48 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java @@ -37,7 +37,7 @@ public class StartTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java index 213dafa9ff..632218843a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java @@ -40,7 +40,7 @@ public class SyncTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java index 9363edbfa8..6451b9a6ba 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java @@ -31,7 +31,7 @@ public class TimerCallbackBlockedTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java index 838ecc4d25..4abc008cae 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java @@ -36,7 +36,7 @@ public class TimerTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java index 880e0591bb..1b2345bfda 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java @@ -34,7 +34,7 @@ public class UUIDAndRandomTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java index ae8decfaba..7017938bfa 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java @@ -43,7 +43,7 @@ public class UpsertSearchAttributesTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java index 26167a7334..93b86db452 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java @@ -32,7 +32,7 @@ public class WorkflowCancellationScopePromiseTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java index 99f95fe46a..e8482258b3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java @@ -38,7 +38,7 @@ public class WorkflowFailureNonRetryableFlagTest { private static final Map retryCount = new ConcurrentHashMap<>(); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java index 060e3abc83..971f0b52b0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java @@ -33,7 +33,7 @@ public class WorkflowIdResuePolicyTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java index 43d1917078..54d0a35ca8 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java @@ -32,7 +32,7 @@ public class WorkflowLocalsTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java index 81118f38a3..cefda2668c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java @@ -38,7 +38,7 @@ public class WorkflowRetryDoNotRetryExceptionTest { private static final Map retryCount = new ConcurrentHashMap<>(); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java index e912e39b81..3525d7febd 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java @@ -40,7 +40,7 @@ public class WorkflowRetryTest { private static final Map retryCount = new ConcurrentHashMap<>(); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java index 48ec61f27f..e2098fc5cf 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java @@ -37,7 +37,7 @@ public class WorkflowRetryWithMethodRetryDoNotRetryExceptionTest { private static final Map retryCount = new ConcurrentHashMap<>(); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java index 93962d716a..cf60276579 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java @@ -37,7 +37,7 @@ public class WorkflowTaskFailureBackoffTest { private static int testWorkflowTaskFailureBackoffReplayCount; private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java index 8900a48388..2fca3fd20b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java @@ -37,7 +37,7 @@ public class WorkflowTaskNPEBackoffTest { private static int testWorkflowTaskFailureBackoffReplayCount; private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java index f18a3044fb..123d86cfda 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java @@ -35,7 +35,7 @@ public class WorkflowTaskTimeoutWorkflowTest { private static final Map retryCount = new ConcurrentHashMap<>(); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java index d89b51cb58..2f94b05bc9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java @@ -37,7 +37,7 @@ public class WorkflowWithCronScheduleTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java index 12b4cde813..583b5f00b9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java @@ -35,7 +35,7 @@ public class WorkflowsWithFailedPromisesCanBeCanceledTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java index 7454b730fd..003c075c83 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java @@ -43,7 +43,7 @@ public class AbandonOnCancelActivityTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureNonRetryableTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureNonRetryableTest.java index 01a67c9834..fa6793ca52 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureNonRetryableTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureNonRetryableTest.java @@ -38,7 +38,7 @@ public class ActivityApplicationFailureNonRetryableTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureRetryTest.java index a296f40ee0..e0ab46ff1e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationFailureRetryTest.java @@ -36,7 +36,7 @@ public class ActivityApplicationFailureRetryTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationNoSpecifiedRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationNoSpecifiedRetryTest.java index 15a4451101..4e8b3e0200 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationNoSpecifiedRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationNoSpecifiedRetryTest.java @@ -35,7 +35,7 @@ public class ActivityApplicationNoSpecifiedRetryTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationOptOutOfRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationOptOutOfRetryTest.java index cb4e4467ee..be29f4094e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationOptOutOfRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityApplicationOptOutOfRetryTest.java @@ -36,7 +36,7 @@ public class ActivityApplicationOptOutOfRetryTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryAnnotatedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryAnnotatedTest.java index 327b61af05..53e20e778a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryAnnotatedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryAnnotatedTest.java @@ -36,7 +36,7 @@ public class ActivityRetryAnnotatedTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOnTimeoutTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOnTimeoutTest.java index 7ecb9610f2..2729665024 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOnTimeoutTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOnTimeoutTest.java @@ -36,7 +36,7 @@ public class ActivityRetryOnTimeoutTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOptionsChangeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOptionsChangeTest.java index 8701895dfd..64a81731cf 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOptionsChangeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryOptionsChangeTest.java @@ -37,7 +37,7 @@ public class ActivityRetryOptionsChangeTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java index 02fce8c944..51310e27c2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithExpirationTest.java @@ -39,7 +39,7 @@ public class ActivityRetryWithExpirationTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithMaxAttemptsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithMaxAttemptsTest.java index 6ebb5fa6de..ce3be284fe 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithMaxAttemptsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRetryWithMaxAttemptsTest.java @@ -39,7 +39,7 @@ public class ActivityRetryWithMaxAttemptsTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryOptionsChangeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryOptionsChangeTest.java index 23ddc89784..783e62cca2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryOptionsChangeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryOptionsChangeTest.java @@ -38,7 +38,7 @@ public class AsyncActivityRetryOptionsChangeTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryTest.java index b2cd16038b..8efda50ca9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityRetryTest.java @@ -40,7 +40,7 @@ public class AsyncActivityRetryTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java index 586b64612f..e11654d1d6 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java @@ -37,7 +37,7 @@ public class AsyncActivityTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java index e63c03eebb..9af9d51d23 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java @@ -40,7 +40,7 @@ public class AsyncRetryOptionsChangeTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java index a07244dd3d..9cb79e1c08 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java @@ -39,7 +39,7 @@ public class AsyncRetryTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java index 85ee51d62a..d5f1b91565 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java @@ -35,7 +35,7 @@ public class AsyncUntyped2ActivityTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java index 62b81a28fd..f261694394 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java @@ -36,7 +36,7 @@ public class AsyncUntypedActivityTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java index 6aaee3b943..fbebbceaab 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java @@ -36,7 +36,7 @@ public class LocalActivitiesWorkflowTaskHeartbeatTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityAndQueryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityAndQueryTest.java index bd9f25f2b3..452689b632 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityAndQueryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityAndQueryTest.java @@ -42,7 +42,7 @@ public class LocalActivityAndQueryTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityRetryTest.java index 1945db1977..abaa77dd5b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityRetryTest.java @@ -36,7 +36,7 @@ public class LocalActivityRetryTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java index 1e930ff9da..7e3239c914 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java @@ -38,7 +38,7 @@ public class LocalActivityTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java index c4324e40a7..957a9ce726 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java @@ -33,7 +33,7 @@ public class LongLocalActivityWorkflowTaskHeartbeatFailureTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java index 0aa9a99d96..6d66276598 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java @@ -33,7 +33,7 @@ public class LongLocalActivityWorkflowTaskHeartbeatTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java index e91f9fac37..740612a698 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java @@ -39,7 +39,7 @@ public class ParallelLocalActivitiesTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java index cd492d8a8d..33308a23eb 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java @@ -37,7 +37,7 @@ public class ParallelLocalActivityExecutionWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java index f37a4877fe..907421d5f6 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java @@ -38,7 +38,7 @@ public class TryCancelActivityTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java index 197e147a32..ab6bfb8e29 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java @@ -38,7 +38,7 @@ public class UntypedActivityRetryTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java index 280fae9f3c..d60eb64ca9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java @@ -35,7 +35,7 @@ public class ChildAsyncLambdaWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java index 9907c03fcf..1ea4baec6f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java @@ -35,7 +35,7 @@ public class ChildAsyncWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java index 212ea54c7b..b2ab6fcd18 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java @@ -40,7 +40,7 @@ public class ChildWorkflowCancellationTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java index 6ddc2818a6..b5ae65ff7a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java @@ -35,7 +35,7 @@ public class ChildWorkflowExecutionPromiseHandlerTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java index 1ae5b9d459..8e9b69c42e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java @@ -33,7 +33,7 @@ public class ChildWorkflowTest { private static String child2Id; private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java index 2a47a6b441..4d316585f2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java @@ -35,7 +35,7 @@ public class ChildWorkflowTimeoutTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java index 3269fe9c8f..07fc5f890f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java @@ -40,7 +40,7 @@ public class ChildWorkflowWithCronScheduleTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java index 307eed51d8..cb933aab87 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java @@ -35,7 +35,7 @@ public class NamedChildTest { private static final String childReexecuteId = UUID.randomUUID().toString(); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java index 5807e166ae..a41363234b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java @@ -35,7 +35,7 @@ public class NonSerializableExceptionInChildWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java index e73de461a7..ee7f47160d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java @@ -35,7 +35,7 @@ public class ParentWorkflowInfoInChildWorkflowsTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java index 0426465e13..c3b2db48f6 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java @@ -36,7 +36,7 @@ public class StartChildWorkflowWithCancellationScopeAndCancelParentTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java index 2d253e694a..74dd8d6d19 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java @@ -34,7 +34,7 @@ public class UntypedChildStubWorkflowAsyncInvokeTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java index 1ab0076214..4c92abc2e0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java @@ -33,7 +33,7 @@ public class UntypedChildStubWorkflowAsyncTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java index dd875be64b..330391f061 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java @@ -35,7 +35,7 @@ public class UntypedChildStubWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestActivities.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestActivities.java index 4471b068bf..5255950de8 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestActivities.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestActivities.java @@ -101,7 +101,7 @@ class TestActivitiesImpl implements TestActivities { public ActivityCompletionClient completionClient; int lastAttempt; - public TestActivitiesImpl(ActivityCompletionClient completionClient) { + public void setCompletionClient(ActivityCompletionClient completionClient) { this.completionClient = completionClient; } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java index 0d8e968089..860ad0a849 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java @@ -38,7 +38,7 @@ public class ExceptionInSignalTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java index fab92dfb70..e61f6a1068 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java @@ -34,7 +34,7 @@ public class SignalAndQueryInterfaceTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java index e5a456e399..6020da12da 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java @@ -36,7 +36,7 @@ public class SignalAndQueryListenerTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java index ba566e1e90..4ab747a182 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java @@ -43,7 +43,7 @@ public class SignalDuringLastWorkflowTaskTest { private static final AtomicInteger workflowTaskCount = new AtomicInteger(); private static CompletableFuture sendSignal; private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java index b641c601a8..67da44b0de 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java @@ -36,7 +36,7 @@ public class SignalExternalWorkflowFailureTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java index 4dfa20835f..0ab542c37e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java @@ -34,7 +34,7 @@ public class SignalExternalWorkflowImmediateCancellationTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java index ec09bdf791..2c21d4ff50 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java @@ -33,7 +33,7 @@ public class SignalExternalWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java index 70f392c988..a2609e6f91 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java @@ -39,7 +39,7 @@ public class SignalOrderingWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java index b996391a70..691bcd037e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java @@ -48,7 +48,7 @@ public class SignalTest { private static final Logger log = LoggerFactory.getLogger(SignalTest.class); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java index 4b5326c884..113340cb37 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java @@ -30,7 +30,7 @@ public class UntypedSignalExternalWorkflowTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java index 5b8b9aec6d..2fea503170 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java @@ -33,7 +33,7 @@ public class GetVersionAddNewBeforeTest { private static final Logger log = LoggerFactory.getLogger(GetVersionAddNewBeforeTest.class); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java index ef504cd803..9cd40f379d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java @@ -34,7 +34,7 @@ public class GetVersionRemovedBeforeTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java index 994b57de7a..0f0115d641 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java @@ -34,7 +34,7 @@ public class GetVersionRemovedInReplayTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java index 6e4d00caa8..b0275ed926 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java @@ -40,7 +40,7 @@ public class GetVersionSameIdOnReplayTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java index d6390b30f7..1b60768006 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java @@ -33,7 +33,7 @@ public class GetVersionSameIdTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java index 280f90b122..e1b0b10548 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java @@ -35,7 +35,7 @@ public class GetVersionTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java index 499db2b6eb..05c9df4c0d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java @@ -35,7 +35,7 @@ public class GetVersionWithoutCommandEventTest { private static CompletableFuture executionStarted = new CompletableFuture<>(); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java index 3669cc5763..f46bc9e621 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java @@ -33,7 +33,7 @@ public class GetVersionWorkflowRemoveTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java index 0a3d17a102..86e405c911 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java @@ -34,7 +34,7 @@ public class GetVersionWorkflowReplaceCompletelyTest { private static final Logger log = LoggerFactory.getLogger(GetVersionWorkflowReplaceCompletelyTest.class); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java index 5feaae3451..13d981a59b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java @@ -34,7 +34,7 @@ public class GetVersionWorkflowReplaceGetVersionIdTest { private static final Logger log = LoggerFactory.getLogger(GetVersionWorkflowReplaceGetVersionIdTest.class); private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java index 644e774da7..86eb688076 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java @@ -33,7 +33,7 @@ public class VersionNotSupportedTest { private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(null); + new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = From 5d8b25f416c9a5ec813642de2bea398515773d83 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Mon, 29 Mar 2021 14:26:51 -0700 Subject: [PATCH 09/21] Fixed a few more tests that needed replay. --- .../BinaryChecksumSetWhenTaskCompletedTest.java | 6 ++++++ ...erministicWorkflowPolicyBlockWorkflowTest.java | 5 +++++ ...terministicWorkflowPolicyFailWorkflowTest.java | 7 ++++++- .../workflow/shared/SDKTestWorkflowRule.java | 6 ++++++ .../versionTests/GetVersionAddNewBeforeTest.java | 6 ++++++ .../versionTests/GetVersionRemovedBeforeTest.java | 6 ++++++ .../GetVersionRemovedInReplayTest.java | 6 ++++++ .../GetVersionSameIdOnReplayTest.java | 5 +++++ .../versionTests/GetVersionSameIdTest.java | 5 +++++ .../workflow/versionTests/GetVersionTest.java | 6 ++++++ .../GetVersionWithoutCommandEventTest.java | 7 ++++++- .../GetVersionWorkflowRemoveTest.java | 6 ++++++ .../GetVersionWorkflowReplaceCompletelyTest.java | 6 ++++++ ...GetVersionWorkflowReplaceGetVersionIdTest.java | 6 ++++++ .../versionTests/VersionNotSupportedTest.java | 6 ++++++ .../io/temporal/testing/TestWorkflowRule.java | 15 ++++++++++++--- 16 files changed, 99 insertions(+), 5 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java index 73d026675a..c6576ceabf 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java @@ -29,6 +29,7 @@ import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowStub; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; @@ -45,6 +46,11 @@ public class BinaryChecksumSetWhenTaskCompletedTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() + .setWorkflowClientOptions( + WorkflowClientOptions.newBuilder() + .setBinaryChecksum(SDKTestWorkflowRule.BINARY_CHECKSUM) + .setNamespace(SDKTestWorkflowRule.NAMESPACE) + .build()) .setWorkflowTypes(SimpleTestWorkflow.class) .setActivityImplementations(activitiesImpl) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java index 82939b1413..15609c704f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java @@ -22,6 +22,7 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowOptions; import io.temporal.failure.TimeoutFailure; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import java.lang.management.ManagementFactory; @@ -41,6 +42,10 @@ public class NonDeterministicWorkflowPolicyBlockWorkflowTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(WorkflowTest.DeterminismFailingWorkflowImpl.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java index effbc43397..817954c123 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java @@ -23,6 +23,7 @@ import io.temporal.client.WorkflowOptions; import io.temporal.failure.ApplicationFailure; import io.temporal.internal.replay.InternalWorkflowTaskException; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.worker.WorkflowImplementationOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; @@ -39,12 +40,16 @@ public class NonDeterministicWorkflowPolicyFailWorkflowTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() + .setActivityImplementations(activitiesImpl) .setWorkflowTypes( WorkflowImplementationOptions.newBuilder() .setFailWorkflowExceptionTypes(Throwable.class) .build(), WorkflowTest.DeterminismFailingWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java index aeaaa607cc..1b86ce19a1 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java @@ -37,6 +37,7 @@ import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.testing.TestWorkflowEnvironment; import io.temporal.testing.TestWorkflowRule; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.worker.WorkerOptions; import io.temporal.worker.WorkflowImplementationOptions; import io.temporal.workflow.Functions; @@ -97,6 +98,11 @@ public Builder setWorkerOptions(WorkerOptions options) { return this; } + public Builder setWorkerFactoryOptions(WorkerFactoryOptions options) { + testWorkflowRuleBuilder.setWorkerFactoryOptions(options); + return this; + } + public Builder setWorkflowClientOptions(WorkflowClientOptions workflowClientOptions) { testWorkflowRuleBuilder.setWorkflowClientOptions(workflowClientOptions); return this; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java index 2fea503170..020e889166 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java @@ -19,10 +19,12 @@ package io.temporal.workflow.versionTests; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; import org.junit.Assume; import org.junit.Rule; import org.junit.Test; @@ -40,6 +42,10 @@ public class GetVersionAddNewBeforeTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowAddNewBefore.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java index 9cd40f379d..8d56816817 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java @@ -22,11 +22,13 @@ import static org.junit.Assert.assertEquals; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; 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; @@ -41,6 +43,10 @@ public class GetVersionRemovedBeforeTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionRemovedBefore.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java index 0f0115d641..4fb604fe15 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java @@ -22,11 +22,13 @@ import static org.junit.Assert.assertEquals; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; 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; @@ -41,6 +43,10 @@ public class GetVersionRemovedInReplayTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionRemovedInReplay.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java index b0275ed926..8830290c63 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java @@ -27,6 +27,7 @@ import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.client.WorkflowStub; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; @@ -47,6 +48,10 @@ public class GetVersionSameIdOnReplayTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionSameIdOnReplay.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java index 1b60768006..222332e257 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; @@ -40,6 +41,10 @@ public class GetVersionSameIdTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionSameId.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java index e1b0b10548..567bfb288c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java @@ -23,11 +23,13 @@ import static org.junit.Assert.assertTrue; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; 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; @@ -42,6 +44,10 @@ public class GetVersionTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowImpl.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java index 05c9df4c0d..48c425cc60 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java @@ -21,11 +21,13 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowStub; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.CompletablePromise; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; +import java.time.Duration; import java.util.concurrent.CompletableFuture; import org.junit.Assert; import org.junit.Rule; @@ -42,7 +44,10 @@ public class GetVersionWithoutCommandEventTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWithoutCommandEventWorkflowImpl.class) .setActivityImplementations(activitiesImpl) - .setTestTimeoutSeconds(20) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java index f46bc9e621..56854cddf2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java @@ -20,11 +20,13 @@ package io.temporal.workflow.versionTests; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; 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.Assume; import org.junit.Rule; @@ -40,6 +42,10 @@ public class GetVersionWorkflowRemoveTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowRemove.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java index 86e405c911..ff02692823 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java @@ -19,10 +19,12 @@ package io.temporal.workflow.versionTests; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; import org.junit.Assume; import org.junit.Rule; import org.junit.Test; @@ -41,6 +43,10 @@ public class GetVersionWorkflowReplaceCompletelyTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowReplaceCompletely.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java index 13d981a59b..692204e830 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java @@ -19,10 +19,12 @@ package io.temporal.workflow.versionTests; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; +import java.time.Duration; import org.junit.Assume; import org.junit.Rule; import org.junit.Test; @@ -41,6 +43,10 @@ public class GetVersionWorkflowReplaceGetVersionIdTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowReplaceGetVersionId.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java index 86eb688076..b1e8097573 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java @@ -21,11 +21,13 @@ import io.temporal.client.WorkflowException; import io.temporal.failure.ApplicationFailure; +import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; 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; @@ -40,6 +42,10 @@ public class VersionNotSupportedTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestVersionNotSupportedWorkflowImpl.class) .setActivityImplementations(activitiesImpl) + .setWorkerFactoryOptions( + WorkerFactoryOptions.newBuilder() + .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) + .build()) .build(); @Test diff --git a/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java b/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java index d275d9dd66..e9c1704039 100644 --- a/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java +++ b/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java @@ -69,6 +69,7 @@ public class TestWorkflowRule implements TestRule { private final WorkerInterceptor[] interceptors; private final WorkflowImplementationOptions workflowImplementationOptions; private final WorkerOptions workerOptions; + private final WorkerFactoryOptions workerFactoryOptions; private final TestWorkflowEnvironment testEnvironment; private final TestWatcher watchman = new TestWatcher() { @@ -94,6 +95,11 @@ private TestWorkflowRule(Builder builder) { (builder.workerOptions == null) ? WorkerOptions.newBuilder().build() : builder.workerOptions; + workerFactoryOptions = + (builder.workerFactoryOptions == null) + ? WorkerFactoryOptions.newBuilder().build() + : builder.workerFactoryOptions; + workerFactoryOptions.toBuilder().setWorkerInterceptors(interceptors).build(); workflowImplementationOptions = (builder.workflowImplementationOptions == null) ? WorkflowImplementationOptions.newBuilder().build() @@ -108,12 +114,10 @@ private TestWorkflowRule(Builder builder) { (builder.workflowClientOptions == null) ? WorkflowClientOptions.newBuilder().setNamespace(namespace).build() : builder.workflowClientOptions; - WorkerFactoryOptions factoryOptions = - WorkerFactoryOptions.newBuilder().setWorkerInterceptors(interceptors).build(); TestEnvironmentOptions testOptions = TestEnvironmentOptions.newBuilder() .setWorkflowClientOptions(clientOptions) - .setWorkerFactoryOptions(factoryOptions) + .setWorkerFactoryOptions(workerFactoryOptions) .setUseExternalService(useExternalService) .setTarget(builder.target) .build(); @@ -129,6 +133,7 @@ public static class Builder { private WorkflowImplementationOptions workflowImplementationOptions; private WorkerOptions workerOptions; + private WorkerFactoryOptions workerFactoryOptions; private WorkflowClientOptions workflowClientOptions; private String namespace; private Class[] workflowTypes; @@ -146,6 +151,10 @@ public Builder setWorkerOptions(WorkerOptions options) { return this; } + public void setWorkerFactoryOptions(WorkerFactoryOptions options) { + this.workerFactoryOptions = options; + } + /** * Override {@link WorkflowClientOptions} for test environment. If set, takes precedence over * {@link #setNamespace(String) namespace}. From 714251ca13503ee6422d31aba01de42ca6dddd61 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Mon, 29 Mar 2021 14:53:32 -0700 Subject: [PATCH 10/21] Fixed SyncTest --- .../src/test/java/io/temporal/workflow/SyncTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java index 632218843a..73a1c62f3b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java @@ -53,6 +53,8 @@ public class SyncTest { @Test public void testSync() { + activitiesImpl.setCompletionClient( + testWorkflowRule.getWorkflowClient().newActivityCompletionClient()); TestWorkflows.TestWorkflow1 workflowStub = testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); @@ -72,12 +74,14 @@ public void testSync() { @Test public void testSyncUntypedAndStackTrace() { + activitiesImpl.setCompletionClient( + testWorkflowRule.getWorkflowClient().newActivityCompletionClient()); WorkflowStub workflowStub = testWorkflowRule.newUntypedWorkflowStubTimeoutOptions("TestWorkflow1"); WorkflowExecution execution = workflowStub.start(testWorkflowRule.getTaskQueue()); testWorkflowRule.sleep(Duration.ofMillis(500)); String stackTrace = workflowStub.query(QUERY_TYPE_STACK_TRACE, String.class); - assertTrue(stackTrace, stackTrace.contains("WorkflowTest$TestSyncWorkflowImpl.execute")); + assertTrue(stackTrace, stackTrace.contains("TestSyncWorkflowImpl.execute")); assertTrue(stackTrace, stackTrace.contains("activityWithDelay")); // Test stub created from workflow execution. workflowStub = @@ -85,7 +89,7 @@ public void testSyncUntypedAndStackTrace() { .getWorkflowClient() .newUntypedWorkflowStub(execution, workflowStub.getWorkflowType()); stackTrace = workflowStub.query(QUERY_TYPE_STACK_TRACE, String.class); - assertTrue(stackTrace, stackTrace.contains("WorkflowTest$TestSyncWorkflowImpl.execute")); + assertTrue(stackTrace, stackTrace.contains("TestSyncWorkflowImpl.execute")); assertTrue(stackTrace, stackTrace.contains("activityWithDelay")); String result = workflowStub.getResult(String.class); assertEquals("activity10", result); From cc916ca880a034be7f02f6f19a73ae2a8cd3057b Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Mon, 29 Mar 2021 21:42:36 -0700 Subject: [PATCH 11/21] Fixed a silly bug. --- .../src/main/java/io/temporal/testing/TestWorkflowRule.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java b/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java index e9c1704039..b8ed855584 100644 --- a/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java +++ b/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java @@ -97,9 +97,8 @@ private TestWorkflowRule(Builder builder) { : builder.workerOptions; workerFactoryOptions = (builder.workerFactoryOptions == null) - ? WorkerFactoryOptions.newBuilder().build() - : builder.workerFactoryOptions; - workerFactoryOptions.toBuilder().setWorkerInterceptors(interceptors).build(); + ? WorkerFactoryOptions.newBuilder().setWorkerInterceptors(interceptors).build() + : builder.workerFactoryOptions.toBuilder().setWorkerInterceptors(interceptors).build(); workflowImplementationOptions = (builder.workflowImplementationOptions == null) ? WorkflowImplementationOptions.newBuilder().build() From 29e1d8819eaa6c9418d68168cae70af97d5b331b Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Mon, 29 Mar 2021 23:20:27 -0700 Subject: [PATCH 12/21] Previously run only when testEnvironment != null, and it was null when Docker was used. When using the rule, testEnvironment is never null, so it failed in Docker. Inserted if statement to skip this test in Docker. --- .../workflow/SearchAttributesTest.java | 129 +++++++++--------- 1 file changed, 65 insertions(+), 64 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java index 5a34570720..46e21787d1 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java @@ -19,6 +19,8 @@ package io.temporal.workflow; +import static org.junit.Assert.assertEquals; + import com.google.protobuf.ByteString; import com.uber.m3.tally.NoopScope; import io.temporal.api.common.v1.Payload; @@ -37,7 +39,6 @@ import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -55,72 +56,72 @@ public class SearchAttributesTest { @Test public void testSearchAttributes() { - if (testWorkflowRule.getTestEnvironment() != null) { - String testKeyString = "CustomKeywordField"; - String testValueString = "testKeyword"; - String testKeyInteger = "CustomIntField"; - Integer testValueInteger = 1; - String testKeyDateTime = "CustomDateTimeField"; - LocalDateTime testValueDateTime = LocalDateTime.now(); - String testKeyBool = "CustomBoolField"; - Boolean testValueBool = true; - String testKeyDouble = "CustomDoubleField"; - Double testValueDouble = 1.23; + if (SDKTestWorkflowRule.useExternalService) { + return; + } + String testKeyString = "CustomKeywordField"; + String testValueString = "testKeyword"; + String testKeyInteger = "CustomIntField"; + Integer testValueInteger = 1; + String testKeyDateTime = "CustomDateTimeField"; + LocalDateTime testValueDateTime = LocalDateTime.now(); + String testKeyBool = "CustomBoolField"; + Boolean testValueBool = true; + String testKeyDouble = "CustomDoubleField"; + Double testValueDouble = 1.23; - // add more type to test - Map searchAttr = new HashMap(); - searchAttr.put(testKeyString, testValueString); - searchAttr.put(testKeyInteger, testValueInteger); - searchAttr.put(testKeyDateTime, testValueDateTime); - searchAttr.put(testKeyBool, testValueBool); - searchAttr.put(testKeyDouble, testValueDouble); + // add more type to test + Map searchAttr = new HashMap<>(); + searchAttr.put(testKeyString, testValueString); + searchAttr.put(testKeyInteger, testValueInteger); + searchAttr.put(testKeyDateTime, testValueDateTime); + searchAttr.put(testKeyBool, testValueBool); + searchAttr.put(testKeyDouble, testValueDouble); - WorkflowOptions workflowOptions = - TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) - .toBuilder() - .setSearchAttributes(searchAttr) - .build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = - testWorkflowRule - .getWorkflowClient() - .newWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, - workflowOptions); - WorkflowExecution executionF = WorkflowClient.start(stubF::func); + WorkflowOptions workflowOptions = + TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) + .toBuilder() + .setSearchAttributes(searchAttr) + .build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc stubF = + testWorkflowRule + .getWorkflowClient() + .newWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc.class, workflowOptions); + WorkflowExecution executionF = WorkflowClient.start(stubF::func); - GetWorkflowExecutionHistoryResponse historyResp = - WorkflowExecutionUtils.getHistoryPage( - testWorkflowRule.getTestEnvironment().getWorkflowService(), - SDKTestWorkflowRule.NAMESPACE, - executionF, - ByteString.EMPTY, - new NoopScope()); - HistoryEvent startEvent = historyResp.getHistory().getEvents(0); - SearchAttributes searchAttrFromEvent = - startEvent.getWorkflowExecutionStartedEventAttributes().getSearchAttributes(); + GetWorkflowExecutionHistoryResponse historyResp = + WorkflowExecutionUtils.getHistoryPage( + testWorkflowRule.getTestEnvironment().getWorkflowService(), + SDKTestWorkflowRule.NAMESPACE, + executionF, + ByteString.EMPTY, + new NoopScope()); + HistoryEvent startEvent = historyResp.getHistory().getEvents(0); + SearchAttributes searchAttrFromEvent = + startEvent.getWorkflowExecutionStartedEventAttributes().getSearchAttributes(); - Map fieldsMap = searchAttrFromEvent.getIndexedFieldsMap(); - Payload searchAttrStringBytes = fieldsMap.get(testKeyString); - DataConverter converter = DataConverter.getDefaultInstance(); - String retrievedString = - converter.fromPayload(searchAttrStringBytes, String.class, String.class); - Assert.assertEquals(testValueString, retrievedString); - Payload searchAttrIntegerBytes = fieldsMap.get(testKeyInteger); - Integer retrievedInteger = - converter.fromPayload(searchAttrIntegerBytes, Integer.class, Integer.class); - Assert.assertEquals(testValueInteger, retrievedInteger); - Payload searchAttrDateTimeBytes = fieldsMap.get(testKeyDateTime); - LocalDateTime retrievedDateTime = - converter.fromPayload(searchAttrDateTimeBytes, LocalDateTime.class, LocalDateTime.class); - Assert.assertEquals(testValueDateTime, retrievedDateTime); - Payload searchAttrBoolBytes = fieldsMap.get(testKeyBool); - Boolean retrievedBool = - converter.fromPayload(searchAttrBoolBytes, Boolean.class, Boolean.class); - Assert.assertEquals(testValueBool, retrievedBool); - Payload searchAttrDoubleBytes = fieldsMap.get(testKeyDouble); - Double retrievedDouble = - converter.fromPayload(searchAttrDoubleBytes, Double.class, Double.class); - Assert.assertEquals(testValueDouble, retrievedDouble); - } + Map fieldsMap = searchAttrFromEvent.getIndexedFieldsMap(); + Payload searchAttrStringBytes = fieldsMap.get(testKeyString); + DataConverter converter = DataConverter.getDefaultInstance(); + String retrievedString = + converter.fromPayload(searchAttrStringBytes, String.class, String.class); + assertEquals(testValueString, retrievedString); + Payload searchAttrIntegerBytes = fieldsMap.get(testKeyInteger); + Integer retrievedInteger = + converter.fromPayload(searchAttrIntegerBytes, Integer.class, Integer.class); + assertEquals(testValueInteger, retrievedInteger); + Payload searchAttrDateTimeBytes = fieldsMap.get(testKeyDateTime); + LocalDateTime retrievedDateTime = + converter.fromPayload(searchAttrDateTimeBytes, LocalDateTime.class, LocalDateTime.class); + assertEquals(testValueDateTime, retrievedDateTime); + Payload searchAttrBoolBytes = fieldsMap.get(testKeyBool); + Boolean retrievedBool = + converter.fromPayload(searchAttrBoolBytes, Boolean.class, Boolean.class); + assertEquals(testValueBool, retrievedBool); + Payload searchAttrDoubleBytes = fieldsMap.get(testKeyDouble); + Double retrievedDouble = + converter.fromPayload(searchAttrDoubleBytes, Double.class, Double.class); + assertEquals(testValueDouble, retrievedDouble); } } From 4b0395f3aa0f18a2a9bc26595ef54abb239f9748 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Tue, 30 Mar 2021 11:50:47 -0700 Subject: [PATCH 13/21] Fixed CustomDatetimeField search attribute string --- docker/buildkite/docker-compose.yaml | 2 +- .../test/java/io/temporal/workflow/SearchAttributesTest.java | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/docker/buildkite/docker-compose.yaml b/docker/buildkite/docker-compose.yaml index 1c7794106b..128f531ed4 100644 --- a/docker/buildkite/docker-compose.yaml +++ b/docker/buildkite/docker-compose.yaml @@ -19,7 +19,7 @@ services: - "8126:8126" temporal: - image: temporalio/auto-setup:1.1.1 + image: temporalio/auto-setup:latest logging: driver: none ports: diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java index 46e21787d1..f1f39f965b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java @@ -56,14 +56,11 @@ public class SearchAttributesTest { @Test public void testSearchAttributes() { - if (SDKTestWorkflowRule.useExternalService) { - return; - } String testKeyString = "CustomKeywordField"; String testValueString = "testKeyword"; String testKeyInteger = "CustomIntField"; Integer testValueInteger = 1; - String testKeyDateTime = "CustomDateTimeField"; + String testKeyDateTime = "CustomDatetimeField"; LocalDateTime testValueDateTime = LocalDateTime.now(); String testKeyBool = "CustomBoolField"; Boolean testValueBool = true; From 01a996d0de25d54bfd39022780c7d4bab9b8ce4d Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Tue, 30 Mar 2021 14:43:30 -0700 Subject: [PATCH 14/21] Added .getWorkflowExecutionHistory() and .blockingStub to WorkflowRules --- docker/buildkite/docker-compose.yaml | 2 +- .../client/WorkflowClientOptions.java | 4 ++++ .../workflow/UpsertSearchAttributesTest.java | 6 +---- .../WorkflowTaskFailureBackoffTest.java | 6 +---- .../workflow/WorkflowTaskNPEBackoffTest.java | 6 +---- .../AbandonOnCancelActivityTest.java | 6 +---- .../ChildWorkflowCancellationTest.java | 24 ++++--------------- .../workflow/shared/SDKTestWorkflowRule.java | 13 ++++++++-- .../GetVersionSameIdOnReplayTest.java | 11 +-------- .../io/temporal/testing/TestWorkflowRule.java | 20 +++++++++++++++- 10 files changed, 44 insertions(+), 54 deletions(-) diff --git a/docker/buildkite/docker-compose.yaml b/docker/buildkite/docker-compose.yaml index 128f531ed4..1c7794106b 100644 --- a/docker/buildkite/docker-compose.yaml +++ b/docker/buildkite/docker-compose.yaml @@ -19,7 +19,7 @@ services: - "8126:8126" temporal: - image: temporalio/auto-setup:latest + image: temporalio/auto-setup:1.1.1 logging: driver: none ports: diff --git a/temporal-sdk/src/main/java/io/temporal/client/WorkflowClientOptions.java b/temporal-sdk/src/main/java/io/temporal/client/WorkflowClientOptions.java index e33160d2e7..e266b81048 100644 --- a/temporal-sdk/src/main/java/io/temporal/client/WorkflowClientOptions.java +++ b/temporal-sdk/src/main/java/io/temporal/client/WorkflowClientOptions.java @@ -47,6 +47,10 @@ public static Builder newBuilder(WorkflowClientOptions options) { return new Builder(options); } + public WorkflowClientOptions.Builder toBuilder() { + return new WorkflowClientOptions.Builder(this); + } + public static WorkflowClientOptions getDefaultInstance() { return DEFAULT_INSTANCE; } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java index 7017938bfa..d007d8951c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java @@ -76,11 +76,7 @@ public void testUpsertSearchAttributes() { .setExecution(execution) .build(); GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getTestEnvironment() - .getWorkflowService() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); boolean found = false; for (HistoryEvent event : response.getHistory().getEventsList()) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java index cf60276579..5f5748ec60 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java @@ -71,11 +71,7 @@ public void testWorkflowTaskFailureBackoff() { .setExecution(WorkflowStub.fromTyped(workflowStub).getExecution()) .build(); GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getTestEnvironment() - .getWorkflowService() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); int failedTaskCount = 0; for (HistoryEvent event : response.getHistory().getEventsList()) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java index 2fca3fd20b..717c52595a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java @@ -71,11 +71,7 @@ public void testWorkflowTaskNPEBackoff() { .setExecution(WorkflowStub.fromTyped(workflowStub).getExecution()) .build(); GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getTestEnvironment() - .getWorkflowService() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); int failedTaskCount = 0; for (HistoryEvent event : response.getHistory().getEventsList()) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java index 003c075c83..7e7bbb6086 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java @@ -80,11 +80,7 @@ public void testAbandonOnCancelActivity() { .setExecution(execution) .build(); GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getWorkflowClient() - .getWorkflowServiceStubs() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); for (HistoryEvent event : response.getHistory().getEventsList()) { Assert.assertNotEquals( diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java index b2ab6fcd18..2640139d5c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java @@ -68,11 +68,7 @@ public void testChildWorkflowWaitCancellationRequested() { .setExecution(execution) .build(); GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getTestEnvironment() - .getWorkflowService() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); boolean hasChildCanceled = false; boolean hasChildCancelRequested = false; @@ -108,11 +104,7 @@ public void testChildWorkflowWaitCancellationCompleted() { .setExecution(execution) .build(); GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getTestEnvironment() - .getWorkflowService() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); boolean hasChildCanceled = false; for (HistoryEvent event : response.getHistory().getEventsList()) { @@ -141,11 +133,7 @@ public void testChildWorkflowCancellationAbandon() { .setExecution(execution) .build(); GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getTestEnvironment() - .getWorkflowService() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); boolean hasChildCancelInitiated = false; for (HistoryEvent event : response.getHistory().getEventsList()) { @@ -175,11 +163,7 @@ public void testChildWorkflowCancellationTryCancel() { .setExecution(execution) .build(); GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getTestEnvironment() - .getWorkflowService() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); boolean hasChildCancelInitiated = false; boolean hasChildCancelRequested = false; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java index 1b86ce19a1..808a657660 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java @@ -28,6 +28,7 @@ import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; +import io.temporal.api.workflowservice.v1.WorkflowServiceGrpc; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowQueryException; @@ -163,6 +164,10 @@ public Statement apply(Statement base, Description description) { return testWorkflowRule.apply(base, description); } + public WorkflowServiceGrpc.WorkflowServiceBlockingStub blockingStub() { + return testWorkflowRule.blockingStub(); + } + public T getInterceptor(Class type) { return testWorkflowRule.getInterceptor(type); } @@ -171,6 +176,11 @@ public String getTaskQueue() { return testWorkflowRule.getTaskQueue(); } + public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( + GetWorkflowExecutionHistoryRequest request) { + return testWorkflowRule.getWorkflowExecutionHistory(request); + } + public WorkflowClient getWorkflowClient() { return testWorkflowRule.getWorkflowClient(); } @@ -257,8 +267,7 @@ public static void regenerateHistoryForReplay( } } - // TODO: Refactor testEnvironment to support testing through real service to avoid this - // switches + // TODO: Refactor testEnv to support testing through real service to avoid these switches. public void registerDelayedCallback(Duration delay, Runnable r) { if (useExternalService) { ScheduledFuture result = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java index 8830290c63..3ba0525613 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java @@ -30,7 +30,6 @@ import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; @@ -40,14 +39,10 @@ public class GetVersionSameIdOnReplayTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionSameIdOnReplay.class) - .setActivityImplementations(activitiesImpl) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) @@ -70,11 +65,7 @@ public void testGetVersionSameIdOnReplay() { // Validate that no marker is recorded GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getTestEnvironment() - .getWorkflowService() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); for (HistoryEvent event : response.getHistory().getEventsList()) { Assert.assertFalse(EventType.EVENT_TYPE_MARKER_RECORDED == event.getEventType()); } diff --git a/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java b/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java index b8ed855584..45677f0b28 100644 --- a/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java +++ b/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java @@ -19,6 +19,9 @@ package io.temporal.testing; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; +import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; +import io.temporal.api.workflowservice.v1.WorkflowServiceGrpc; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowClientOptions; import io.temporal.common.interceptors.WorkerInterceptor; @@ -112,7 +115,7 @@ private TestWorkflowRule(Builder builder) { WorkflowClientOptions clientOptions = (builder.workflowClientOptions == null) ? WorkflowClientOptions.newBuilder().setNamespace(namespace).build() - : builder.workflowClientOptions; + : builder.workflowClientOptions.toBuilder().setNamespace(namespace).build(); TestEnvironmentOptions testOptions = TestEnvironmentOptions.newBuilder() .setWorkflowClientOptions(clientOptions) @@ -274,6 +277,11 @@ protected void shutdown() throws Throwable { } } + /** Returns blockingStub */ + public WorkflowServiceGrpc.WorkflowServiceBlockingStub blockingStub() { + return testEnvironment.getWorkflowService().blockingStub(); + } + /** Returns tracer. */ public T getInterceptor(Class type) { if (interceptors != null) { @@ -291,6 +299,16 @@ public String getTaskQueue() { return taskQueue; } + /** + * Returns name of the task queue that test worker is polling. + * + * @return + */ + public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( + GetWorkflowExecutionHistoryRequest request) { + return this.blockingStub().getWorkflowExecutionHistory(request); + } + /** Returns client to the Temporal service used to start and query workflows. */ public WorkflowClient getWorkflowClient() { return testEnvironment.getWorkflowClient(); From 632bab2a451dccc870c1ce5c4b5649679b243a32 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Tue, 30 Mar 2021 15:28:57 -0700 Subject: [PATCH 15/21] Removed unnesassary ActivityImplementations setting. --- .../src/test/java/io/temporal/workflow/AwaitTest.java | 9 +-------- .../BinaryChecksumSetWhenTaskCompletedTest.java | 11 +---------- .../io/temporal/workflow/ContinueAsNewNoArgsTest.java | 5 ----- .../java/io/temporal/workflow/ContinueAsNewTest.java | 5 ----- .../test/java/io/temporal/workflow/ExecuteTest.java | 5 ----- .../workflow/GetAttemptFromWorkflowInfoTest.java | 5 ----- .../src/test/java/io/temporal/workflow/MemoTest.java | 5 ----- .../java/io/temporal/workflow/MultipleTimersTest.java | 9 +-------- .../io/temporal/workflow/MutableSideEffectTest.java | 4 ---- .../io/temporal/workflow/NoQueryThreadLeakTest.java | 9 +-------- ...nDeterministicWorkflowPolicyBlockWorkflowTest.java | 5 ----- .../io/temporal/workflow/ParentContinueAsNewTest.java | 5 ----- .../io/temporal/workflow/PolymorphicStartTest.java | 5 ----- .../io/temporal/workflow/SearchAttributesTest.java | 8 +++----- .../src/test/java/io/temporal/workflow/StartTest.java | 5 ----- .../temporal/workflow/TimerCallbackBlockedTest.java | 5 ----- .../src/test/java/io/temporal/workflow/TimerTest.java | 5 ----- .../WorkflowCancellationScopePromiseTest.java | 9 +-------- .../workflow/WorkflowFailureNonRetryableFlagTest.java | 8 +------- .../temporal/workflow/WorkflowIdResuePolicyTest.java | 5 ----- .../java/io/temporal/workflow/WorkflowLocalsTest.java | 9 +-------- .../WorkflowRetryDoNotRetryExceptionTest.java | 4 ---- .../java/io/temporal/workflow/WorkflowRetryTest.java | 8 +------- ...owRetryWithMethodRetryDoNotRetryExceptionTest.java | 4 ---- .../workflow/WorkflowTaskFailureBackoffTest.java | 4 ---- .../temporal/workflow/WorkflowTaskNPEBackoffTest.java | 8 +------- .../workflow/WorkflowTaskTimeoutWorkflowTest.java | 4 ---- .../workflow/WorkflowWithCronScheduleTest.java | 5 ----- .../WorkflowsWithFailedPromisesCanBeCanceledTest.java | 5 ----- .../activityTests/AsyncRetryOptionsChangeTest.java | 5 ----- .../workflow/activityTests/AsyncRetryTest.java | 9 +-------- .../ChildAsyncLambdaWorkflowTest.java | 5 ----- .../childWorkflowTests/ChildAsyncWorkflowTest.java | 5 ----- .../ChildWorkflowExecutionPromiseHandlerTest.java | 5 ----- .../childWorkflowTests/ChildWorkflowTest.java | 4 ---- .../childWorkflowTests/ChildWorkflowTimeoutTest.java | 5 ----- .../ChildWorkflowWithCronScheduleTest.java | 5 ----- .../workflow/childWorkflowTests/NamedChildTest.java | 4 ---- .../NonSerializableExceptionInChildWorkflowTest.java | 5 ----- .../ParentWorkflowInfoInChildWorkflowsTest.java | 5 ----- ...kflowWithCancellationScopeAndCancelParentTest.java | 5 ----- .../UntypedChildStubWorkflowAsyncInvokeTest.java | 5 ----- .../UntypedChildStubWorkflowAsyncTest.java | 5 ----- .../UntypedChildStubWorkflowTest.java | 5 ----- .../signalTests/SignalAndQueryInterfaceTest.java | 8 +------- .../signalTests/SignalAndQueryListenerTest.java | 4 ---- .../signalTests/SignalDuringLastWorkflowTaskTest.java | 4 ---- .../SignalExternalWorkflowFailureTest.java | 4 ---- ...gnalExternalWorkflowImmediateCancellationTest.java | 4 ---- .../signalTests/SignalExternalWorkflowTest.java | 4 ---- .../io/temporal/workflow/signalTests/SignalTest.java | 4 ---- .../UntypedSignalExternalWorkflowTest.java | 4 ---- .../versionTests/GetVersionAddNewBeforeTest.java | 4 ---- .../workflow/versionTests/GetVersionSameIdTest.java | 5 ----- .../GetVersionWithoutCommandEventTest.java | 4 ---- .../GetVersionWorkflowReplaceCompletelyTest.java | 4 ---- .../GetVersionWorkflowReplaceGetVersionIdTest.java | 4 ---- 57 files changed, 14 insertions(+), 298 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/AwaitTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/AwaitTest.java index ad61270f61..2bbe79eeac 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/AwaitTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/AwaitTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertFalse; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Rule; @@ -31,15 +30,9 @@ public class AwaitTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestAwait.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestAwait.class).build(); @Test public void testAwait() { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java index c6576ceabf..a385af49bb 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java @@ -40,19 +40,14 @@ public class BinaryChecksumSetWhenTaskCompletedTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowClientOptions( WorkflowClientOptions.newBuilder() .setBinaryChecksum(SDKTestWorkflowRule.BINARY_CHECKSUM) - .setNamespace(SDKTestWorkflowRule.NAMESPACE) .build()) .setWorkflowTypes(SimpleTestWorkflow.class) - .setActivityImplementations(activitiesImpl) .build(); @Test @@ -69,11 +64,7 @@ public void testBinaryChecksumSetWhenTaskCompleted() { .setExecution(execution) .build(); GetWorkflowExecutionHistoryResponse response = - testWorkflowRule - .getTestEnvironment() - .getWorkflowService() - .blockingStub() - .getWorkflowExecutionHistory(request); + testWorkflowRule.getWorkflowExecutionHistory(request); boolean foundCompletedTask = false; for (HistoryEvent event : response.getHistory().getEventsList()) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java index c04f3c3d6f..b5948d82e2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewNoArgsTest.java @@ -21,21 +21,16 @@ import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; public class ContinueAsNewNoArgsTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestContinueAsNewNoArgsImpl.class) - .setActivityImplementations(activitiesImpl) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java index 82f95bbcca..abedd97c0d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java @@ -23,7 +23,6 @@ import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.util.HashMap; import java.util.Map; import org.junit.Assert; @@ -32,14 +31,10 @@ public class ContinueAsNewTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestContinueAsNewImpl.class) - .setActivityImplementations(activitiesImpl) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java index 68fec1e945..6c8612a2f7 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ExecuteTest.java @@ -21,7 +21,6 @@ import io.temporal.client.WorkflowClient; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import java.util.concurrent.ExecutionException; import org.junit.Assert; @@ -30,14 +29,10 @@ public class ExecuteTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java index 06d8d666f4..ba1fb6964e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java @@ -21,7 +21,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; import org.junit.Assert; import org.junit.Rule; @@ -29,16 +28,12 @@ public class GetAttemptFromWorkflowInfoTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( WorkflowTest.TestMultiargsWorkflowsFuncParent.class, TestAttemptReturningWorkflowFunc.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java index 077abf9fa1..75200f51b7 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java @@ -31,7 +31,6 @@ import io.temporal.common.converter.GsonJsonPayloadConverter; import io.temporal.internal.common.WorkflowExecutionUtils; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestOptions; import java.util.HashMap; @@ -42,14 +41,10 @@ public class MemoTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java index 99089738f2..682648abfb 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MultipleTimersTest.java @@ -20,7 +20,6 @@ package io.temporal.workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; @@ -28,15 +27,9 @@ public class MultipleTimersTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestMultipleTimersImpl.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestMultipleTimersImpl.class).build(); @Test public void testMultipleTimers() { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java index 4d66340849..ebf5ab1867 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MutableSideEffectTest.java @@ -20,7 +20,6 @@ package io.temporal.workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import java.util.*; @@ -32,14 +31,11 @@ public class MutableSideEffectTest { private static final Map> mutableSideEffectValue = Collections.synchronizedMap(new HashMap<>()); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestMutableSideEffectWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java index 8eab35ac06..1929e5f17b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java @@ -22,7 +22,6 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowStub; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.lang.management.ManagementFactory; import java.time.Duration; import org.junit.Assert; @@ -31,15 +30,9 @@ public class NoQueryThreadLeakTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestNoQueryWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestNoQueryWorkflowImpl.class).build(); @Test public void testNoQueryThreadLeak() throws InterruptedException { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java index 15609c704f..24f8e0c381 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java @@ -24,7 +24,6 @@ import io.temporal.failure.TimeoutFailure; import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.time.Duration; @@ -34,14 +33,10 @@ public class NonDeterministicWorkflowPolicyBlockWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(WorkflowTest.DeterminismFailingWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java index c59cb0f286..1a02e6f7d1 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java @@ -22,7 +22,6 @@ import io.temporal.api.enums.v1.WorkflowIdReusePolicy; import io.temporal.client.WorkflowOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; @@ -31,14 +30,10 @@ public class ParentContinueAsNewTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestParentWorkflowContinueAsNew.class, WorkflowTest.TestChild.class) - .setActivityImplementations(activitiesImpl) .build(); /** Reproduction of a bug when a child of continued as new workflow has the same UUID ID. */ diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java index 5bbc234d27..be98e4846f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/PolymorphicStartTest.java @@ -20,21 +20,16 @@ package io.temporal.workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; public class PolymorphicStartTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(WorkflowAImpl.class, WorkflowBImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java index f1f39f965b..1b8bd08788 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SearchAttributesTest.java @@ -33,7 +33,6 @@ import io.temporal.common.converter.DataConverter; import io.temporal.internal.common.WorkflowExecutionUtils; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestOptions; import java.time.LocalDateTime; @@ -44,18 +43,17 @@ public class SearchAttributesTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test public void testSearchAttributes() { + if (SDKTestWorkflowRule.useExternalService) { + return; + } String testKeyString = "CustomKeywordField"; String testValueString = "testKeyword"; String testKeyInteger = "CustomIntField"; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java index 984ec6df48..c3e5c2fe4b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/StartTest.java @@ -26,7 +26,6 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestOptions; import java.util.Optional; @@ -36,14 +35,10 @@ public class StartTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java index 6451b9a6ba..2c975022df 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/TimerCallbackBlockedTest.java @@ -21,7 +21,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; @@ -30,14 +29,10 @@ public class TimerCallbackBlockedTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestTimerCallbackBlockedWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .build(); /** Test that it is not allowed to block in the timer callback thread. */ diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java index 4abc008cae..38609b1b8f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java @@ -24,7 +24,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.testing.TracingWorkerInterceptor; 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; @@ -35,14 +34,10 @@ public class TimerTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestTimerWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java index 93b86db452..41275a0fb0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowCancellationScopePromiseTest.java @@ -23,7 +23,6 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import org.junit.Assert; import org.junit.Rule; @@ -31,15 +30,9 @@ public class WorkflowCancellationScopePromiseTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestCancellationScopePromise.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestCancellationScopePromise.class).build(); @Test public void testWorkflowCancellationScopePromise() { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java index e8482258b3..347e6e67e0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java @@ -23,7 +23,6 @@ import io.temporal.common.RetryOptions; import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; import java.time.Duration; import java.util.Map; @@ -37,17 +36,12 @@ public class WorkflowFailureNonRetryableFlagTest { private static final Map retryCount = new ConcurrentHashMap<>(); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestWorkflowNonRetryableFlag.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestWorkflowNonRetryableFlag.class).build(); @Test public void testWorkflowFailureNonRetryableFlag() { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java index 971f0b52b0..aaf87fcedf 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowIdResuePolicyTest.java @@ -22,7 +22,6 @@ import io.temporal.api.enums.v1.WorkflowIdReusePolicy; import io.temporal.client.WorkflowOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestOptions; import java.util.UUID; @@ -32,14 +31,10 @@ public class WorkflowIdResuePolicyTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java index 54d0a35ca8..57708a81c3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowLocalsTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; @@ -31,15 +30,9 @@ public class WorkflowLocalsTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestWorkflowLocals.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestWorkflowLocals.class).build(); @Test public void testWorkflowLocals() { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java index cefda2668c..8699ef5004 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java @@ -23,7 +23,6 @@ import io.temporal.common.RetryOptions; import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; import java.time.Duration; import java.util.Map; @@ -37,8 +36,6 @@ public class WorkflowRetryDoNotRetryExceptionTest { private static final Map retryCount = new ConcurrentHashMap<>(); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); @@ -46,7 +43,6 @@ public class WorkflowRetryDoNotRetryExceptionTest { public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestWorkflowRetryDoNotRetryException.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java index 3525d7febd..ff6f9190ab 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java @@ -25,7 +25,6 @@ import io.temporal.common.RetryOptions; import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; import java.time.Duration; import java.util.Map; @@ -39,17 +38,12 @@ public class WorkflowRetryTest { private static final Map retryCount = new ConcurrentHashMap<>(); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestWorkflowRetryImpl.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestWorkflowRetryImpl.class).build(); @Test public void testWorkflowRetry() { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java index e2098fc5cf..acd2748e1e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryWithMethodRetryDoNotRetryExceptionTest.java @@ -24,7 +24,6 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.worker.WorkflowImplementationOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; @@ -36,8 +35,6 @@ public class WorkflowRetryWithMethodRetryDoNotRetryExceptionTest { private static final Map retryCount = new ConcurrentHashMap<>(); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); @@ -50,7 +47,6 @@ public class WorkflowRetryWithMethodRetryDoNotRetryExceptionTest { IllegalStateException.class, IllegalArgumentException.class) .build(), TestWorkflowRetryWithMethodRetryImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java index 5f5748ec60..3b1a7f66b7 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java @@ -26,7 +26,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; @@ -36,14 +35,11 @@ public class WorkflowTaskFailureBackoffTest { private static int testWorkflowTaskFailureBackoffReplayCount; - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestWorkflowTaskFailureBackoff.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java index 717c52595a..6abe1cbd22 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java @@ -26,7 +26,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; @@ -36,15 +35,10 @@ public class WorkflowTaskNPEBackoffTest { private static int testWorkflowTaskFailureBackoffReplayCount; - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestWorkflowTaskNPEBackoff.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestWorkflowTaskNPEBackoff.class).build(); @Test public void testWorkflowTaskNPEBackoff() { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java index 123d86cfda..e856527f0a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskTimeoutWorkflowTest.java @@ -21,7 +21,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.time.Duration; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -34,8 +33,6 @@ public class WorkflowTaskTimeoutWorkflowTest { private static final Map retryCount = new ConcurrentHashMap<>(); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public TestName testName = new TestName(); @@ -43,7 +40,6 @@ public class WorkflowTaskTimeoutWorkflowTest { public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(WorkflowTaskTimeoutWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java index 2f94b05bc9..ddb88d47fd 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java @@ -27,7 +27,6 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.time.Duration; import org.junit.Assume; import org.junit.Rule; @@ -36,16 +35,12 @@ public class WorkflowWithCronScheduleTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public TestName testName = new TestName(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(WorkflowTest.TestWorkflowWithCronScheduleImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java index 583b5f00b9..8be608c926 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowsWithFailedPromisesCanBeCanceledTest.java @@ -26,7 +26,6 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import org.junit.Assert; import org.junit.Rule; @@ -34,14 +33,10 @@ public class WorkflowsWithFailedPromisesCanBeCanceledTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestCancellationForWorkflowsWithFailedPromises.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java index 9af9d51d23..402c322390 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryOptionsChangeTest.java @@ -27,7 +27,6 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import java.util.ArrayList; @@ -39,9 +38,6 @@ public class AsyncRetryOptionsChangeTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() @@ -50,7 +46,6 @@ public class AsyncRetryOptionsChangeTest { .setFailWorkflowExceptionTypes(IllegalThreadStateException.class) .build(), TestAsyncRetryOptionsChangeWorkflow.class) - .setActivityImplementations(activitiesImpl) .build(); /** @see DeterministicRunnerTest#testRetry() */ diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java index 9cb79e1c08..13869333a3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncRetryTest.java @@ -26,7 +26,6 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import java.util.ArrayList; @@ -38,15 +37,9 @@ public class AsyncRetryTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestAsyncRetryWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestAsyncRetryWorkflowImpl.class).build(); /** @see DeterministicRunnerTest#testRetry() */ @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java index d60eb64ca9..80d43d3af4 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java @@ -25,7 +25,6 @@ import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; @@ -34,14 +33,10 @@ public class ChildAsyncLambdaWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestWaitOnSignalWorkflowImpl.class, TestChildAsyncLambdaWorkflow.class) - .setActivityImplementations(activitiesImpl) .build(); /** diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java index 1ea4baec6f..dd9ea0a82e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncWorkflowTest.java @@ -25,7 +25,6 @@ import io.temporal.workflow.ChildWorkflowOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestWorkflows; import org.junit.Assert; @@ -34,16 +33,12 @@ public class ChildAsyncWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( TestChildAsyncWorkflow.class, TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java index b5ae65ff7a..b2820af6d1 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java @@ -26,7 +26,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.testing.TestWorkflowRule; import io.temporal.workflow.*; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Rule; @@ -34,14 +33,10 @@ public class ChildWorkflowExecutionPromiseHandlerTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public TestWorkflowRule testWorkflowRule = TestWorkflowRule.newBuilder() .setWorkflowTypes(TestNamedChild.class, TestChildWorkflowExecutionPromiseHandler.class) - .setActivityImplementations(activitiesImpl) .build(); /** Tests that handler of the WorkflowExecution promise is executed in a workflow thread. */ diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java index 8e9b69c42e..68362d3e95 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java @@ -23,7 +23,6 @@ import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.util.UUID; import org.junit.Rule; @@ -32,15 +31,12 @@ public class ChildWorkflowTest { private static String child2Id; - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( TestParentWorkflow.class, TestNamedChild.class, WorkflowTest.TestChild.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java index 4d316585f2..78cbd4fea0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java @@ -26,7 +26,6 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Rule; @@ -34,14 +33,10 @@ public class ChildWorkflowTimeoutTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestParentWorkflowWithChildTimeout.class, WorkflowTest.TestChild.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java index 07fc5f890f..ee065e786a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java @@ -29,7 +29,6 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assume; @@ -39,9 +38,6 @@ public class ChildWorkflowWithCronScheduleTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public TestName testName = new TestName(); @Rule @@ -49,7 +45,6 @@ public class ChildWorkflowWithCronScheduleTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( TestCronParentWorkflow.class, WorkflowTest.TestWorkflowWithCronScheduleImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java index cb933aab87..4ccef2ee73 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java @@ -26,7 +26,6 @@ import io.temporal.failure.ChildWorkflowFailure; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.util.UUID; import org.junit.Rule; import org.junit.Test; @@ -34,14 +33,11 @@ public class NamedChildTest { private static final String childReexecuteId = UUID.randomUUID().toString(); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestNamedChild.class, TestChildReexecuteWorkflow.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java index a41363234b..ab012adb0d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java @@ -26,7 +26,6 @@ import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import org.junit.Assert; import org.junit.Rule; @@ -34,9 +33,6 @@ public class NonSerializableExceptionInChildWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() @@ -46,7 +42,6 @@ public class NonSerializableExceptionInChildWorkflowTest { .build(), TestNonSerializableExceptionInChildWorkflow.class, NonSerializableExceptionChildWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java index ee7f47160d..4c73189cc0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java @@ -24,7 +24,6 @@ import io.temporal.workflow.WorkflowInfo; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestOptions; import java.util.Optional; @@ -34,16 +33,12 @@ public class ParentWorkflowInfoInChildWorkflowsTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( WorkflowTest.TestMultiargsWorkflowsFuncParent.class, TestMultiargsWorkflowsFuncChild.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java index c3b2db48f6..ed89ffd235 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java @@ -27,7 +27,6 @@ import io.temporal.failure.CanceledFailure; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.util.ArrayList; import java.util.List; import org.junit.Rule; @@ -35,14 +34,10 @@ public class StartChildWorkflowWithCancellationScopeAndCancelParentTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(ParentThatStartsChildInCancellationScope.class, SleepyChild.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java index 74dd8d6d19..a23c1a5fc0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncInvokeTest.java @@ -24,7 +24,6 @@ import io.temporal.workflow.ChildWorkflowStub; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestWorkflows; import org.junit.Assert; @@ -33,16 +32,12 @@ public class UntypedChildStubWorkflowAsyncInvokeTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( TestUntypedChildStubWorkflowAsyncInvoke.class, TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java index 4c92abc2e0..1b19b708ad 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowAsyncTest.java @@ -23,7 +23,6 @@ import io.temporal.workflow.ChildWorkflowStub; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestWorkflows; import org.junit.Assert; @@ -32,16 +31,12 @@ public class UntypedChildStubWorkflowAsyncTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( TestUntypedChildStubWorkflowAsync.class, TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java index 330391f061..9f5b6bf0e1 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/UntypedChildStubWorkflowTest.java @@ -25,7 +25,6 @@ import io.temporal.workflow.ChildWorkflowStub; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; import io.temporal.workflow.shared.TestWorkflows; import org.junit.Assert; @@ -34,16 +33,12 @@ public class UntypedChildStubWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( TestUntypedChildStubWorkflow.class, TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java index e61f6a1068..a5385e895c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java @@ -27,21 +27,15 @@ import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; public class SignalAndQueryInterfaceTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = - SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(SignalQueryWorkflowAImpl.class) - .setActivityImplementations(activitiesImpl) - .build(); + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(SignalQueryWorkflowAImpl.class).build(); @Test public void testSignalAndQueryInterface() { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java index 6020da12da..34045f7c01 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java @@ -26,7 +26,6 @@ import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; import java.util.ArrayList; import java.util.List; @@ -35,14 +34,11 @@ import org.junit.Test; public class SignalAndQueryListenerTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestSignalAndQueryListenerWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java index 4ab747a182..4521e2f9fe 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java @@ -24,7 +24,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; import java.time.Duration; import java.util.Optional; @@ -42,14 +41,11 @@ public class SignalDuringLastWorkflowTaskTest { private static final AtomicInteger workflowTaskCount = new AtomicInteger(); private static CompletableFuture sendSignal; - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestSignalDuringLastWorkflowTaskWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java index 67da44b0de..a78e7d684f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java @@ -28,21 +28,17 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; -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 SignalExternalWorkflowFailureTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestSignalExternalWorkflowFailure.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java index 0ab542c37e..c42f21fb20 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java @@ -25,7 +25,6 @@ import io.temporal.failure.CanceledFailure; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; @@ -33,14 +32,11 @@ import org.junit.Test; public class SignalExternalWorkflowImmediateCancellationTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestSignalExternalWorkflowImmediateCancellation.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java index 2c21d4ff50..0a390ba113 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java @@ -25,21 +25,17 @@ import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; public class SignalExternalWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestSignalExternalWorkflow.class, SignalingChildImpl.class) - .setActivityImplementations(activitiesImpl) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java index 691bcd037e..9baa95101e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java @@ -31,7 +31,6 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestOptions; import java.time.Duration; import java.util.ArrayList; @@ -47,14 +46,11 @@ public class SignalTest { private static final Logger log = LoggerFactory.getLogger(SignalTest.class); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestSignalWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .setTestTimeoutSeconds(15) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java index 113340cb37..f389d8c12b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java @@ -22,22 +22,18 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; public class UntypedSignalExternalWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( TestUntypedSignalExternalWorkflow.class, UntypedSignalingChildImpl.class) - .setActivityImplementations(activitiesImpl) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java index 020e889166..0dd5cd4479 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionAddNewBeforeTest.java @@ -22,7 +22,6 @@ import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assume; @@ -34,14 +33,11 @@ public class GetVersionAddNewBeforeTest { private static final Logger log = LoggerFactory.getLogger(GetVersionAddNewBeforeTest.class); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowAddNewBefore.class) - .setActivityImplementations(activitiesImpl) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java index 222332e257..4d53b949d3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdTest.java @@ -24,7 +24,6 @@ import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assume; @@ -33,14 +32,10 @@ public class GetVersionSameIdTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionSameId.class) - .setActivityImplementations(activitiesImpl) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java index 48c425cc60..2ca1844d80 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java @@ -26,7 +26,6 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import java.time.Duration; import java.util.concurrent.CompletableFuture; import org.junit.Assert; @@ -36,14 +35,11 @@ public class GetVersionWithoutCommandEventTest { private static CompletableFuture executionStarted = new CompletableFuture<>(); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWithoutCommandEventWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java index ff02692823..aeaf873793 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceCompletelyTest.java @@ -22,7 +22,6 @@ import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assume; @@ -35,14 +34,11 @@ public class GetVersionWorkflowReplaceCompletelyTest { private static final Logger log = LoggerFactory.getLogger(GetVersionWorkflowReplaceCompletelyTest.class); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowReplaceCompletely.class) - .setActivityImplementations(activitiesImpl) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java index 692204e830..4fab6e937e 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowReplaceGetVersionIdTest.java @@ -22,7 +22,6 @@ import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assume; @@ -35,14 +34,11 @@ public class GetVersionWorkflowReplaceGetVersionIdTest { private static final Logger log = LoggerFactory.getLogger(GetVersionWorkflowReplaceGetVersionIdTest.class); - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowReplaceGetVersionId.class) - .setActivityImplementations(activitiesImpl) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) From 41e71e412bf6373cc89a211eaa5d8ca2fc0c76ff Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Tue, 30 Mar 2021 23:38:29 -0700 Subject: [PATCH 16/21] Factored out execution history logic into the workflow rule. --- ...inaryChecksumSetWhenTaskCompletedTest.java | 18 ++------ .../workflow/UpsertSearchAttributesTest.java | 13 ++---- .../WorkflowTaskFailureBackoffTest.java | 15 +++---- .../workflow/WorkflowTaskNPEBackoffTest.java | 15 +++---- .../AbandonOnCancelActivityTest.java | 18 ++------ .../ChildWorkflowCancellationTest.java | 43 ++++--------------- .../workflow/shared/SDKTestWorkflowRule.java | 6 +-- .../GetVersionSameIdOnReplayTest.java | 13 ++---- .../io/temporal/testing/TestWorkflowRule.java | 17 +++++--- 9 files changed, 47 insertions(+), 111 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java index a385af49bb..3b99f02b4d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java @@ -25,16 +25,12 @@ 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.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowStub; -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 io.temporal.workflow.shared.*; import org.junit.Rule; import org.junit.Test; @@ -58,16 +54,10 @@ public void testBinaryChecksumSetWhenTaskCompleted() { WorkflowClient.start(client::execute, testWorkflowRule.getTaskQueue()); WorkflowStub stub = WorkflowStub.fromTyped(client); SDKTestWorkflowRule.waitForOKQuery(stub); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(execution) - .build(); - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); boolean foundCompletedTask = false; - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_COMPLETED) { assertEquals( SDKTestWorkflowRule.BINARY_CHECKSUM, diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java index d007d8951c..23b624e591 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java @@ -25,9 +25,8 @@ import io.temporal.api.common.v1.SearchAttributes; 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.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.client.WorkflowClient; import io.temporal.internal.common.SearchAttributesUtil; import io.temporal.testing.TracingWorkerInterceptor; @@ -70,16 +69,10 @@ public void testUpsertSearchAttributes() { "upsertSearchAttributes", "executeActivity Activity", "activity Activity"); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(execution) - .build(); - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); boolean found = false; - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { if (EventType.EVENT_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES == event.getEventType()) { found = true; break; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java index 3b1a7f66b7..f0263fece2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java @@ -19,10 +19,10 @@ package io.temporal.workflow; +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.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.workflow.shared.SDKTestWorkflowRule; @@ -61,16 +61,11 @@ public void testWorkflowTaskFailureBackoff() { long elapsed = testWorkflowRule.getTestEnvironment().currentTimeMillis() - start; Assert.assertTrue("spinned on fail workflow task", elapsed > 1000); Assert.assertEquals("result1", result); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(WorkflowStub.fromTyped(workflowStub).getExecution()) - .build(); - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); + WorkflowExecution execution = WorkflowStub.fromTyped(workflowStub).getExecution(); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); int failedTaskCount = 0; - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_FAILED) { failedTaskCount++; } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java index 6abe1cbd22..73da17de72 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskNPEBackoffTest.java @@ -19,10 +19,10 @@ package io.temporal.workflow; +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.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.workflow.shared.SDKTestWorkflowRule; @@ -59,16 +59,11 @@ public void testWorkflowTaskNPEBackoff() { long elapsed = testWorkflowRule.getTestEnvironment().currentTimeMillis() - start; Assert.assertTrue("spinned on fail workflow task", elapsed > 1000); Assert.assertEquals("result1", result); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(WorkflowStub.fromTyped(workflowStub).getExecution()) - .build(); - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); + WorkflowExecution execution = WorkflowStub.fromTyped(workflowStub).getExecution(); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); int failedTaskCount = 0; - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_FAILED) { failedTaskCount++; } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java index 7e7bbb6086..b0b873c0a7 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java @@ -23,18 +23,14 @@ 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.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; @@ -74,15 +70,9 @@ public void testAbandonOnCancelActivity() { long elapsed = testWorkflowRule.getTestEnvironment().currentTimeMillis() - start; Assert.assertTrue(String.valueOf(elapsed), elapsed < 500); activitiesImpl.assertInvocations("activityWithDelay"); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(testWorkflowRule.getTestEnvironment().getNamespace()) - .setExecution(execution) - .build(); - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { Assert.assertNotEquals( EventType.EVENT_TYPE_ACTIVITY_TASK_CANCEL_REQUESTED, event.getEventType()); } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java index 2640139d5c..21538e0553 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java @@ -21,9 +21,8 @@ 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.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; @@ -62,17 +61,11 @@ public void testChildWorkflowWaitCancellationRequested() { } catch (WorkflowFailedException e) { Assert.assertTrue(e.getCause() instanceof CanceledFailure); } - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(testWorkflowRule.getTestEnvironment().getNamespace()) - .setExecution(execution) - .build(); - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); boolean hasChildCanceled = false; boolean hasChildCancelRequested = false; - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { if (event.getEventType() == EventType.EVENT_TYPE_CHILD_WORKFLOW_EXECUTION_CANCELED) { hasChildCanceled = true; } @@ -98,16 +91,10 @@ public void testChildWorkflowWaitCancellationCompleted() { } catch (WorkflowFailedException e) { Assert.assertTrue(e.getCause() instanceof CanceledFailure); } - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(testWorkflowRule.getTestEnvironment().getNamespace()) - .setExecution(execution) - .build(); - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); boolean hasChildCanceled = false; - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { if (event.getEventType() == EventType.EVENT_TYPE_CHILD_WORKFLOW_EXECUTION_CANCELED) { hasChildCanceled = true; } @@ -127,16 +114,10 @@ public void testChildWorkflowCancellationAbandon() { } catch (WorkflowFailedException e) { Assert.assertTrue(e.getCause() instanceof CanceledFailure); } - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(testWorkflowRule.getTestEnvironment().getNamespace()) - .setExecution(execution) - .build(); - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); boolean hasChildCancelInitiated = false; - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { if (event.getEventType() == EventType.EVENT_TYPE_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED) { hasChildCancelInitiated = true; @@ -157,17 +138,11 @@ public void testChildWorkflowCancellationTryCancel() { } catch (WorkflowFailedException e) { Assert.assertTrue(e.getCause() instanceof CanceledFailure); } - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(testWorkflowRule.getTestEnvironment().getNamespace()) - .setExecution(execution) - .build(); - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); boolean hasChildCancelInitiated = false; boolean hasChildCancelRequested = false; - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { if (event.getEventType() == EventType.EVENT_TYPE_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED) { hasChildCancelInitiated = true; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java index 808a657660..004e847f3d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java @@ -26,6 +26,7 @@ import com.google.common.io.CharSink; import com.google.common.io.Files; import io.temporal.api.common.v1.WorkflowExecution; +import io.temporal.api.history.v1.History; import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.api.workflowservice.v1.WorkflowServiceGrpc; @@ -176,9 +177,8 @@ public String getTaskQueue() { return testWorkflowRule.getTaskQueue(); } - public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( - GetWorkflowExecutionHistoryRequest request) { - return testWorkflowRule.getWorkflowExecutionHistory(request); + public History getWorkflowExecutionHistory(WorkflowExecution execution) { + return testWorkflowRule.getWorkflowExecutionHistory(execution); } public WorkflowClient getWorkflowClient() { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java index 3ba0525613..941e4f3a51 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionSameIdOnReplayTest.java @@ -23,9 +23,8 @@ 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.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.client.WorkflowStub; import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.Workflow; @@ -57,16 +56,10 @@ public void testGetVersionSameIdOnReplay() { testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); workflowStub.execute(testWorkflowRule.getTaskQueue()); WorkflowExecution execution = WorkflowStub.fromTyped(workflowStub).getExecution(); - GetWorkflowExecutionHistoryRequest request = - GetWorkflowExecutionHistoryRequest.newBuilder() - .setNamespace(SDKTestWorkflowRule.NAMESPACE) - .setExecution(execution) - .build(); + History history = testWorkflowRule.getWorkflowExecutionHistory(execution); // Validate that no marker is recorded - GetWorkflowExecutionHistoryResponse response = - testWorkflowRule.getWorkflowExecutionHistory(request); - for (HistoryEvent event : response.getHistory().getEventsList()) { + for (HistoryEvent event : history.getEventsList()) { Assert.assertFalse(EventType.EVENT_TYPE_MARKER_RECORDED == event.getEventType()); } } diff --git a/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java b/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java index 45677f0b28..afce0b82a7 100644 --- a/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java +++ b/temporal-testing-junit4/src/main/java/io/temporal/testing/TestWorkflowRule.java @@ -19,8 +19,9 @@ package io.temporal.testing; +import io.temporal.api.common.v1.WorkflowExecution; +import io.temporal.api.history.v1.History; import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest; -import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; import io.temporal.api.workflowservice.v1.WorkflowServiceGrpc; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowClientOptions; @@ -73,6 +74,7 @@ public class TestWorkflowRule implements TestRule { private final WorkflowImplementationOptions workflowImplementationOptions; private final WorkerOptions workerOptions; private final WorkerFactoryOptions workerFactoryOptions; + private final String namespace; private final TestWorkflowEnvironment testEnvironment; private final TestWatcher watchman = new TestWatcher() { @@ -86,11 +88,10 @@ protected void failed(Throwable e, Description description) { private TestWorkflowRule(Builder builder) { - String namespace = (builder.namespace == null) ? "UnitTest" : builder.namespace; - doNotStart = builder.doNotStart; interceptors = builder.workerInterceptors; useExternalService = builder.useExternalService; + namespace = (builder.namespace == null) ? "UnitTest" : builder.namespace; workflowTypes = (builder.workflowTypes == null) ? new Class[0] : builder.workflowTypes; activityImplementations = (builder.activityImplementations == null) ? new Object[0] : builder.activityImplementations; @@ -304,9 +305,13 @@ public String getTaskQueue() { * * @return */ - public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( - GetWorkflowExecutionHistoryRequest request) { - return this.blockingStub().getWorkflowExecutionHistory(request); + public History getWorkflowExecutionHistory(WorkflowExecution execution) { + GetWorkflowExecutionHistoryRequest request = + GetWorkflowExecutionHistoryRequest.newBuilder() + .setNamespace(namespace) + .setExecution(execution) + .build(); + return this.blockingStub().getWorkflowExecutionHistory(request).getHistory(); } /** Returns client to the Temporal service used to start and query workflows. */ From b900865da77e618e5301e259066a64f74868018d Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Wed, 31 Mar 2021 00:25:55 -0700 Subject: [PATCH 17/21] Removed unnecessary activityImpl field --- .../java/io/temporal/workflow/ExceptionPropagationTest.java | 5 +---- .../NonDeterministicWorkflowPolicyFailWorkflowTest.java | 5 +---- .../src/test/java/io/temporal/workflow/SagaTest.java | 5 +---- .../src/test/java/io/temporal/workflow/SideEffectTest.java | 5 +---- .../test/java/io/temporal/workflow/UUIDAndRandomTest.java | 5 +---- .../io/temporal/workflow/UpsertSearchAttributesTest.java | 5 +---- .../ParallelLocalActivityExecutionWorkflowTest.java | 5 +---- .../workflow/activityTests/UntypedActivityRetryTest.java | 5 +---- .../temporal/workflow/signalTests/ExceptionInSignalTest.java | 4 +--- .../workflow/signalTests/SignalOrderingWorkflowTest.java | 4 +--- .../workflow/versionTests/GetVersionRemovedBeforeTest.java | 5 +---- .../workflow/versionTests/GetVersionRemovedInReplayTest.java | 5 +---- .../io/temporal/workflow/versionTests/GetVersionTest.java | 5 +---- .../workflow/versionTests/GetVersionWorkflowRemoveTest.java | 5 +---- .../workflow/versionTests/VersionNotSupportedTest.java | 5 +---- 15 files changed, 15 insertions(+), 58 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java index 747aa779d9..ca43b58850 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java @@ -40,9 +40,6 @@ public class ExceptionPropagationTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() @@ -53,7 +50,7 @@ public class ExceptionPropagationTest { .build(), ThrowingChild.class, TestExceptionPropagationImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .build(); /** diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java index 817954c123..c86ba2674b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java @@ -34,13 +34,10 @@ public class NonDeterministicWorkflowPolicyFailWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkflowTypes( WorkflowImplementationOptions.newBuilder() .setFailWorkflowExceptionTypes(Throwable.class) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java index 5cbb9d1c62..349a0e2169 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java @@ -31,9 +31,6 @@ public class SagaTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() @@ -41,7 +38,7 @@ public class SagaTest { TestSagaWorkflowImpl.class, TestCompensationWorkflowImpl.class, TestMultiargsWorkflowsFuncImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java index 3101a76652..18fb0a1f51 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SideEffectTest.java @@ -33,14 +33,11 @@ public class SideEffectTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestSideEffectWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java index 1b2345bfda..84a1e98d66 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/UUIDAndRandomTest.java @@ -33,14 +33,11 @@ public class UUIDAndRandomTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestUUIDAndRandom.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java index 23b624e591..84629d00fb 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/UpsertSearchAttributesTest.java @@ -41,14 +41,11 @@ public class UpsertSearchAttributesTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestUpsertSearchAttributesImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkerInterceptors( new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace())) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java index 33308a23eb..ecd81907d8 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivityExecutionWorkflowTest.java @@ -36,14 +36,11 @@ public class ParallelLocalActivityExecutionWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestParallelLocalActivityExecutionWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java index ab6bfb8e29..3a87f2d5bc 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java @@ -37,14 +37,11 @@ public class UntypedActivityRetryTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestUntypedActivityRetry.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java index 860ad0a849..23c63215a0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java @@ -37,14 +37,12 @@ import org.junit.Test; public class ExceptionInSignalTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestSignalExceptionWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setTestTimeoutSeconds(20) .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java index a2609e6f91..e885f0073b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalOrderingWorkflowTest.java @@ -38,14 +38,12 @@ import org.junit.Test; public class SignalOrderingWorkflowTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(SignalOrderingWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java index 8d56816817..0ae54b2073 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedBeforeTest.java @@ -35,14 +35,11 @@ public class GetVersionRemovedBeforeTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionRemovedBefore.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java index 4fb604fe15..203f94f1cf 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovedInReplayTest.java @@ -35,14 +35,11 @@ public class GetVersionRemovedInReplayTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionRemovedInReplay.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java index 567bfb288c..842fc58d77 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionTest.java @@ -36,14 +36,11 @@ public class GetVersionTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java index 56854cddf2..17e65b43e7 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWorkflowRemoveTest.java @@ -34,14 +34,11 @@ public class GetVersionWorkflowRemoveTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestGetVersionWorkflowRemove.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java index b1e8097573..6bd9065df4 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/VersionNotSupportedTest.java @@ -34,14 +34,11 @@ public class VersionNotSupportedTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); - @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestVersionNotSupportedWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) From faa1af39aa7985be14d50e71e71b28729e7730c3 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Wed, 31 Mar 2021 09:34:09 -0700 Subject: [PATCH 18/21] Fixed bug. --- .../workflow/activityTests/UntypedActivityRetryTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java index 3a87f2d5bc..ab6bfb8e29 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/UntypedActivityRetryTest.java @@ -37,11 +37,14 @@ public class UntypedActivityRetryTest { + private final TestActivities.TestActivitiesImpl activitiesImpl = + new TestActivities.TestActivitiesImpl(); + @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestUntypedActivityRetry.class) - .setActivityImplementations(new TestActivities.TestActivitiesImpl()) + .setActivityImplementations(activitiesImpl) .build(); @Test From 92ea7b3269bb7f21308bf6d7402f45c76bd61c18 Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Wed, 31 Mar 2021 15:13:57 -0700 Subject: [PATCH 19/21] Removed WorkflowTest! --- ...CommandsGeneratePlantUMLStateDiagrams.java | 4 +- .../sync/DeterministicRunnerTest.java | 3 +- .../temporal/workflow/DetachedScopeTest.java | 5 +- .../workflow/ExceptionPropagationTest.java | 5 +- .../GetAttemptFromWorkflowInfoTest.java | 4 +- .../LocalAsyncCompletionWorkflowTest.java | 47 ++-- .../workflow/NoQueryThreadLeakTest.java | 7 +- ...nisticWorkflowPolicyBlockWorkflowTest.java | 8 +- ...inisticWorkflowPolicyFailWorkflowTest.java | 8 +- .../workflow/ParentContinueAsNewTest.java | 7 +- .../java/io/temporal/workflow/SyncTest.java | 5 +- .../java/io/temporal/workflow/TimerTest.java | 1 + .../WorkflowFailureNonRetryableFlagTest.java | 7 +- .../WorkflowRetryDoNotRetryExceptionTest.java | 7 +- .../temporal/workflow/WorkflowRetryTest.java | 7 +- .../io/temporal/workflow/WorkflowTest.java | 236 ------------------ .../WorkflowWithCronScheduleTest.java | 11 +- .../activityTests/AsyncActivityTest.java | 5 +- .../AsyncUntyped2ActivityTest.java | 5 +- .../AsyncUntypedActivityTest.java | 5 +- ...alActivitiesWorkflowTaskHeartbeatTest.java | 5 +- .../activityTests/LocalActivityTest.java | 5 +- ...ivityWorkflowTaskHeartbeatFailureTest.java | 5 +- ...ocalActivityWorkflowTaskHeartbeatTest.java | 5 +- ...izableExceptionInActivityWorkflowTest.java | 4 +- .../ParallelLocalActivitiesTest.java | 5 +- .../activityTests/TryCancelActivityTest.java | 5 +- .../ChildWorkflowAsyncRetryTest.java | 16 +- .../ChildWorkflowCancellationTest.java | 14 +- ...ldWorkflowExecutionPromiseHandlerTest.java | 6 +- .../ChildWorkflowRetryTest.java | 11 +- .../childWorkflowTests/ChildWorkflowTest.java | 14 +- .../ChildWorkflowTimeoutTest.java | 8 +- .../ChildWorkflowWithCronScheduleTest.java | 12 +- .../childWorkflowTests/NamedChildTest.java | 11 +- ...ializableExceptionInChildWorkflowTest.java | 6 +- ...arentWorkflowInfoInChildWorkflowsTest.java | 5 +- ...hCancellationScopeAndCancelParentTest.java | 9 +- .../temporal/workflow/shared/AngryChild.java | 41 +++ .../DeterminismFailingWorkflowImpl.java | 35 +++ .../shared/NonSerializableException.java | 39 +++ .../workflow/shared/SignalQueryBase.java | 31 +++ .../temporal/workflow/shared/TestChild.java | 31 +++ .../TestMultiargsWorkflowsFuncParent.java | 46 ++++ .../TestWorkflowWithCronScheduleImpl.java | 69 +++++ .../workflow/shared/TestWorkflows.java | 81 +++++- .../signalTests/ExceptionInSignalTest.java | 9 +- .../SignalAndQueryInterfaceTest.java | 8 +- .../SignalAndQueryListenerTest.java | 7 +- .../SignalDuringLastWorkflowTaskTest.java | 8 +- .../SignalExternalWorkflowFailureTest.java | 5 +- ...rnalWorkflowImmediateCancellationTest.java | 4 +- .../SignalExternalWorkflowTest.java | 17 +- .../workflow/signalTests/SignalTest.java | 30 +-- .../UntypedSignalExternalWorkflowTest.java | 9 +- .../GetVersionWithoutCommandEventTest.java | 8 +- 56 files changed, 548 insertions(+), 463 deletions(-) delete mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/shared/AngryChild.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/shared/DeterminismFailingWorkflowImpl.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/shared/NonSerializableException.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/shared/SignalQueryBase.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/shared/TestChild.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/shared/TestMultiargsWorkflowsFuncParent.java create mode 100644 temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflowWithCronScheduleImpl.java diff --git a/temporal-sdk/src/test/java/io/temporal/internal/statemachines/CommandsGeneratePlantUMLStateDiagrams.java b/temporal-sdk/src/test/java/io/temporal/internal/statemachines/CommandsGeneratePlantUMLStateDiagrams.java index 804326b042..a6c5b8654a 100644 --- a/temporal-sdk/src/test/java/io/temporal/internal/statemachines/CommandsGeneratePlantUMLStateDiagrams.java +++ b/temporal-sdk/src/test/java/io/temporal/internal/statemachines/CommandsGeneratePlantUMLStateDiagrams.java @@ -23,7 +23,6 @@ import com.google.common.io.CharSink; import com.google.common.io.Files; import io.temporal.workflow.Functions; -import io.temporal.workflow.WorkflowTest; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -35,7 +34,8 @@ public class CommandsGeneratePlantUMLStateDiagrams { - private static final Logger log = LoggerFactory.getLogger(WorkflowTest.class); + private static final Logger log = + LoggerFactory.getLogger(CommandsGeneratePlantUMLStateDiagrams.class); @Test public void plantUML() { diff --git a/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java b/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java index 48893ed7cc..6950fde93a 100644 --- a/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java @@ -51,7 +51,6 @@ import io.temporal.workflow.Functions; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -127,7 +126,7 @@ public void testYield() throws Throwable { * Async retry cannot be tested here as it relies on timer that is implemented outside of * Dispatcher. * - * @see WorkflowTest#testAsyncRetry() + * @see activityTests.AsyncRetryTest#testAsyncRetry() */ @Test @Ignore // timer removed from dispatcher diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java index 76f4b83ac4..a531ceb55f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java @@ -25,10 +25,7 @@ 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 io.temporal.workflow.shared.*; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java index ca43b58850..1efd2fc5d0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java @@ -27,10 +27,7 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.failure.ChildWorkflowFailure; import io.temporal.worker.WorkflowImplementationOptions; -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 io.temporal.workflow.shared.*; import java.io.FileNotFoundException; import java.io.IOException; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java index ba1fb6964e..ec94606fd2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/GetAttemptFromWorkflowInfoTest.java @@ -21,6 +21,7 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestMultiargsWorkflowsFuncParent; import io.temporal.workflow.shared.TestOptions; import org.junit.Assert; import org.junit.Rule; @@ -32,8 +33,7 @@ public class GetAttemptFromWorkflowInfoTest { public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( - WorkflowTest.TestMultiargsWorkflowsFuncParent.class, - TestAttemptReturningWorkflowFunc.class) + TestMultiargsWorkflowsFuncParent.class, TestAttemptReturningWorkflowFunc.class) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/LocalAsyncCompletionWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/LocalAsyncCompletionWorkflowTest.java index 879058c112..03011a0a97 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/LocalAsyncCompletionWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/LocalAsyncCompletionWorkflowTest.java @@ -19,12 +19,7 @@ package io.temporal.workflow; -import io.temporal.activity.Activity; -import io.temporal.activity.ActivityExecutionContext; -import io.temporal.activity.ActivityInterface; -import io.temporal.activity.ActivityMethod; -import io.temporal.activity.ActivityOptions; -import io.temporal.activity.ManualActivityCompletionClient; +import io.temporal.activity.*; import io.temporal.common.RetryOptions; import io.temporal.worker.WorkerOptions; import io.temporal.workflow.shared.SDKTestWorkflowRule; @@ -54,6 +49,19 @@ public class LocalAsyncCompletionWorkflowTest { .setTestTimeoutSeconds(15) .build(); + /** + * This test runs 10 async activities in parallel. The expectation is that + * MAX_CONCURRENT_ACTIVITIES limit is being respected and only 1 activity should be running at the + * same time. + */ + @Test + public void verifyLocalActivityCompletionRespectsConcurrencySettings() { + String taskQueue = testWorkflowRule.getTaskQueue(); + TestWorkflow workflow = testWorkflowRule.newWorkflowStub(TestWorkflow.class); + String result = workflow.execute(taskQueue); + Assert.assertEquals("success", result); + } + @WorkflowInterface public interface TestWorkflow { @@ -61,6 +69,13 @@ public interface TestWorkflow { String execute(String taskQueue); } + @ActivityInterface + public interface TestActivity { + + @ActivityMethod + int execute(int value); + } + public static class TestWorkflowImpl implements TestWorkflow { @Override @@ -91,13 +106,6 @@ public String execute(String taskQueue) { } } - @ActivityInterface - public interface TestActivity { - - @ActivityMethod - int execute(int value); - } - public static class AsyncActivityWithManualCompletion implements TestActivity { private final AtomicInteger concurrentActivitiesCount = new AtomicInteger(0); @@ -129,17 +137,4 @@ private void asyncActivityFn(int value, ManualActivityCompletionClient completio } } } - - /** - * This test runs 10 async activities in parallel. The expectation is that - * MAX_CONCURRENT_ACTIVITIES limit is being respected and only 1 activity should be running at the - * same time. - */ - @Test - public void verifyLocalActivityCompletionRespectsConcurrencySettings() { - String taskQueue = testWorkflowRule.getTaskQueue(); - TestWorkflow workflow = testWorkflowRule.newWorkflowStub(TestWorkflow.class); - String result = workflow.execute(taskQueue); - Assert.assertEquals("success", result); - } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java index 1929e5f17b..8522254234 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NoQueryThreadLeakTest.java @@ -22,6 +22,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowStub; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestWorkflows; import java.lang.management.ManagementFactory; import java.time.Duration; import org.junit.Assert; @@ -37,8 +38,8 @@ public class NoQueryThreadLeakTest { @Test public void testNoQueryThreadLeak() throws InterruptedException { int threadCount = ManagementFactory.getThreadMXBean().getThreadCount(); - WorkflowTest.QueryableWorkflow client = - testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.QueryableWorkflow.class); + TestWorkflows.QueryableWorkflow client = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.QueryableWorkflow.class); WorkflowClient.start(client::execute); testWorkflowRule.sleep(Duration.ofSeconds(1)); // Calls query multiple times to check at the end of the method that if it doesn't leak threads @@ -57,7 +58,7 @@ public void testNoQueryThreadLeak() throws InterruptedException { Assert.assertTrue("query leaks threads: " + threadsCreated, threadsCreated < queryCount); } - public static class TestNoQueryWorkflowImpl implements WorkflowTest.QueryableWorkflow { + public static class TestNoQueryWorkflowImpl implements TestWorkflows.QueryableWorkflow { CompletablePromise promise = Workflow.newPromise(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java index 24f8e0c381..7bf8bc0f4c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyBlockWorkflowTest.java @@ -23,7 +23,9 @@ import io.temporal.client.WorkflowOptions; import io.temporal.failure.TimeoutFailure; import io.temporal.worker.WorkerFactoryOptions; +import io.temporal.workflow.shared.DeterminismFailingWorkflowImpl; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestWorkflows; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.time.Duration; @@ -36,7 +38,7 @@ public class NonDeterministicWorkflowPolicyBlockWorkflowTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(WorkflowTest.DeterminismFailingWorkflowImpl.class) + .setWorkflowTypes(DeterminismFailingWorkflowImpl.class) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) @@ -51,10 +53,10 @@ public void testNonDeterministicWorkflowPolicyBlockWorkflow() { .setWorkflowTaskTimeout(Duration.ofSeconds(1)) .setTaskQueue(testWorkflowRule.getTaskQueue()) .build(); - WorkflowTest.DeterminismFailingWorkflow workflowStub = + TestWorkflows.DeterminismFailingWorkflow workflowStub = testWorkflowRule .getWorkflowClient() - .newWorkflowStub(WorkflowTest.DeterminismFailingWorkflow.class, options); + .newWorkflowStub(TestWorkflows.DeterminismFailingWorkflow.class, options); try { workflowStub.execute(testWorkflowRule.getTaskQueue()); Assert.fail("unreachable"); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java index c86ba2674b..f742626bd4 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/NonDeterministicWorkflowPolicyFailWorkflowTest.java @@ -25,8 +25,10 @@ import io.temporal.internal.replay.InternalWorkflowTaskException; import io.temporal.worker.WorkerFactoryOptions; import io.temporal.worker.WorkflowImplementationOptions; +import io.temporal.workflow.shared.DeterminismFailingWorkflowImpl; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; @@ -42,7 +44,7 @@ public class NonDeterministicWorkflowPolicyFailWorkflowTest { WorkflowImplementationOptions.newBuilder() .setFailWorkflowExceptionTypes(Throwable.class) .build(), - WorkflowTest.DeterminismFailingWorkflowImpl.class) + DeterminismFailingWorkflowImpl.class) .setWorkerFactoryOptions( WorkerFactoryOptions.newBuilder() .setWorkflowHostLocalTaskQueueScheduleToStartTimeout(Duration.ZERO) @@ -57,10 +59,10 @@ public void testNonDeterministicWorkflowPolicyFailWorkflow() { .setWorkflowTaskTimeout(Duration.ofSeconds(1)) .setTaskQueue(testWorkflowRule.getTaskQueue()) .build(); - WorkflowTest.DeterminismFailingWorkflow workflowStub = + TestWorkflows.DeterminismFailingWorkflow workflowStub = testWorkflowRule .getWorkflowClient() - .newWorkflowStub(WorkflowTest.DeterminismFailingWorkflow.class, options); + .newWorkflowStub(TestWorkflows.DeterminismFailingWorkflow.class, options); try { workflowStub.execute(testWorkflowRule.getTaskQueue()); Assert.fail("unreachable"); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java index 1a02e6f7d1..d089ebaba9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java @@ -21,6 +21,7 @@ import io.temporal.api.enums.v1.WorkflowIdReusePolicy; import io.temporal.client.WorkflowOptions; +import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; @@ -33,7 +34,7 @@ public class ParentContinueAsNewTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestParentWorkflowContinueAsNew.class, WorkflowTest.TestChild.class) + .setWorkflowTypes(TestParentWorkflowContinueAsNew.class, TestChild.class) .build(); /** Reproduction of a bug when a child of continued as new workflow has the same UUID ID. */ @@ -55,9 +56,9 @@ public void testParentContinueAsNew() { public static class TestParentWorkflowContinueAsNew implements TestWorkflows.TestWorkflow1 { - private final WorkflowTest.ITestChild child1 = + private final TestWorkflows.ITestChild child1 = Workflow.newChildWorkflowStub( - WorkflowTest.ITestChild.class, + TestWorkflows.ITestChild.class, ChildWorkflowOptions.newBuilder() .setWorkflowIdReusePolicy( WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java index 73a1c62f3b..ad79b5a30c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java @@ -28,10 +28,7 @@ import io.temporal.failure.CanceledFailure; import io.temporal.failure.TerminatedFailure; import io.temporal.testing.TracingWorkerInterceptor; -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 io.temporal.workflow.shared.*; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java index 38609b1b8f..9c10f10806 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java @@ -23,6 +23,7 @@ import io.temporal.client.WorkflowOptions; import io.temporal.testing.TracingWorkerInterceptor; +import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestOptions; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java index 347e6e67e0..3d87f3fa74 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowFailureNonRetryableFlagTest.java @@ -24,6 +24,7 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestOptions; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -51,11 +52,11 @@ public void testWorkflowFailureNonRetryableFlag() { .setMaximumAttempts(100) .setBackoffCoefficient(1.0) .build(); - WorkflowTest.TestWorkflowRetry workflowStub = + TestWorkflows.TestWorkflowRetry workflowStub = testWorkflowRule .getWorkflowClient() .newWorkflowStub( - WorkflowTest.TestWorkflowRetry.class, + TestWorkflows.TestWorkflowRetry.class, TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) .toBuilder() .setRetryOptions(workflowRetryOptions) @@ -76,7 +77,7 @@ public void testWorkflowFailureNonRetryableFlag() { } } - public static class TestWorkflowNonRetryableFlag implements WorkflowTest.TestWorkflowRetry { + public static class TestWorkflowNonRetryableFlag implements TestWorkflows.TestWorkflowRetry { @Override public String execute(String testName) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java index 8699ef5004..dbec69bea4 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryDoNotRetryExceptionTest.java @@ -24,6 +24,7 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestOptions; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -54,11 +55,11 @@ public void testWorkflowRetryDoNotRetryException() { .setMaximumAttempts(100) .setBackoffCoefficient(1.0) .build(); - WorkflowTest.TestWorkflowRetry workflowStub = + TestWorkflows.TestWorkflowRetry workflowStub = testWorkflowRule .getWorkflowClient() .newWorkflowStub( - WorkflowTest.TestWorkflowRetry.class, + TestWorkflows.TestWorkflowRetry.class, TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) .toBuilder() .setRetryOptions(workflowRetryOptions) @@ -76,7 +77,7 @@ public void testWorkflowRetryDoNotRetryException() { } public static class TestWorkflowRetryDoNotRetryException - implements WorkflowTest.TestWorkflowRetry { + implements TestWorkflows.TestWorkflowRetry { @Override public String execute(String testName) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java index ff6f9190ab..497c88c9bc 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRetryTest.java @@ -26,6 +26,7 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestOptions; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -53,11 +54,11 @@ public void testWorkflowRetry() { .setMaximumAttempts(3) .setBackoffCoefficient(1.0) .build(); - WorkflowTest.TestWorkflowRetry workflowStub = + TestWorkflows.TestWorkflowRetry workflowStub = testWorkflowRule .getWorkflowClient() .newWorkflowStub( - WorkflowTest.TestWorkflowRetry.class, + TestWorkflows.TestWorkflowRetry.class, TestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()) .toBuilder() .setRetryOptions(workflowRetryOptions) @@ -78,7 +79,7 @@ public void testWorkflowRetry() { } } - public static class TestWorkflowRetryImpl implements WorkflowTest.TestWorkflowRetry { + public static class TestWorkflowRetryImpl implements TestWorkflows.TestWorkflowRetry { @Override public String execute(String testName) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java deleted file mode 100644 index 49f5c24d98..0000000000 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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.activity.Activity; -import io.temporal.activity.ActivityOptions; -import io.temporal.common.CronSchedule; -import io.temporal.failure.ApplicationFailure; -import io.temporal.workflow.shared.TestActivities; -import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; -import io.temporal.workflow.shared.TestOptions; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.text.SimpleDateFormat; -import java.time.Duration; -import java.util.Date; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; -import org.slf4j.Logger; - -public class WorkflowTest { - - private static final Map retryCount = new ConcurrentHashMap<>(); - public static String lastCompletionResult; - static Optional lastFail; - - @WorkflowInterface - public interface TestWorkflowSignaled { - - @WorkflowMethod - String execute(); - - @SignalMethod(name = "testSignal") - void signal1(String arg); - } - - @WorkflowInterface - public interface TestWorkflow { - @WorkflowMethod - void execute(ChildWorkflowCancellationType cancellationType); - } - - @WorkflowInterface - public interface TestChildWorkflow { - @WorkflowMethod - void execute(); - } - - @WorkflowInterface - public interface QueryableWorkflow { - - @WorkflowMethod - String execute(); - - @QueryMethod - String getState(); - - @SignalMethod(name = "testSignal") - void mySignal(String value); - } - - @WorkflowInterface - public interface ITestChild { - - @WorkflowMethod - String execute(String arg, int delay); - } - - @WorkflowInterface - public interface ITestNamedChild { - - @WorkflowMethod(name = "namedChild") - String execute(String arg); - } - - @WorkflowInterface - public interface SignalingChild { - - @WorkflowMethod - String execute(String arg, String parentWorkflowId); - } - - @WorkflowInterface - public interface TestWorkflowRetry { - - @WorkflowMethod - String execute(String testName); - } - - @WorkflowInterface - public interface TestWorkflowWithCronSchedule { - @WorkflowMethod - @CronSchedule("0 * * * *") - String execute(String testName); - } - - @WorkflowInterface - public interface DeterminismFailingWorkflow { - @WorkflowMethod - void execute(String taskQueue); - } - - public interface SignalQueryBase { - @SignalMethod - void signal(String arg); - - @QueryMethod - String getSignal(); - } - - public static class TestChild implements ITestChild { - - @Override - public String execute(String arg, int delay) { - Workflow.sleep(delay); - return arg.toUpperCase(); - } - } - - public static class AngryChild implements ITestChild { - - @Override - public String execute(String taskQueue, int delay) { - TestActivities.AngryChildActivity activity = - Workflow.newActivityStub( - TestActivities.AngryChildActivity.class, - ActivityOptions.newBuilder() - .setTaskQueue(taskQueue) - .setScheduleToCloseTimeout(Duration.ofSeconds(5)) - .build()); - activity.execute(); - throw ApplicationFailure.newFailure("simulated failure", "test"); - } - } - - public static class TestWorkflowWithCronScheduleImpl implements TestWorkflowWithCronSchedule { - - @Override - public String execute(String testName) { - Logger log = Workflow.getLogger(TestWorkflowWithCronScheduleImpl.class); - - if (CancellationScope.current().isCancelRequested()) { - log.debug("TestWorkflowWithCronScheduleImpl run canceled."); - return null; - } - - lastCompletionResult = Workflow.getLastCompletionResult(String.class); - lastFail = Workflow.getPreviousRunFailure(); - - AtomicInteger count = retryCount.get(testName); - if (count == null) { - count = new AtomicInteger(); - retryCount.put(testName, count); - } - int c = count.incrementAndGet(); - - if (c == 3) { - throw ApplicationFailure.newFailure("simulated error", "test"); - } - - SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS"); - Date now = new Date(Workflow.currentTimeMillis()); - log.debug("TestWorkflowWithCronScheduleImpl run at " + sdf.format(now)); - return "run " + c; - } - } - - public static class DeterminismFailingWorkflowImpl implements DeterminismFailingWorkflow { - - @Override - public void execute(String taskQueue) { - TestActivities activities = - Workflow.newActivityStub( - TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); - if (!Workflow.isReplaying()) { - activities.activity1(1); - } - } - } - - public static class NonSerializableException extends RuntimeException { - @SuppressWarnings("unused") - private final InputStream file; // gson chokes on this field - - public NonSerializableException() { - try { - file = new FileInputStream(File.createTempFile("foo", "bar")); - } catch (IOException e) { - throw Activity.wrap(e); - } - } - } - - public static class TestMultiargsWorkflowsFuncParent - implements TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc { - @Override - public String func() { - ChildWorkflowOptions workflowOptions = - ChildWorkflowOptions.newBuilder() - .setWorkflowRunTimeout(Duration.ofSeconds(100)) - .setWorkflowTaskTimeout(Duration.ofSeconds(60)) - .build(); - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2 child = - Workflow.newChildWorkflowStub( - TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2.class, workflowOptions); - - Optional parentWorkflowId = Workflow.getInfo().getParentWorkflowId(); - String childsParentWorkflowId = child.func2(null, 0); - - String result = - String.format("%s - %s", parentWorkflowId.isPresent(), childsParentWorkflowId); - return result; - } - } -} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java index ddb88d47fd..bec097bb36 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowWithCronScheduleTest.java @@ -19,7 +19,6 @@ package io.temporal.workflow; -import static io.temporal.workflow.WorkflowTest.*; import static io.temporal.workflow.shared.TestOptions.newWorkflowOptionsWithTimeouts; import static org.junit.Assert.*; @@ -27,6 +26,7 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestWorkflowWithCronScheduleImpl; import java.time.Duration; import org.junit.Assume; import org.junit.Rule; @@ -40,7 +40,7 @@ public class WorkflowWithCronScheduleTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(WorkflowTest.TestWorkflowWithCronScheduleImpl.class) + .setWorkflowTypes(TestWorkflowWithCronScheduleImpl.class) .build(); @Test @@ -70,9 +70,10 @@ public void testWorkflowWithCronSchedule() { } // Run 3 failed. So on run 4 we get the last completion result from run 2. - assertEquals("run 2", lastCompletionResult); + assertEquals("run 2", TestWorkflowWithCronScheduleImpl.lastCompletionResult); // The last failure ought to be the one from run 3 - assertTrue(lastFail.isPresent()); - assertTrue(lastFail.get().getMessage().contains("simulated error")); + assertTrue(TestWorkflowWithCronScheduleImpl.lastFail.isPresent()); + assertTrue( + TestWorkflowWithCronScheduleImpl.lastFail.get().getMessage().contains("simulated error")); } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java index e11654d1d6..4a2b9e1993 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java @@ -24,10 +24,7 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import java.util.ArrayList; import java.util.List; import java.util.UUID; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java index d5f1b91565..57f9726c65 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java @@ -24,10 +24,7 @@ import io.temporal.workflow.ActivityStub; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java index f261694394..4420398a4b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java @@ -25,10 +25,7 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java index fbebbceaab..d7e45448c6 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java @@ -22,10 +22,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import java.time.Duration; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java index 7e3239c914..e9f76a2cc0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java @@ -26,10 +26,7 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import java.io.IOException; import org.junit.Assert; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java index 957a9ce726..2d98d875d9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java @@ -21,10 +21,7 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java index 6d66276598..67d1a8affc 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java @@ -21,10 +21,7 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java index 510116e607..de8436df20 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/NonSerializableExceptionInActivityWorkflowTest.java @@ -23,7 +23,7 @@ import io.temporal.activity.ActivityOptions; import io.temporal.failure.ActivityFailure; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.shared.NonSerializableException; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; @@ -62,7 +62,7 @@ public static class NonSerializableExceptionActivityImpl @Override public void execute() { - throw new WorkflowTest.NonSerializableException(); + throw new NonSerializableException(); } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java index 740612a698..a7963e9ba9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java @@ -24,10 +24,7 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import java.time.Duration; import java.util.ArrayList; import java.util.List; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java index 907421d5f6..3d6c7e9ae3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java @@ -26,10 +26,7 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.Workflow; -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 io.temporal.workflow.shared.*; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java index 4e7c9a55f7..e8fcaf10de 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java @@ -27,13 +27,8 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.failure.ChildWorkflowFailure; import io.temporal.testing.WorkflowReplayer; -import io.temporal.workflow.Async; -import io.temporal.workflow.ChildWorkflowOptions; -import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; -import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; -import io.temporal.workflow.shared.TestWorkflows; +import io.temporal.workflow.*; +import io.temporal.workflow.shared.*; import java.time.Duration; import org.junit.Assume; import org.junit.Rule; @@ -47,8 +42,7 @@ public class ChildWorkflowAsyncRetryTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes( - TestChildWorkflowAsyncRetryWorkflow.class, WorkflowTest.AngryChild.class) + .setWorkflowTypes(TestChildWorkflowAsyncRetryWorkflow.class, AngryChild.class) .setActivityImplementations(angryChildActivity) .build(); @@ -89,7 +83,7 @@ public void testAlteredWorkflowReplayFailure() throws Exception { public static class TestChildWorkflowAsyncRetryWorkflow implements TestWorkflows.TestWorkflow1 { - private WorkflowTest.ITestChild child; + private TestWorkflows.ITestChild child; public TestChildWorkflowAsyncRetryWorkflow() {} @@ -107,7 +101,7 @@ public String execute(String taskQueue) { .setMaximumAttempts(3) .build()) .build(); - child = Workflow.newChildWorkflowStub(WorkflowTest.ITestChild.class, options); + child = Workflow.newChildWorkflowStub(TestWorkflows.ITestChild.class, options); return Async.function(child::execute, taskQueue, 0).get(); } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java index 21538e0553..f2591f6d6f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowCancellationTest.java @@ -29,23 +29,21 @@ import io.temporal.workflow.ChildWorkflowCancellationType; import io.temporal.workflow.ChildWorkflowOptions; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; public class ChildWorkflowCancellationTest { - private final TestActivities.TestActivitiesImpl activitiesImpl = - new TestActivities.TestActivitiesImpl(); @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes(TestParentWorkflowImpl.class, TestChildWorkflowImpl.class) - .setActivityImplementations(activitiesImpl) + .setActivityImplementations(new TestActivities.TestActivitiesImpl()) .build(); @Test @@ -156,19 +154,19 @@ public void testChildWorkflowCancellationTryCancel() { Assert.assertFalse(hasChildCancelRequested); } - public static class TestParentWorkflowImpl implements WorkflowTest.TestWorkflow { + public static class TestParentWorkflowImpl implements TestWorkflows.TestWorkflow { @Override public void execute(ChildWorkflowCancellationType cancellationType) { - WorkflowTest.TestChildWorkflow child = + TestWorkflows.TestChildWorkflow child = Workflow.newChildWorkflowStub( - WorkflowTest.TestChildWorkflow.class, + TestWorkflows.TestChildWorkflow.class, ChildWorkflowOptions.newBuilder().setCancellationType(cancellationType).build()); child.execute(); } } - public static class TestChildWorkflowImpl implements WorkflowTest.TestChildWorkflow { + public static class TestChildWorkflowImpl implements TestWorkflows.TestChildWorkflow { @Override public void execute() { try { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java index b2820af6d1..39f18bb22c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java @@ -55,7 +55,7 @@ public void testChildWorkflowExecutionPromiseHandler() { assertEquals("FOO", result); } - public static class TestNamedChild implements WorkflowTest.ITestNamedChild { + public static class TestNamedChild implements TestWorkflows.ITestNamedChild { @Override public String execute(String arg) { @@ -66,11 +66,11 @@ public String execute(String arg) { public static class TestChildWorkflowExecutionPromiseHandler implements TestWorkflows.TestWorkflow1 { - private WorkflowTest.ITestNamedChild child; + private TestWorkflows.ITestNamedChild child; @Override public String execute(String taskQueue) { - child = Workflow.newChildWorkflowStub(WorkflowTest.ITestNamedChild.class); + child = Workflow.newChildWorkflowStub(TestWorkflows.ITestNamedChild.class); Promise childResult = Async.function(child::execute, "foo"); Promise executionPromise = Workflow.getWorkflowExecution(child); CompletablePromise result = Workflow.newPromise(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java index 42f3be7e78..5fcf566281 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java @@ -38,10 +38,7 @@ import io.temporal.worker.WorkflowImplementationOptions; import io.temporal.workflow.ChildWorkflowOptions; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; -import io.temporal.workflow.shared.SDKTestWorkflowRule; -import io.temporal.workflow.shared.TestActivities; -import io.temporal.workflow.shared.TestWorkflows; +import io.temporal.workflow.shared.*; import java.time.Duration; import java.util.concurrent.atomic.AtomicReference; import org.junit.Assume; @@ -62,7 +59,7 @@ public class ChildWorkflowRetryTest { .setFailWorkflowExceptionTypes(UnsupportedOperationException.class) .build(), TestChildWorkflowRetryWorkflow.class, - WorkflowTest.AngryChild.class) + AngryChild.class) .setActivityImplementations(angryChildActivity) .setWorkflowClientOptions( WorkflowClientOptions.newBuilder() @@ -139,7 +136,7 @@ public void testChildWorkflowRetryReplay() throws Exception { public static class TestChildWorkflowRetryWorkflow implements TestWorkflows.TestWorkflow1 { - private WorkflowTest.ITestChild child; + private TestWorkflows.ITestChild child; public TestChildWorkflowRetryWorkflow() {} @@ -157,7 +154,7 @@ public String execute(String taskQueue) { .setMaximumAttempts(3) .build()) .build(); - child = Workflow.newChildWorkflowStub(WorkflowTest.ITestChild.class, options); + child = Workflow.newChildWorkflowStub(TestWorkflows.ITestChild.class, options); return child.execute(taskQueue, 0); } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java index 68362d3e95..81e214c8c3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java @@ -23,6 +23,7 @@ import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestChild; import io.temporal.workflow.shared.TestWorkflows; import java.util.UUID; import org.junit.Rule; @@ -35,8 +36,7 @@ public class ChildWorkflowTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes( - TestParentWorkflow.class, TestNamedChild.class, WorkflowTest.TestChild.class) + .setWorkflowTypes(TestParentWorkflow.class, TestNamedChild.class, TestChild.class) .build(); @Test @@ -47,7 +47,7 @@ public void testChildWorkflow() { assertEquals("HELLO WORLD!", client.execute(testWorkflowRule.getTaskQueue())); } - public static class TestNamedChild implements WorkflowTest.ITestNamedChild { + public static class TestNamedChild implements TestWorkflows.ITestNamedChild { @Override public String execute(String arg) { return arg.toUpperCase(); @@ -56,14 +56,14 @@ public String execute(String arg) { public static class TestParentWorkflow implements TestWorkflows.TestWorkflow1 { - private final WorkflowTest.ITestChild child1 = - Workflow.newChildWorkflowStub(WorkflowTest.ITestChild.class); - private final WorkflowTest.ITestNamedChild child2; + private final TestWorkflows.ITestChild child1 = + Workflow.newChildWorkflowStub(TestWorkflows.ITestChild.class); + private final TestWorkflows.ITestNamedChild child2; public TestParentWorkflow() { ChildWorkflowOptions options = ChildWorkflowOptions.newBuilder().setWorkflowId(child2Id).build(); - child2 = Workflow.newChildWorkflowStub(WorkflowTest.ITestNamedChild.class, options); + child2 = Workflow.newChildWorkflowStub(TestWorkflows.ITestNamedChild.class, options); } @Override diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java index 78cbd4fea0..4d2e0a6d66 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java @@ -24,7 +24,7 @@ import com.google.common.base.Throwables; import io.temporal.workflow.ChildWorkflowOptions; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; @@ -36,7 +36,7 @@ public class ChildWorkflowTimeoutTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes(TestParentWorkflowWithChildTimeout.class, WorkflowTest.TestChild.class) + .setWorkflowTypes(TestParentWorkflowWithChildTimeout.class, TestChild.class) .build(); @Test @@ -50,12 +50,12 @@ public void testChildWorkflowTimeout() { public static class TestParentWorkflowWithChildTimeout implements TestWorkflows.TestWorkflow1 { - private final WorkflowTest.ITestChild child; + private final TestWorkflows.ITestChild child; public TestParentWorkflowWithChildTimeout() { ChildWorkflowOptions options = ChildWorkflowOptions.newBuilder().setWorkflowRunTimeout(Duration.ofSeconds(1)).build(); - child = Workflow.newChildWorkflowStub(WorkflowTest.ITestChild.class, options); + child = Workflow.newChildWorkflowStub(TestWorkflows.ITestChild.class, options); } @Override diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java index ee065e786a..f9bfc33862 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java @@ -19,7 +19,6 @@ package io.temporal.workflow.childWorkflowTests; -import static io.temporal.workflow.WorkflowTest.lastCompletionResult; import static io.temporal.workflow.shared.TestOptions.newWorkflowOptionsWithTimeouts; import static org.junit.Assert.*; @@ -27,7 +26,7 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; @@ -43,8 +42,7 @@ public class ChildWorkflowWithCronScheduleTest { @Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() - .setWorkflowTypes( - TestCronParentWorkflow.class, WorkflowTest.TestWorkflowWithCronScheduleImpl.class) + .setWorkflowTypes(TestCronParentWorkflow.class, TestWorkflowWithCronScheduleImpl.class) .build(); @Test @@ -74,12 +72,12 @@ public void testChildWorkflowWithCronSchedule() { } // Run 3 failed. So on run 4 we get the last completion result from run 2. - assertEquals("run 2", lastCompletionResult); + assertEquals("run 2", TestWorkflowWithCronScheduleImpl.lastCompletionResult); } public static class TestCronParentWorkflow implements TestWorkflows.TestWorkflow1 { - private final WorkflowTest.TestWorkflowWithCronSchedule cronChild = - Workflow.newChildWorkflowStub(WorkflowTest.TestWorkflowWithCronSchedule.class); + private final TestWorkflows.TestWorkflowWithCronSchedule cronChild = + Workflow.newChildWorkflowStub(TestWorkflows.TestWorkflowWithCronSchedule.class); @Override public String execute(String taskQueue) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java index 4ccef2ee73..e122e19ae5 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java @@ -26,6 +26,7 @@ import io.temporal.failure.ChildWorkflowFailure; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestWorkflows; import java.util.UUID; import org.junit.Rule; import org.junit.Test; @@ -80,7 +81,7 @@ public interface WorkflowIdReusePolicyParent { String execute(boolean parallel, WorkflowIdReusePolicy policy); } - public static class TestNamedChild implements WorkflowTest.ITestNamedChild { + public static class TestNamedChild implements TestWorkflows.ITestNamedChild { @Override public String execute(String arg) { @@ -100,15 +101,15 @@ public String execute(boolean parallel, WorkflowIdReusePolicy policy) { .setWorkflowIdReusePolicy(policy) .build(); - WorkflowTest.ITestNamedChild child1 = - Workflow.newChildWorkflowStub(WorkflowTest.ITestNamedChild.class, options); + TestWorkflows.ITestNamedChild child1 = + Workflow.newChildWorkflowStub(TestWorkflows.ITestNamedChild.class, options); Promise r1P = Async.function(child1::execute, "Hello "); String r1 = null; if (!parallel) { r1 = r1P.get(); } - WorkflowTest.ITestNamedChild child2 = - Workflow.newChildWorkflowStub(WorkflowTest.ITestNamedChild.class, options); + TestWorkflows.ITestNamedChild child2 = + Workflow.newChildWorkflowStub(TestWorkflows.ITestNamedChild.class, options); ChildWorkflowStub child2Stub = ChildWorkflowStub.fromTyped(child2); // Same as String r2 = child2.execute("World!"); String r2 = child2Stub.execute(String.class, "World!"); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java index ab012adb0d..ffedabc53a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java @@ -24,7 +24,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; -import io.temporal.workflow.WorkflowTest; +import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import org.junit.Assert; @@ -38,7 +38,7 @@ public class NonSerializableExceptionInChildWorkflowTest { SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( WorkflowImplementationOptions.newBuilder() - .setFailWorkflowExceptionTypes(WorkflowTest.NonSerializableException.class) + .setFailWorkflowExceptionTypes(NonSerializableException.class) .build(), TestNonSerializableExceptionInChildWorkflow.class, NonSerializableExceptionChildWorkflowImpl.class) @@ -64,7 +64,7 @@ public static class NonSerializableExceptionChildWorkflowImpl @Override public String execute(String taskQueue) { - throw new WorkflowTest.NonSerializableException(); + throw new NonSerializableException(); } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java index 4c73189cc0..c1c0490ac1 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ParentWorkflowInfoInChildWorkflowsTest.java @@ -22,9 +22,9 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInfo; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions; +import io.temporal.workflow.shared.TestMultiargsWorkflowsFuncParent; import io.temporal.workflow.shared.TestOptions; import java.util.Optional; import org.junit.Assert; @@ -37,8 +37,7 @@ public class ParentWorkflowInfoInChildWorkflowsTest { public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder() .setWorkflowTypes( - WorkflowTest.TestMultiargsWorkflowsFuncParent.class, - TestMultiargsWorkflowsFuncChild.class) + TestMultiargsWorkflowsFuncChild.class, TestMultiargsWorkflowsFuncParent.class) .build(); @Test diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java index ed89ffd235..a11bbdf666 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java @@ -27,6 +27,7 @@ import io.temporal.failure.CanceledFailure; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestWorkflows; import java.util.ArrayList; import java.util.List; import org.junit.Rule; @@ -54,12 +55,12 @@ public void testStartChildWorkflowWithCancellationScopeAndCancelParent() { } public static class ParentThatStartsChildInCancellationScope - implements WorkflowTest.TestWorkflow { + implements TestWorkflows.TestWorkflow { @Override public void execute(ChildWorkflowCancellationType cancellationType) { - WorkflowTest.TestChildWorkflow child = + TestWorkflows.TestChildWorkflow child = Workflow.newChildWorkflowStub( - WorkflowTest.TestChildWorkflow.class, + TestWorkflows.TestChildWorkflow.class, ChildWorkflowOptions.newBuilder().setCancellationType(cancellationType).build()); List> children = new ArrayList<>(); // This is a non blocking call that returns immediately. @@ -75,7 +76,7 @@ public void execute(ChildWorkflowCancellationType cancellationType) { } } - public static class SleepyChild implements WorkflowTest.TestChildWorkflow { + public static class SleepyChild implements TestWorkflows.TestChildWorkflow { @Override public void execute() { Workflow.await(() -> false); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/AngryChild.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/AngryChild.java new file mode 100644 index 0000000000..cdf15ed064 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/AngryChild.java @@ -0,0 +1,41 @@ +/* + * 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.shared; + +import io.temporal.activity.ActivityOptions; +import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.Workflow; +import java.time.Duration; + +public class AngryChild implements TestWorkflows.ITestChild { + + @Override + public String execute(String taskQueue, int delay) { + TestActivities.AngryChildActivity activity = + Workflow.newActivityStub( + TestActivities.AngryChildActivity.class, + ActivityOptions.newBuilder() + .setTaskQueue(taskQueue) + .setScheduleToCloseTimeout(Duration.ofSeconds(5)) + .build()); + activity.execute(); + throw ApplicationFailure.newFailure("simulated failure", "test"); + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/DeterminismFailingWorkflowImpl.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/DeterminismFailingWorkflowImpl.java new file mode 100644 index 0000000000..5c2384fc85 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/DeterminismFailingWorkflowImpl.java @@ -0,0 +1,35 @@ +/* + * 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.shared; + +import io.temporal.workflow.Workflow; + +public class DeterminismFailingWorkflowImpl implements TestWorkflows.DeterminismFailingWorkflow { + + @Override + public void execute(String taskQueue) { + TestActivities activities = + Workflow.newActivityStub( + TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue)); + if (!Workflow.isReplaying()) { + activities.activity1(1); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/NonSerializableException.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/NonSerializableException.java new file mode 100644 index 0000000000..e2600506f9 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/NonSerializableException.java @@ -0,0 +1,39 @@ +/* + * 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.shared; + +import io.temporal.activity.Activity; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +public class NonSerializableException extends RuntimeException { + @SuppressWarnings("unused") + private final InputStream file; // gson chokes on this field + + public NonSerializableException() { + try { + file = new FileInputStream(File.createTempFile("foo", "bar")); + } catch (IOException e) { + throw Activity.wrap(e); + } + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/SignalQueryBase.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SignalQueryBase.java new file mode 100644 index 0000000000..e11913a9b7 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SignalQueryBase.java @@ -0,0 +1,31 @@ +/* + * 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.shared; + +import io.temporal.workflow.QueryMethod; +import io.temporal.workflow.SignalMethod; + +public interface SignalQueryBase { + @SignalMethod + void signal(String arg); + + @QueryMethod + String getSignal(); +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestChild.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestChild.java new file mode 100644 index 0000000000..65f5630f1b --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestChild.java @@ -0,0 +1,31 @@ +/* + * 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.shared; + +import io.temporal.workflow.Workflow; + +public class TestChild implements TestWorkflows.ITestChild { + + @Override + public String execute(String arg, int delay) { + Workflow.sleep(delay); + return arg.toUpperCase(); + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestMultiargsWorkflowsFuncParent.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestMultiargsWorkflowsFuncParent.java new file mode 100644 index 0000000000..3dbe3a322c --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestMultiargsWorkflowsFuncParent.java @@ -0,0 +1,46 @@ +/* + * 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.shared; + +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.Workflow; +import java.time.Duration; +import java.util.Optional; + +public class TestMultiargsWorkflowsFuncParent + implements TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc { + @Override + public String func() { + ChildWorkflowOptions workflowOptions = + ChildWorkflowOptions.newBuilder() + .setWorkflowRunTimeout(Duration.ofSeconds(100)) + .setWorkflowTaskTimeout(Duration.ofSeconds(60)) + .build(); + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2 child = + Workflow.newChildWorkflowStub( + TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsFunc2.class, workflowOptions); + + Optional parentWorkflowId = Workflow.getInfo().getParentWorkflowId(); + String childsParentWorkflowId = child.func2(null, 0); + + String result = String.format("%s - %s", parentWorkflowId.isPresent(), childsParentWorkflowId); + return result; + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflowWithCronScheduleImpl.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflowWithCronScheduleImpl.java new file mode 100644 index 0000000000..0672d531ae --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflowWithCronScheduleImpl.java @@ -0,0 +1,69 @@ +/* + * 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.shared; + +import io.temporal.failure.ApplicationFailure; +import io.temporal.workflow.CancellationScope; +import io.temporal.workflow.Workflow; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; + +public class TestWorkflowWithCronScheduleImpl + implements TestWorkflows.TestWorkflowWithCronSchedule { + + public static final Map retryCount = new ConcurrentHashMap<>(); + public static String lastCompletionResult; + public static Optional lastFail; + + + @Override + public String execute(String testName) { + Logger log = Workflow.getLogger(TestWorkflowWithCronScheduleImpl.class); + + if (CancellationScope.current().isCancelRequested()) { + log.debug("TestWorkflowWithCronScheduleImpl run canceled."); + return null; + } + + lastCompletionResult = Workflow.getLastCompletionResult(String.class); + lastFail = Workflow.getPreviousRunFailure(); + + AtomicInteger count = retryCount.get(testName); + if (count == null) { + count = new AtomicInteger(); + retryCount.put(testName, count); + } + int c = count.incrementAndGet(); + + if (c == 3) { + throw ApplicationFailure.newFailure("simulated error", "test"); + } + + SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS"); + Date now = new Date(Workflow.currentTimeMillis()); + log.debug("TestWorkflowWithCronScheduleImpl run at " + sdf.format(now)); + return "run " + c; + } +} diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflows.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflows.java index 7892b5cebd..d21af6afc4 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflows.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflows.java @@ -19,12 +19,17 @@ package io.temporal.workflow.shared; -import io.temporal.workflow.QueryMethod; -import io.temporal.workflow.WorkflowInterface; -import io.temporal.workflow.WorkflowMethod; +import io.temporal.common.CronSchedule; +import io.temporal.workflow.*; import java.util.List; public class TestWorkflows { + @WorkflowInterface + public interface TestWorkflow { + @WorkflowMethod + void execute(ChildWorkflowCancellationType cancellationType); + } + @WorkflowInterface public interface TestWorkflow1 { @@ -41,4 +46,74 @@ public interface TestWorkflow2 { @QueryMethod(name = "getTrace") List getTrace(); } + + @WorkflowInterface + public interface TestChildWorkflow { + @WorkflowMethod + void execute(); + } + + @WorkflowInterface + public interface ITestChild { + + @WorkflowMethod + String execute(String arg, int delay); + } + + @WorkflowInterface + public interface ITestNamedChild { + + @WorkflowMethod(name = "namedChild") + String execute(String arg); + } + + @WorkflowInterface + public interface QueryableWorkflow { + + @WorkflowMethod + String execute(); + + @QueryMethod + String getState(); + + @SignalMethod(name = "testSignal") + void mySignal(String value); + } + + @WorkflowInterface + public interface DeterminismFailingWorkflow { + @WorkflowMethod + void execute(String taskQueue); + } + + @WorkflowInterface + public interface SignalingChild { + + @WorkflowMethod + String execute(String arg, String parentWorkflowId); + } + + @WorkflowInterface + public interface TestWorkflowRetry { + + @WorkflowMethod + String execute(String testName); + } + + @WorkflowInterface + public interface TestWorkflowWithCronSchedule { + @WorkflowMethod + @CronSchedule("0 * * * *") + String execute(String testName); + } + + @WorkflowInterface + public interface TestWorkflowSignaled { + + @WorkflowMethod + String execute(); + + @SignalMethod(name = "testSignal") + void signal1(String arg); + } } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java index 23c63215a0..a777729900 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/ExceptionInSignalTest.java @@ -25,9 +25,9 @@ import io.temporal.client.WorkflowClient; import io.temporal.workflow.Async; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.time.Duration; @@ -48,8 +48,8 @@ public class ExceptionInSignalTest { @Test public void testExceptionInSignal() throws InterruptedException { - WorkflowTest.TestWorkflowSignaled signalWorkflow = - testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.TestWorkflowSignaled.class); + TestWorkflows.TestWorkflowSignaled signalWorkflow = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflowSignaled.class); CompletableFuture result = WorkflowClient.execute(signalWorkflow::execute); signalWorkflow.signal1("test"); try { @@ -78,7 +78,8 @@ public void testExceptionInSignal() throws InterruptedException { "workflow threads might leak, #workflowThreads = " + workflowThreads, workflowThreads < 20); } - public static class TestSignalExceptionWorkflowImpl implements WorkflowTest.TestWorkflowSignaled { + public static class TestSignalExceptionWorkflowImpl + implements TestWorkflows.TestWorkflowSignaled { private final boolean signaled = false; @Override diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java index a5385e895c..b6e8060cfc 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryInterfaceTest.java @@ -25,8 +25,8 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.SignalQueryBase; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -43,10 +43,10 @@ public void testSignalAndQueryInterface() { testWorkflowRule.newWorkflowStubTimeoutOptions(SignalQueryWorkflowA.class); WorkflowExecution execution = WorkflowClient.start(stub::execute); - WorkflowTest.SignalQueryBase signalStub = + SignalQueryBase signalStub = testWorkflowRule .getWorkflowClient() - .newWorkflowStub(WorkflowTest.SignalQueryBase.class, execution.getWorkflowId()); + .newWorkflowStub(SignalQueryBase.class, execution.getWorkflowId()); signalStub.signal("Hello World!"); String result = WorkflowStub.fromTyped(stub).getResult(String.class); String queryResult = signalStub.getSignal(); @@ -55,7 +55,7 @@ public void testSignalAndQueryInterface() { } @WorkflowInterface - public interface SignalQueryWorkflowA extends WorkflowTest.SignalQueryBase { + public interface SignalQueryWorkflowA extends SignalQueryBase { @WorkflowMethod String execute(); } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java index 34045f7c01..b9d33be30a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java @@ -26,6 +26,7 @@ import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.SignalQueryBase; import io.temporal.workflow.shared.TestOptions; import java.util.ArrayList; import java.util.List; @@ -51,10 +52,10 @@ public void testSignalAndQueryListener() { testWorkflowRule.newWorkflowStubTimeoutOptions(TestSignalAndQueryListenerWorkflow.class); WorkflowExecution execution = WorkflowClient.start(stub::execute); - WorkflowTest.SignalQueryBase signalStub = + SignalQueryBase signalStub = testWorkflowRule .getWorkflowClient() - .newWorkflowStub(WorkflowTest.SignalQueryBase.class, execution.getWorkflowId()); + .newWorkflowStub(SignalQueryBase.class, execution.getWorkflowId()); // Send signals before listener is registered to test signal buffering signalStub.signal("a"); signalStub.signal("b"); @@ -108,7 +109,7 @@ public static class TestSignalAndQueryListenerWorkflowImpl public void execute() { Workflow.await(() -> register); Workflow.registerListener( - new WorkflowTest.SignalQueryBase() { + new SignalQueryBase() { @Override public void signal(String arg) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java index 4521e2f9fe..deda32adb4 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalDuringLastWorkflowTaskTest.java @@ -22,9 +22,9 @@ import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestOptions; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import java.util.Optional; import java.util.UUID; @@ -55,10 +55,10 @@ public void testSignalDuringLastWorkflowTask() { .toBuilder() .setWorkflowId("testSignalDuringLastWorkflowTask-" + UUID.randomUUID().toString()) .build(); - WorkflowTest.TestWorkflowSignaled client = + TestWorkflows.TestWorkflowSignaled client = testWorkflowRule .getWorkflowClient() - .newWorkflowStub(WorkflowTest.TestWorkflowSignaled.class, options); + .newWorkflowStub(TestWorkflows.TestWorkflowSignaled.class, options); WorkflowExecution execution = WorkflowClient.start(client::execute); testWorkflowRule.registerDelayedCallback( Duration.ofSeconds(1), @@ -84,7 +84,7 @@ public void testSignalDuringLastWorkflowTask() { } static class TestSignalDuringLastWorkflowTaskWorkflowImpl - implements WorkflowTest.TestWorkflowSignaled { + implements TestWorkflows.TestWorkflowSignaled { private String signal; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java index a78e7d684f..b1290fd3cc 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowFailureTest.java @@ -26,7 +26,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.failure.ApplicationFailure; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; @@ -71,9 +70,9 @@ public static class TestSignalExternalWorkflowFailure implements TestWorkflows.T public String execute(String taskQueue) { WorkflowExecution parentExecution = WorkflowExecution.newBuilder().setWorkflowId("invalid id").build(); - WorkflowTest.TestWorkflowSignaled workflow = + TestWorkflows.TestWorkflowSignaled workflow = Workflow.newExternalWorkflowStub( - WorkflowTest.TestWorkflowSignaled.class, parentExecution); + TestWorkflows.TestWorkflowSignaled.class, parentExecution); workflow.signal1("World"); return "ignored"; } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java index c42f21fb20..0acbc4ae0c 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java @@ -66,9 +66,9 @@ public static class TestSignalExternalWorkflowImmediateCancellation public String execute(String taskQueue) { WorkflowExecution parentExecution = WorkflowExecution.newBuilder().setWorkflowId("invalid id").build(); - WorkflowTest.TestWorkflowSignaled workflow = + TestWorkflows.TestWorkflowSignaled workflow = Workflow.newExternalWorkflowStub( - WorkflowTest.TestWorkflowSignaled.class, parentExecution); + TestWorkflows.TestWorkflowSignaled.class, parentExecution); CompletablePromise signal = Workflow.newPromise(); CancellationScope scope = Workflow.newCancellationScope( diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java index 0a390ba113..67161fb364 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java @@ -25,6 +25,7 @@ import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; @@ -48,10 +49,10 @@ public void testSignalExternalWorkflow() { .setWorkflowTaskTimeout(Duration.ofSeconds(60)) .setTaskQueue(testWorkflowRule.getTaskQueue()) .build(); - WorkflowTest.TestWorkflowSignaled client = + TestWorkflows.TestWorkflowSignaled client = testWorkflowRule .getWorkflowClient() - .newWorkflowStub(WorkflowTest.TestWorkflowSignaled.class, options); + .newWorkflowStub(TestWorkflows.TestWorkflowSignaled.class, options); Assert.assertEquals("Hello World!", client.execute()); WorkflowStub stub = WorkflowStub.fromTyped(client); testWorkflowRule @@ -67,10 +68,10 @@ public void testSignalExternalWorkflow() { "handleSignal testSignal"); } - public static class TestSignalExternalWorkflow implements WorkflowTest.TestWorkflowSignaled { + public static class TestSignalExternalWorkflow implements TestWorkflows.TestWorkflowSignaled { - private final WorkflowTest.SignalingChild child = - Workflow.newChildWorkflowStub(WorkflowTest.SignalingChild.class); + private final TestWorkflows.SignalingChild child = + Workflow.newChildWorkflowStub(TestWorkflows.SignalingChild.class); private final CompletablePromise fromSignal = Workflow.newPromise(); @@ -87,15 +88,15 @@ public void signal1(String arg) { } } - public static class SignalingChildImpl implements WorkflowTest.SignalingChild { + public static class SignalingChildImpl implements TestWorkflows.SignalingChild { @Override public String execute(String greeting, String parentWorkflowId) { WorkflowExecution parentExecution = WorkflowExecution.newBuilder().setWorkflowId(parentWorkflowId).build(); - WorkflowTest.TestWorkflowSignaled parent = + TestWorkflows.TestWorkflowSignaled parent = Workflow.newExternalWorkflowStub( - WorkflowTest.TestWorkflowSignaled.class, parentExecution); + TestWorkflows.TestWorkflowSignaled.class, parentExecution); ExternalWorkflowStub untyped = ExternalWorkflowStub.fromTyped(parent); // Same as parent.signal1("World"); untyped.signal("testSignal", "World"); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java index 9baa95101e..66e5f31834 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalTest.java @@ -29,9 +29,9 @@ import io.temporal.client.*; import io.temporal.workflow.CompletablePromise; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestOptions; +import io.temporal.workflow.shared.TestWorkflows.QueryableWorkflow; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -63,8 +63,7 @@ public void testSignal() { .toBuilder() .setWorkflowId(workflowId) .build(); - WorkflowTest.QueryableWorkflow client = - workflowClient.newWorkflowStub(WorkflowTest.QueryableWorkflow.class, options); + QueryableWorkflow client = workflowClient.newWorkflowStub(QueryableWorkflow.class, options); // To execute workflow client.execute() would do. But we want to start workflow and immediately // return. WorkflowExecution execution = WorkflowClient.start(client::execute); @@ -79,11 +78,9 @@ public void testSignal() { testWorkflowRule.sleep(Duration.ofSeconds(1)); // Test client created using WorkflowExecution - WorkflowTest.QueryableWorkflow client2 = + QueryableWorkflow client2 = workflowClient.newWorkflowStub( - WorkflowTest.QueryableWorkflow.class, - execution.getWorkflowId(), - Optional.of(execution.getRunId())); + QueryableWorkflow.class, execution.getWorkflowId(), Optional.of(execution.getRunId())); assertEquals("Hello ", client2.getState()); testWorkflowRule.sleep(Duration.ofMillis(500)); @@ -105,8 +102,7 @@ public void testSignalWithStart() throws Exception { .toBuilder() .setWorkflowId(workflowId) .build(); - WorkflowTest.QueryableWorkflow client = - workflowClient.newWorkflowStub(WorkflowTest.QueryableWorkflow.class, options); + QueryableWorkflow client = workflowClient.newWorkflowStub(QueryableWorkflow.class, options); // SignalWithStart starts a workflow and delivers the signal to it. BatchRequest batch = workflowClient.newSignalWithStartRequest(); @@ -116,8 +112,7 @@ public void testSignalWithStart() throws Exception { testWorkflowRule.sleep(Duration.ofSeconds(1)); // Test client created using WorkflowExecution - WorkflowTest.QueryableWorkflow client2 = - workflowClient.newWorkflowStub(WorkflowTest.QueryableWorkflow.class, options); + QueryableWorkflow client2 = workflowClient.newWorkflowStub(QueryableWorkflow.class, options); // SignalWithStart delivers the signal to the already running workflow. BatchRequest batch2 = workflowClient.newSignalWithStartRequest(); batch2.add(client2::mySignal, "World!"); @@ -132,8 +127,7 @@ public void testSignalWithStart() throws Exception { workflowClient.newUntypedWorkflowStub(execution, Optional.empty()).getResult(String.class)); // Check if that it starts closed workflow (AllowDuplicate is default IdReusePolicy) - WorkflowTest.QueryableWorkflow client3 = - workflowClient.newWorkflowStub(WorkflowTest.QueryableWorkflow.class, options); + QueryableWorkflow client3 = workflowClient.newWorkflowStub(QueryableWorkflow.class, options); BatchRequest batch3 = workflowClient.newSignalWithStartRequest(); batch3.add(client3::mySignal, "Hello "); batch3.add(client3::execute); @@ -145,9 +139,9 @@ public void testSignalWithStart() throws Exception { assertEquals("Hello World!", result); // Make sure that cannot start if closed and RejectDuplicate policy - WorkflowTest.QueryableWorkflow client4 = + QueryableWorkflow client4 = workflowClient.newWorkflowStub( - WorkflowTest.QueryableWorkflow.class, + QueryableWorkflow.class, options .toBuilder() .setWorkflowIdReusePolicy( @@ -167,7 +161,7 @@ public void testSignalWithStart() throws Exception { @Test public void testSignalUntyped() { WorkflowClient workflowClient = testWorkflowRule.getWorkflowClient(); - String workflowType = WorkflowTest.QueryableWorkflow.class.getSimpleName(); + String workflowType = QueryableWorkflow.class.getSimpleName(); AtomicReference execution = new AtomicReference<>(); WorkflowStub workflowStub = workflowClient.newUntypedWorkflowStub( @@ -214,7 +208,7 @@ public void testSignalUntyped() { } } - public static class TestSignalWorkflowImpl implements WorkflowTest.QueryableWorkflow { + public static class TestSignalWorkflowImpl implements QueryableWorkflow { String state = "initial"; List signals = new ArrayList<>(); CompletablePromise promise = Workflow.newPromise(); @@ -241,7 +235,7 @@ public void mySignal(String value) { } } - public static class TestSignalWithStartWorkflowImpl implements WorkflowTest.QueryableWorkflow { + public static class TestSignalWithStartWorkflowImpl implements QueryableWorkflow { String state = "initial"; List signals = new ArrayList<>(); CompletablePromise promise = Workflow.newPromise(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java index f389d8c12b..19c94ed2a3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java @@ -22,6 +22,7 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; import org.junit.Rule; @@ -44,15 +45,15 @@ public void testUntypedSignalExternalWorkflow() { .setWorkflowTaskTimeout(Duration.ofSeconds(2)) .setTaskQueue(testWorkflowRule.getTaskQueue()) .build(); - WorkflowTest.TestWorkflowSignaled client = + TestWorkflows.TestWorkflowSignaled client = testWorkflowRule .getWorkflowClient() - .newWorkflowStub(WorkflowTest.TestWorkflowSignaled.class, options); + .newWorkflowStub(TestWorkflows.TestWorkflowSignaled.class, options); Assert.assertEquals("Hello World!", client.execute()); } public static class TestUntypedSignalExternalWorkflow - implements WorkflowTest.TestWorkflowSignaled { + implements TestWorkflows.TestWorkflowSignaled { private final ChildWorkflowStub child = Workflow.newUntypedChildWorkflowStub("SignalingChild"); @@ -71,7 +72,7 @@ public void signal1(String arg) { } } - public static class UntypedSignalingChildImpl implements WorkflowTest.SignalingChild { + public static class UntypedSignalingChildImpl implements TestWorkflows.SignalingChild { @Override public String execute(String greeting, String parentWorkflowId) { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java index 2ca1844d80..6aa5529ff2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/versionTests/GetVersionWithoutCommandEventTest.java @@ -24,8 +24,8 @@ import io.temporal.worker.WorkerFactoryOptions; import io.temporal.workflow.CompletablePromise; import io.temporal.workflow.Workflow; -import io.temporal.workflow.WorkflowTest; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import java.util.concurrent.CompletableFuture; import org.junit.Assert; @@ -49,8 +49,8 @@ public class GetVersionWithoutCommandEventTest { @Test public void testGetVersionWithoutCommandEvent() throws Exception { executionStarted = new CompletableFuture(); - WorkflowTest.TestWorkflowSignaled workflowStub = - testWorkflowRule.newWorkflowStubTimeoutOptions(WorkflowTest.TestWorkflowSignaled.class); + TestWorkflows.TestWorkflowSignaled workflowStub = + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflowSignaled.class); WorkflowClient.start(workflowStub::execute); executionStarted.get(); workflowStub.signal1("test signal"); @@ -59,7 +59,7 @@ public void testGetVersionWithoutCommandEvent() throws Exception { } public static class TestGetVersionWithoutCommandEventWorkflowImpl - implements WorkflowTest.TestWorkflowSignaled { + implements TestWorkflows.TestWorkflowSignaled { CompletablePromise signalReceived = Workflow.newPromise(); From 336afefae6feb7db243391461caa861a2428e96e Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Wed, 31 Mar 2021 17:47:18 -0700 Subject: [PATCH 20/21] A few minor things --- .../java/io/temporal/internal/sync/DeterministicRunnerTest.java | 2 +- .../java/io/temporal/workflow/shared/SDKTestWorkflowRule.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java b/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java index 6950fde93a..f9fecff5bc 100644 --- a/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java @@ -126,7 +126,7 @@ public void testYield() throws Throwable { * Async retry cannot be tested here as it relies on timer that is implemented outside of * Dispatcher. * - * @see activityTests.AsyncRetryTest#testAsyncRetry() + * @see io.temporal.workflow.activityTests.AsyncRetryTest#testAsyncRetry() */ @Test @Ignore // timer removed from dispatcher diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java index 004e847f3d..2ba9c756d0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/SDKTestWorkflowRule.java @@ -59,7 +59,6 @@ public class SDKTestWorkflowRule implements TestRule { public static final String NAMESPACE = "UnitTest"; public static final String BINARY_CHECKSUM = "testChecksum"; - public static final String ANNOTATION_TASK_QUEUE = "WorkflowTest-testExecute[Docker]"; public static final String UUID_REGEXP = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"; // Enable to regenerate JsonFiles used for replay testing. From 5d20211cd78bcc7324ba5dc6b8afe2d4d21f2bfd Mon Sep 17 00:00:00 2001 From: Vera Kobylchak Date: Thu, 1 Apr 2021 11:03:03 -0700 Subject: [PATCH 21/21] Replaced with single class imports --- .../workflow/BinaryChecksumSetWhenTaskCompletedTest.java | 5 ++++- .../java/io/temporal/workflow/DetachedScopeTest.java | 5 ++++- .../io/temporal/workflow/ExceptionPropagationTest.java | 5 ++++- .../io/temporal/workflow/ParentContinueAsNewTest.java | 2 +- .../src/test/java/io/temporal/workflow/SyncTest.java | 5 ++++- .../src/test/java/io/temporal/workflow/TimerTest.java | 1 - .../activityTests/AbandonOnCancelActivityTest.java | 5 ++++- .../activityTests/ActivityPollerPrefetchingTest.java | 6 +++++- .../AsyncActivityCompleteWithErrorTest.java | 6 +++++- .../workflow/activityTests/AsyncActivityTest.java | 5 ++++- .../activityTests/AsyncUntyped2ActivityTest.java | 5 ++++- .../workflow/activityTests/AsyncUntypedActivityTest.java | 5 ++++- .../LocalActivitiesWorkflowTaskHeartbeatTest.java | 5 ++++- .../workflow/activityTests/LocalActivityTest.java | 5 ++++- ...ongLocalActivityWorkflowTaskHeartbeatFailureTest.java | 5 ++++- .../LongLocalActivityWorkflowTaskHeartbeatTest.java | 5 ++++- .../activityTests/ParallelLocalActivitiesTest.java | 5 ++++- .../workflow/activityTests/TryCancelActivityTest.java | 5 ++++- .../childWorkflowTests/ChildAsyncLambdaWorkflowTest.java | 9 ++++++++- .../childWorkflowTests/ChildWorkflowAsyncRetryTest.java | 9 +++++++-- .../ChildWorkflowExecutionPromiseHandlerTest.java | 5 ++++- .../childWorkflowTests/ChildWorkflowRetryTest.java | 5 ++++- .../workflow/childWorkflowTests/ChildWorkflowTest.java | 5 ++++- .../childWorkflowTests/ChildWorkflowTimeoutTest.java | 2 +- .../ChildWorkflowWithCronScheduleTest.java | 2 +- .../workflow/childWorkflowTests/NamedChildTest.java | 8 +++++++- .../NonSerializableExceptionInChildWorkflowTest.java | 2 +- ...WorkflowWithCancellationScopeAndCancelParentTest.java | 7 ++++++- .../java/io/temporal/workflow/shared/TestWorkflows.java | 6 +++++- .../workflow/signalTests/SignalAndQueryListenerTest.java | 5 ++++- .../SignalExternalWorkflowImmediateCancellationTest.java | 5 ++++- .../workflow/signalTests/SignalExternalWorkflowTest.java | 6 +++++- .../signalTests/UntypedSignalExternalWorkflowTest.java | 6 +++++- 33 files changed, 133 insertions(+), 34 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java index 3b99f02b4d..597c456366 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/BinaryChecksumSetWhenTaskCompletedTest.java @@ -30,7 +30,10 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowStub; -import io.temporal.workflow.shared.*; +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 org.junit.Rule; import org.junit.Test; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java index a531ceb55f..76f4b83ac4 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/DetachedScopeTest.java @@ -25,7 +25,10 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.ActivityFailure; import io.temporal.failure.CanceledFailure; -import io.temporal.workflow.shared.*; +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; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java index 1efd2fc5d0..ca43b58850 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ExceptionPropagationTest.java @@ -27,7 +27,10 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.failure.ChildWorkflowFailure; import io.temporal.worker.WorkflowImplementationOptions; -import io.temporal.workflow.shared.*; +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.io.FileNotFoundException; import java.io.IOException; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java index d089ebaba9..363e944deb 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ParentContinueAsNewTest.java @@ -21,8 +21,8 @@ import io.temporal.api.enums.v1.WorkflowIdReusePolicy; import io.temporal.client.WorkflowOptions; -import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestChild; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assert; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java index ad79b5a30c..73a1c62f3b 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SyncTest.java @@ -28,7 +28,10 @@ import io.temporal.failure.CanceledFailure; import io.temporal.failure.TerminatedFailure; import io.temporal.testing.TracingWorkerInterceptor; -import io.temporal.workflow.shared.*; +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; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java index 9c10f10806..38609b1b8f 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/TimerTest.java @@ -23,7 +23,6 @@ import io.temporal.client.WorkflowOptions; import io.temporal.testing.TracingWorkerInterceptor; -import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestOptions; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java index b0b873c0a7..90e19caeb9 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AbandonOnCancelActivityTest.java @@ -30,7 +30,10 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityPollerPrefetchingTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityPollerPrefetchingTest.java index 91954a12c8..9fc346d07d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityPollerPrefetchingTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityPollerPrefetchingTest.java @@ -25,7 +25,11 @@ import io.temporal.activity.ActivityOptions; import io.temporal.common.RetryOptions; import io.temporal.worker.WorkerOptions; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.shared.SDKTestWorkflowRule; import java.time.Duration; import java.util.ArrayList; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityCompleteWithErrorTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityCompleteWithErrorTest.java index 4a3725aa5a..dbe8102f09 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityCompleteWithErrorTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityCompleteWithErrorTest.java @@ -23,7 +23,11 @@ import io.temporal.activity.ManualActivityCompletionClient; import io.temporal.common.RetryOptions; import io.temporal.failure.ApplicationFailure; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.shared.SDKTestWorkflowRule; import java.time.Duration; import java.util.concurrent.ForkJoinPool; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java index 4a2b9e1993..e11654d1d6 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncActivityTest.java @@ -24,7 +24,10 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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.util.ArrayList; import java.util.List; import java.util.UUID; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java index 57f9726c65..d5f1b91565 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntyped2ActivityTest.java @@ -24,7 +24,10 @@ import io.temporal.workflow.ActivityStub; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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 org.junit.Assert; import org.junit.Rule; import org.junit.Test; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java index 4420398a4b..f261694394 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/AsyncUntypedActivityTest.java @@ -25,7 +25,10 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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 org.junit.Assert; import org.junit.Rule; import org.junit.Test; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java index d7e45448c6..fbebbceaab 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivitiesWorkflowTaskHeartbeatTest.java @@ -22,7 +22,10 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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 java.util.concurrent.ExecutionException; import java.util.concurrent.Future; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java index e9f76a2cc0..7e3239c914 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityTest.java @@ -26,7 +26,10 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.testing.TracingWorkerInterceptor; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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.io.IOException; import org.junit.Assert; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java index 2d98d875d9..957a9ce726 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatFailureTest.java @@ -21,7 +21,10 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java index 67d1a8affc..6d66276598 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LongLocalActivityWorkflowTaskHeartbeatTest.java @@ -21,7 +21,10 @@ import io.temporal.client.WorkflowOptions; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java index a7963e9ba9..740612a698 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java @@ -24,7 +24,10 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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 java.util.ArrayList; import java.util.List; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java index 3d6c7e9ae3..907421d5f6 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TryCancelActivityTest.java @@ -26,7 +26,10 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +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; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java index 80d43d3af4..9ed3028d7a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildAsyncLambdaWorkflowTest.java @@ -23,7 +23,14 @@ import static org.junit.Assert.assertNotNull; import io.temporal.api.common.v1.WorkflowExecution; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.CompletablePromise; +import io.temporal.workflow.Promise; +import io.temporal.workflow.SignalMethod; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java index e8fcaf10de..2cb3a715e3 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowAsyncRetryTest.java @@ -27,8 +27,13 @@ import io.temporal.failure.ApplicationFailure; import io.temporal.failure.ChildWorkflowFailure; import io.temporal.testing.WorkflowReplayer; -import io.temporal.workflow.*; -import io.temporal.workflow.shared.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.shared.AngryChild; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assume; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java index 39f18bb22c..bee1545e89 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowExecutionPromiseHandlerTest.java @@ -25,7 +25,10 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.testing.TestWorkflowRule; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.CompletablePromise; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java index 5fcf566281..15587b85d5 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowRetryTest.java @@ -38,7 +38,10 @@ import io.temporal.worker.WorkflowImplementationOptions; import io.temporal.workflow.ChildWorkflowOptions; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; +import io.temporal.workflow.shared.AngryChild; +import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestActivities; +import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import java.util.concurrent.atomic.AtomicReference; import org.junit.Assume; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java index 81e214c8c3..8495f56c1a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTest.java @@ -21,7 +21,10 @@ import static org.junit.Assert.assertEquals; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestChild; import io.temporal.workflow.shared.TestWorkflows; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java index 4d2e0a6d66..18f22a98b0 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowTimeoutTest.java @@ -24,8 +24,8 @@ import com.google.common.base.Throwables; import io.temporal.workflow.ChildWorkflowOptions; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestChild; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Rule; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java index 2b3d0b4adf..a0a7a8634d 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/ChildWorkflowWithCronScheduleTest.java @@ -26,8 +26,8 @@ import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; import io.temporal.workflow.Workflow; -import io.temporal.workflow.shared.*; import io.temporal.workflow.shared.SDKTestWorkflowRule; +import io.temporal.workflow.shared.TestWorkflowWithCronScheduleImpl; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; import org.junit.Assume; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java index e122e19ae5..b24c532206 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NamedChildTest.java @@ -24,7 +24,13 @@ import io.temporal.api.enums.v1.WorkflowIdReusePolicy; import io.temporal.client.WorkflowFailedException; import io.temporal.failure.ChildWorkflowFailure; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.ChildWorkflowStub; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.util.UUID; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java index ffedabc53a..410502d489 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/NonSerializableExceptionInChildWorkflowTest.java @@ -24,7 +24,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; -import io.temporal.workflow.shared.*; +import io.temporal.workflow.shared.NonSerializableException; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import org.junit.Assert; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java index a11bbdf666..88fb8dba56 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/childWorkflowTests/StartChildWorkflowWithCancellationScopeAndCancelParentTest.java @@ -25,7 +25,12 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowStub; import io.temporal.failure.CanceledFailure; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.CancellationScope; +import io.temporal.workflow.ChildWorkflowCancellationType; +import io.temporal.workflow.ChildWorkflowOptions; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.util.ArrayList; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflows.java b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflows.java index d21af6afc4..4b26dcdf01 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflows.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/shared/TestWorkflows.java @@ -20,7 +20,11 @@ package io.temporal.workflow.shared; import io.temporal.common.CronSchedule; -import io.temporal.workflow.*; +import io.temporal.workflow.ChildWorkflowCancellationType; +import io.temporal.workflow.QueryMethod; +import io.temporal.workflow.SignalMethod; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import java.util.List; public class TestWorkflows { diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java index b9d33be30a..961f93fd98 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalAndQueryListenerTest.java @@ -24,7 +24,10 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowQueryException; import io.temporal.testing.TracingWorkerInterceptor; -import io.temporal.workflow.*; +import io.temporal.workflow.SignalMethod; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.SignalQueryBase; import io.temporal.workflow.shared.TestOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java index 0acbc4ae0c..cf32afaf02 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowImmediateCancellationTest.java @@ -23,7 +23,10 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowOptions; import io.temporal.failure.CanceledFailure; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.CancellationScope; +import io.temporal.workflow.CompletablePromise; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java index 67161fb364..a6f2107d35 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalExternalWorkflowTest.java @@ -23,7 +23,11 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.testing.TracingWorkerInterceptor; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.CompletablePromise; +import io.temporal.workflow.ExternalWorkflowStub; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration; diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java index 19c94ed2a3..b7d0998ff8 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/UntypedSignalExternalWorkflowTest.java @@ -20,7 +20,11 @@ package io.temporal.workflow.signalTests; import io.temporal.client.WorkflowOptions; -import io.temporal.workflow.*; +import io.temporal.workflow.ChildWorkflowStub; +import io.temporal.workflow.CompletablePromise; +import io.temporal.workflow.ExternalWorkflowStub; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Workflow; import io.temporal.workflow.shared.SDKTestWorkflowRule; import io.temporal.workflow.shared.TestWorkflows; import java.time.Duration;