View Javadoc

1   /*
2    * $Id: PollingReceiversRestartTestCase.java 22502 2011-07-21 14:40:42Z justin.calleja $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.http.functional;
12  
13  import static org.junit.Assert.assertTrue;
14  
15  import java.util.Arrays;
16  import java.util.Collection;
17  import java.util.concurrent.atomic.AtomicInteger;
18  
19  import org.junit.Rule;
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  import org.mule.tck.AbstractServiceAndFlowTestCase;
23  import org.mule.tck.functional.CounterCallback;
24  import org.mule.tck.functional.FunctionalTestComponent;
25  import org.mule.tck.junit4.rule.DynamicPort;
26  
27  public class PollingReceiversRestartTestCase extends AbstractServiceAndFlowTestCase
28  {
29  
30      private static final int WAIT_TIME = 3000;
31  
32      @Rule
33      public DynamicPort dynamicPort = new DynamicPort("port1");
34  
35      public PollingReceiversRestartTestCase(ConfigVariant variant, String configResources)
36      {
37          super(variant, configResources);
38          setStartContext(false);
39      }
40  
41      @Parameters
42      public static Collection<Object[]> parameters()
43      {
44          return Arrays.asList(new Object[][]{
45              {ConfigVariant.SERVICE, "polling-receivers-restart-test-service.xml"},
46              {ConfigVariant.FLOW, "polling-receivers-restart-test-flow.xml"}
47          });
48      }
49  
50      @Test
51      public void testPollingReceiversRestart() throws Exception
52      {
53          muleContext.start();
54  
55          Object ftc = getComponent("Test");
56          assertTrue("FunctionalTestComponent expected", ftc instanceof FunctionalTestComponent);
57  
58          AtomicInteger pollCounter = new AtomicInteger(0);
59          ((FunctionalTestComponent) ftc).setEventCallback(new CounterCallback(pollCounter));
60  
61          // should be enough to poll for 2 messages
62          Thread.sleep(WAIT_TIME);
63  
64          // stop
65          muleContext.stop();
66          assertTrue("No polls performed", pollCounter.get() > 0);
67  
68          // and restart
69          muleContext.start();
70  
71          pollCounter.set(0);
72          ((FunctionalTestComponent) ftc).setEventCallback(new CounterCallback(pollCounter));
73  
74          Thread.sleep(WAIT_TIME);
75          muleContext.dispose();
76          assertTrue("No polls performed", pollCounter.get() > 0);
77      }
78  
79  }