Skip to content

Commit fbd46f9

Browse files
authored
Fixed hanging on testEnv.close when not started (#245)
1 parent 7011bd6 commit fbd46f9

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

src/main/java/com/uber/cadence/internal/sync/POJOActivityTaskHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public DataConverter getDataConverter() {
6060
}
6161

6262
public void addActivityImplementation(Object activity) {
63+
if (activity instanceof Class) {
64+
throw new IllegalArgumentException("Activity object instance expected, not the class");
65+
}
6366
Class<?> cls = activity.getClass();
6467
for (Method method : cls.getMethods()) {
6568
if (method.getAnnotation(ActivityMethod.class) != null) {

src/main/java/com/uber/cadence/internal/worker/WorkflowWorker.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ public void shutdownNow() {
193193

194194
@Override
195195
public void awaitTermination(long timeout, TimeUnit unit) {
196+
if (!poller.isStarted()) {
197+
return;
198+
}
196199
long timeoutMillis = unit.toMillis(timeout);
197200
timeoutMillis = InternalUtils.awaitTermination(poller, timeoutMillis);
198201
InternalUtils.awaitTermination(pollTaskExecutor, timeoutMillis);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)