1   /*
2    * $Id: AsyncReplyTimeoutFailTestCase.java 11514 2008-03-30 21:13:10Z 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  
11  package org.mule.test.integration.routing;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.context.notification.RoutingNotificationListener;
15  import org.mule.api.context.notification.ServerNotification;
16  import org.mule.api.routing.ResponseTimeoutException;
17  import org.mule.context.notification.RoutingNotification;
18  import org.mule.module.client.MuleClient;
19  import org.mule.tck.FunctionalTestCase;
20  
21  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
22  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
23  
24  public class AsyncReplyTimeoutFailTestCase extends FunctionalTestCase
25  {
26      private CountDownLatch latch;
27  
28      protected String getConfigResources()
29      {
30          return "org/mule/test/integration/routing/multi-async-repy-timeout-fail.xml";
31      }
32  
33      public void testAggregatorTimeoutWithFailure() throws Exception
34      {
35          latch = new CountDownLatch(1);
36  
37          muleContext.registerListener(new RoutingNotificationListener() {
38              public void onNotification(ServerNotification notification)
39              {
40                  if(notification.getAction() == RoutingNotification.ASYNC_REPLY_TIMEOUT)
41                  {
42                      latch.countDown();
43                  }
44              }
45          });
46  
47          String message = "test";
48          MuleClient client = new MuleClient();
49          MuleMessage result = client.send("vm://distributor.queue", message, null);
50          assertNotNull(result);
51          assertNotNull(result.getExceptionPayload());
52          assertTrue(result.getExceptionPayload().getException() instanceof ResponseTimeoutException);
53  
54          assertTrue(latch.await(3000, TimeUnit.MILLISECONDS));
55      }
56  }