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.MuleMessageCollection;
11  import org.mule.api.context.notification.RoutingNotificationListener;
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.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class AsyncReplyTimeoutTestCase extends FunctionalTestCase
25  {
26      
27      private CountDownLatch latch;
28      
29      @Override
30      protected String getConfigResources()
31      {
32          return "org/mule/test/integration/routing/multi-async-repy-timeout.xml";
33      }
34  
35      @Test
36      public void testAggregatorTimeoutWithoutFailure() throws Exception
37      {
38          latch = new CountDownLatch(1);
39  
40          muleContext.registerListener(new RoutingNotificationListener<RoutingNotification>() 
41          {
42              public void onNotification(RoutingNotification notification)
43              {
44                  if (notification.getAction() == RoutingNotification.MISSED_AGGREGATION_GROUP_EVENT)
45                  {
46                      latch.countDown();
47                      assertEquals("test Received Late!", ((MuleMessage)((RoutingNotification)notification).getSource()).getPayload());
48                  }
49              }
50          });
51  
52          String message = "test";
53          MuleClient client = new MuleClient(muleContext);
54          MuleMessage result = client.send("vm://distributor.queue", message, null);
55          assertNotNull(result);
56          assertTrue(result instanceof MuleMessageCollection);
57          MuleMessageCollection mc = (MuleMessageCollection)result;
58          assertEquals(2, mc.size());
59          for (int i = 0; i < mc.getMessagesAsArray().length; i++)
60          {
61              MuleMessage msg = mc.getMessagesAsArray()[i];
62              assertEquals("test Received", msg.getPayload());
63          }
64  
65          assertTrue(latch.await(3000, TimeUnit.MILLISECONDS));
66      }
67  }