|
| 1 | +/* |
| 2 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not |
| 7 | + * use this file except in compliance with the License. A copy of the License is |
| 8 | + * located at |
| 9 | + * |
| 10 | + * http://aws.amazon.com/apache2.0 |
| 11 | + * |
| 12 | + * or in the "license" file accompanying this file. This file is distributed on |
| 13 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 14 | + * express or implied. See the License for the specific language governing |
| 15 | + * permissions and limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.uber.cadence.workflow; |
| 19 | + |
| 20 | +import static junit.framework.TestCase.assertTrue; |
| 21 | + |
| 22 | +import com.uber.cadence.activity.ActivityMethod; |
| 23 | +import com.uber.cadence.testing.TestWorkflowEnvironment; |
| 24 | +import com.uber.cadence.worker.Worker; |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +public class TestEnvironmentCloseTest { |
| 28 | + |
| 29 | + public interface W { |
| 30 | + @WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = "WW") |
| 31 | + void foo(); |
| 32 | + |
| 33 | + @SignalMethod |
| 34 | + void signal(); |
| 35 | + } |
| 36 | + |
| 37 | + public static class WW implements W { |
| 38 | + |
| 39 | + @Override |
| 40 | + public void foo() {} |
| 41 | + |
| 42 | + @Override |
| 43 | + public void signal() {} |
| 44 | + } |
| 45 | + |
| 46 | + public interface A { |
| 47 | + @ActivityMethod |
| 48 | + void bar(); |
| 49 | + } |
| 50 | + |
| 51 | + public static class AA implements A { |
| 52 | + |
| 53 | + @Override |
| 54 | + public void bar() {} |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void testCloseNotHanging() throws InterruptedException { |
| 59 | + TestWorkflowEnvironment env = TestWorkflowEnvironment.newInstance(); |
| 60 | + Worker worker = env.newWorker("WW"); |
| 61 | + worker.registerWorkflowImplementationTypes(WW.class); |
| 62 | + worker.registerActivitiesImplementations(new AA()); |
| 63 | + long start = System.currentTimeMillis(); |
| 64 | + env.close(); |
| 65 | + long elapsed = System.currentTimeMillis() - start; |
| 66 | + assertTrue(elapsed < 5000); |
| 67 | + } |
| 68 | +} |
0 commit comments