View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.routing;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.context.notification.RoutingNotificationListener;
11  import org.mule.api.routing.ResponseTimeoutException;
12  import org.mule.context.notification.RoutingNotification;
13  import org.mule.module.client.MuleClient;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  
16  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
17  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertTrue;
22  
23  public class AsyncReplyTimeoutFailTestCase extends FunctionalTestCase
24  {
25  
26      private CountDownLatch latch;
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "org/mule/test/integration/routing/multi-async-repy-timeout-fail.xml";
32      }
33  
34      @Test
35      public void testAggregatorTimeoutWithFailure() throws Exception
36      {
37          latch = new CountDownLatch(1);
38  
39          muleContext.registerListener(new RoutingNotificationListener<RoutingNotification>() {
40              public void onNotification(RoutingNotification notification)
41              {
42                  if (notification.getAction() == RoutingNotification.ASYNC_REPLY_TIMEOUT)
43                  {
44                      latch.countDown();
45                  }
46              }
47          });
48  
49          String message = "test";
50          MuleClient client = new MuleClient(muleContext);
51          MuleMessage result = client.send("vm://distributor.queue", message, null);
52          assertNotNull(result);
53          assertNotNull(result.getExceptionPayload());
54          assertTrue(result.getExceptionPayload().getException() instanceof ResponseTimeoutException);
55  
56          assertTrue(latch.await(3000, TimeUnit.MILLISECONDS));
57      }
58  }