View Javadoc

1   /*
2    * $Id: ManySendsMule1758TestCase.java 22421 2011-07-15 05:05:06Z 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.issues;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  
17  import java.util.Arrays;
18  import java.util.Collection;
19  
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  
26  public class ManySendsMule1758TestCase extends AbstractServiceAndFlowTestCase
27  {
28      private static int NUM_MESSAGES = 3000;
29  
30      @Parameters
31      public static Collection<Object[]> parameters()
32      {
33          return Arrays.asList(new Object[][]{
34              {ConfigVariant.SERVICE, "org/mule/issues/many-sends-mule-1758-test-service.xml"},
35              {ConfigVariant.FLOW, "org/mule/issues/many-sends-mule-1758-test-flow.xml"}
36          });
37      }
38  
39      public ManySendsMule1758TestCase(ConfigVariant variant, String configResources)
40      {
41          super(variant, configResources);
42      }
43  
44      @Test
45      public void testSingleSend() throws Exception
46      {
47          MuleClient client = new MuleClient(muleContext);
48          MuleMessage response = client.send("vm://s-in", "Marco", null);
49          assertNotNull("Response is null", response);
50          assertEquals("Polo", response.getPayload());
51      }
52  
53      @Test
54      public void testManySends() throws Exception
55      {
56          long then = System.currentTimeMillis();
57          MuleClient client = new MuleClient(muleContext);
58          for (int i = 0; i < NUM_MESSAGES; ++i)
59          {
60              logger.debug("Message " + i);
61              MuleMessage response = client.send("vm://s-in", "Marco", null);
62              assertNotNull("Response is null", response);
63              assertEquals("Polo", response.getPayload());
64          }
65          long now = System.currentTimeMillis();
66          logger.info("Total time " + ((now - then) / 1000.0) + "s; per message " + ((now - then) / (1.0 * NUM_MESSAGES)) + "ms");
67      }
68  }