View Javadoc

1   /*
2    * $Id: InboundAggregationWithTimeoutTestCase.java 22422 2011-07-15 08:22:16Z dirk.olmes $
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.context.notification.RoutingNotificationListener;
14  import org.mule.context.notification.RoutingNotification;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.AbstractServiceAndFlowTestCase;
17  
18  import java.util.Arrays;
19  import java.util.Collection;
20  import java.util.concurrent.CountDownLatch;
21  import java.util.concurrent.TimeUnit;
22  
23  import org.junit.Test;
24  import org.junit.runners.Parameterized.Parameters;
25  
26  import static org.junit.Assert.assertTrue;
27  
28  public class InboundAggregationWithTimeoutTestCase extends AbstractServiceAndFlowTestCase
29  {
30      @Parameters
31      public static Collection<Object[]> parameters()
32      {
33          return Arrays.asList(new Object[][]{
34              {ConfigVariant.SERVICE, "org/mule/test/integration/routing/multi-inbound-aggregator-with-timeout-service.xml"},
35              {ConfigVariant.FLOW, "org/mule/test/integration/routing/multi-inbound-aggregator-with-timeout-flow.xml"}
36          });
37      }
38  
39      public InboundAggregationWithTimeoutTestCase(ConfigVariant variant, String configResources)
40      {
41          super(variant, configResources);
42      }
43  
44      @Test
45      public void testAggregatorTimeout() throws Exception
46      {
47          final CountDownLatch latch = new CountDownLatch(1);
48  
49          muleContext.registerListener(new RoutingNotificationListener<RoutingNotification>()
50          {
51              @Override
52              public void onNotification(RoutingNotification notification)
53              {
54                  if (notification.getAction() == RoutingNotification.CORRELATION_TIMEOUT)
55                  {
56                      latch.countDown();
57                  }
58              }
59          });
60  
61          String message = "test";
62          MuleClient client = new MuleClient(muleContext);
63          client.dispatch("vm://distributor.queue", message, null);
64  
65          assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
66      }
67  }