|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | + * |
| 6 | + * Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this material except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | + |
| 21 | +package io.temporal.workflow; |
| 22 | + |
| 23 | +import static org.junit.Assert.assertThrows; |
| 24 | + |
| 25 | +import io.temporal.client.WorkflowFailedException; |
| 26 | +import io.temporal.testing.internal.SDKTestWorkflowRule; |
| 27 | +import io.temporal.worker.WorkflowImplementationOptions; |
| 28 | +import io.temporal.workflow.shared.TestWorkflows; |
| 29 | +import io.temporal.workflow.shared.TestWorkflows.TestWorkflow1; |
| 30 | +import org.junit.Rule; |
| 31 | +import org.junit.Test; |
| 32 | + |
| 33 | +public class BadAwaitTest { |
| 34 | + |
| 35 | + @Rule |
| 36 | + public SDKTestWorkflowRule testWorkflowRule = |
| 37 | + SDKTestWorkflowRule.newBuilder() |
| 38 | + .setWorkflowTypes( |
| 39 | + WorkflowImplementationOptions.newBuilder() |
| 40 | + .setFailWorkflowExceptionTypes(RuntimeException.class) |
| 41 | + .build(), |
| 42 | + TestAwait.class) |
| 43 | + .build(); |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testBadAwait() { |
| 47 | + for (String testCase : TestWorkflows.illegalCallCases) { |
| 48 | + TestWorkflows.TestWorkflow1 workflowStub = |
| 49 | + testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); |
| 50 | + assertThrows(WorkflowFailedException.class, () -> workflowStub.execute(testCase)); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public static class TestAwait implements TestWorkflow1 { |
| 55 | + @Override |
| 56 | + public String execute(String testCase) { |
| 57 | + Workflow.await( |
| 58 | + () -> { |
| 59 | + TestWorkflows.illegalCalls(testCase); |
| 60 | + return true; |
| 61 | + }); |
| 62 | + return "fail"; |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments