View Javadoc

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