View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.http.functional;
8   
9   import org.mule.tck.functional.CounterCallback;
10  import org.mule.tck.functional.FunctionalTestComponent;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.tck.junit4.rule.DynamicPort;
13  
14  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
15  import org.junit.Rule;
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertTrue;
19  
20  public class PollingReceiversRestartTestCase extends FunctionalTestCase
21  {
22      private static final int WAIT_TIME = 3000;
23  
24      @Rule
25      public DynamicPort dynamicPort = new DynamicPort("port1");
26  
27      public PollingReceiversRestartTestCase()
28      {
29          setStartContext(false);
30      }
31  
32      @Override
33      protected String getConfigResources()
34      {
35          return "polling-receivers-restart-test.xml";
36      }
37  
38      @Test
39      public void testPollingReceiversRestart() throws Exception
40      {
41          muleContext.start();
42  
43          Object ftc = getComponent("Test");
44          assertTrue("FunctionalTestComponent expected", ftc instanceof FunctionalTestComponent);
45  
46          AtomicInteger pollCounter = new AtomicInteger(0);
47          ((FunctionalTestComponent) ftc).setEventCallback(new CounterCallback(pollCounter));
48  
49          // should be enough to poll for 2 messages
50          Thread.sleep(WAIT_TIME);
51  
52          // stop
53          muleContext.stop();
54          assertTrue("No polls performed", pollCounter.get() > 0);
55  
56          // and restart
57          muleContext.start();
58  
59          pollCounter.set(0);
60          ((FunctionalTestComponent) ftc).setEventCallback(new CounterCallback(pollCounter));
61  
62          Thread.sleep(WAIT_TIME);
63          muleContext.dispose();
64          assertTrue("No polls performed", pollCounter.get() > 0);
65      }
66  
67  }