View Javadoc

1   /*
2    * $Id: TcpFunctionalTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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.transport.tcp;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.DynamicPortTestCase;
16  
17  public class TcpFunctionalTestCase extends DynamicPortTestCase 
18  {
19  
20      protected static String TEST_MESSAGE = "Test TCP Request";
21  
22      protected String getConfigResources()
23      {
24          return "tcp-functional-test.xml";
25      }
26  
27      public void testSend() throws Exception
28      {
29          MuleClient client = new MuleClient(muleContext);
30          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, null);
31          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
32      }
33  
34      public void testDispatchAndReply() throws Exception
35      {
36          MuleClient client = new MuleClient(muleContext);
37          client.dispatch("asyncClientEndpoint", TEST_MESSAGE, null);
38          // MULE-2754
39          Thread.sleep(100);
40          MuleMessage result =  client.request("asyncClientEndpoint", 10000);
41          assertNotNull(result);
42          assertEquals(TEST_MESSAGE + " Received Async", result.getPayloadAsString());
43      }
44  
45      public void timeMultipleSend() throws Exception
46      {
47          MuleClient client = new MuleClient(muleContext);
48          long now = System.currentTimeMillis();
49          int count = 1000;
50          for (int i = 0; i < count; i++)
51          {
52              MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, null);
53              assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
54          }
55          long later = System.currentTimeMillis();
56          double speed = count * 1000.0 / (later - now);
57          logger.error(speed + " messages per second");
58      }
59  
60      @Override
61      protected int getNumPortsToFind()
62      {
63          return 2;
64      }
65  }