1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.work;
12
13 import org.mule.api.MuleEventContext;
14 import org.mule.api.construct.FlowConstruct;
15 import org.mule.api.service.Service;
16 import org.mule.construct.Flow;
17 import org.mule.tck.AbstractServiceAndFlowTestCase;
18 import org.mule.tck.functional.EventCallback;
19 import org.mule.tck.functional.FunctionalTestComponent;
20 import org.mule.util.concurrent.Latch;
21
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.concurrent.TimeUnit;
25
26 import org.junit.Test;
27 import org.junit.runners.Parameterized.Parameters;
28
29 import static org.junit.Assert.assertTrue;
30
31 public class GracefulShutdownTimeoutTestCase extends AbstractServiceAndFlowTestCase
32 {
33 @Parameters
34 public static Collection<Object[]> parameters()
35 {
36 return Arrays.asList(new Object[][]{
37 {ConfigVariant.SERVICE, "org/mule/test/integration/work/graceful-shutdown-timeout-service.xml"},
38 {ConfigVariant.FLOW, "org/mule/test/integration/work/graceful-shutdown-timeout-flow.xml"}});
39 }
40
41 public GracefulShutdownTimeoutTestCase(ConfigVariant variant, String configResources)
42 {
43 super(variant, configResources);
44 }
45
46 @Override
47 protected boolean isGracefulShutdown()
48 {
49 return true;
50 }
51
52
53
54
55
56
57
58
59
60
61 @Test
62 public void testGracefulShutdownTimeout() throws Exception
63 {
64 final Latch latch = new Latch();
65
66 FlowConstruct service = muleContext.getRegistry().lookupFlowConstruct("TestService");
67 FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent(service);
68 testComponent.setEventCallback(new EventCallback()
69 {
70 @Override
71 public void eventReceived(MuleEventContext context, Object component) throws Exception
72 {
73 Thread.sleep(5500);
74 latch.countDown();
75
76 }
77 });
78
79 if (variant.equals(ConfigVariant.FLOW))
80 {
81 ((Flow) service).process(getTestEvent("test"));
82 Thread.sleep(200);
83 ((Flow) service).dispose();
84 assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
85 }
86 else
87 {
88 ((Service) service).dispatchEvent(getTestEvent("test"));
89 Thread.sleep(200);
90 ((Service) service).dispose();
91 assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
92 }
93 }
94 }