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