View Javadoc

1   /*
2    * $Id: PollingReceiversRestartTestCase.java 19817 2010-10-04 18:10:39Z dzapata $
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  package org.mule.transport.http.functional;
11  
12  import org.mule.tck.DynamicPortTestCase;
13  import org.mule.tck.FunctionalTestCase;
14  import org.mule.tck.functional.CounterCallback;
15  import org.mule.tck.functional.FunctionalTestComponent;
16  
17  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
18  
19  public class PollingReceiversRestartTestCase extends DynamicPortTestCase
20  {
21      private static final int WAIT_TIME = 3000;
22  
23      public PollingReceiversRestartTestCase()
24      {
25          setStartContext(false);
26      }
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "polling-receivers-restart-test.xml";
32      }
33  
34      public void testPollingReceiversRestart() throws Exception
35      {
36          muleContext.start();
37  
38          Object ftc = getComponent("Test");
39          assertTrue("FunctionalTestComponent expected", ftc instanceof FunctionalTestComponent);
40  
41          AtomicInteger pollCounter = new AtomicInteger(0);
42          ((FunctionalTestComponent) ftc).setEventCallback(new CounterCallback(pollCounter));
43  
44          // should be enough to poll for 2 messages
45          Thread.sleep(WAIT_TIME);
46  
47          // stop
48          muleContext.stop();
49          assertTrue("No polls performed", pollCounter.get() > 0);
50  
51          // and restart
52          muleContext.start();
53  
54          pollCounter.set(0);
55          ((FunctionalTestComponent) ftc).setEventCallback(new CounterCallback(pollCounter));
56  
57          Thread.sleep(WAIT_TIME);
58          muleContext.dispose();
59          assertTrue("No polls performed", pollCounter.get() > 0);
60      }
61  
62      @Override
63      protected int getNumPortsToFind()
64      {
65          return 1;
66      }
67  }