View Javadoc

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