View Javadoc

1   /*
2    * $Id: GracefulShutdownTimeoutTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.test.integration.work;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.api.service.Service;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.tck.functional.EventCallback;
17  import org.mule.tck.functional.FunctionalTestComponent;
18  import org.mule.util.concurrent.Latch;
19  
20  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
21  
22  public class GracefulShutdownTimeoutTestCase extends FunctionalTestCase
23  {
24  
25      @Override
26      protected String getConfigResources()
27      {
28          return "org/mule/test/integration/work/graceful-shutdown-timeout.xml";
29      }
30  
31      @Override
32      protected boolean isGracefulShutdown()
33      {
34          return true;
35      }
36  
37      /**
38       * Dispatch an event to a service component that takes longer than default
39       * graceful shutdown time to complete and customize the graceful shutdown timeout
40       * in configuration so that component execution is not interrupted. This tests
41       * services but the same applies to the graceful shutdown of
42       * receivers/dispatchers etc.
43       * 
44       * @throws Exception
45       */
46      public void testGracefulShutdownTimeout() throws Exception
47      {
48          final Latch latch = new Latch();
49          Service service = muleContext.getRegistry().lookupService("TestService");
50          FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent(service);
51          testComponent.setEventCallback(new EventCallback()
52          {
53  
54              public void eventReceived(MuleEventContext context, Object component) throws Exception
55              {
56                  Thread.sleep(5500);
57                  latch.countDown();
58  
59              }
60          });
61          service.dispatchEvent(getTestInboundEvent("test"));
62          Thread.sleep(200);
63          service.dispose();
64          assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
65      }
66  
67  }