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