View Javadoc

1   /*
2    * $Id: MuleMessageProtocolChunkingTestCase.java 22450 2011-07-19 08:20:41Z 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.transport.tcp.integration;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.junit4.FunctionalTestCase;
17  import org.mule.tck.junit4.rule.DynamicPort;
18  
19  import org.junit.Rule;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertTrue;
25  
26  /**
27   * This test was set for the new changes due to Mule1199
28   */
29  public class MuleMessageProtocolChunkingTestCase extends FunctionalTestCase
30  {
31  
32      public static final long WAIT_MS = 3000L;
33      private static int messages = 2;
34      private static int messagelength = 10;
35  
36      @Rule
37      public DynamicPort dynamicPort = new DynamicPort("port1");
38      
39      @Override
40      protected String getConfigResources()
41      {
42          return "mule-message-protocol-mule-config.xml";
43      }
44  
45      @Test
46      public void testChunking() throws Exception
47      {
48          String message = "";
49          for (int i = 0; i < messagelength; i++)
50          {
51              for (int j = 0; j < 10; j++)
52                  message += i;
53          }
54          sendString(message);
55      }
56  
57      @Test
58      public void testHugeChunk() throws Exception
59      {
60          StringBuffer message = new StringBuffer();
61          // send 50K of stuff;
62          for (int i = 1000; i < 2000; i++)
63          {
64              message.append(i);
65          }
66          sendString(message.toString());
67      }
68  
69      @Test
70      public void testCustomObject() throws Exception
71      {
72          MuleClient client = new MuleClient(muleContext);
73          StringBuffer sBuffer = new StringBuffer();
74          // send 50K of stuff;
75          for (int i = 10000; i < 20000; i++)
76          {
77              sBuffer.append(i);
78          }
79          MessageObject message = new MessageObject(1, sBuffer.toString(), true);
80  
81          for (int i = 0; i < messages; i++)
82          {
83              client.dispatch("vm://in", new DefaultMuleMessage(message, muleContext));
84          }
85  
86          for (int i = 0; i < messages; i++)
87          {
88              MuleMessage msg = client.request("vm://out", WAIT_MS);
89              assertNotNull(msg);
90              assertTrue(msg.getPayload() instanceof MessageObject);
91              MessageObject received = (MessageObject)msg.getPayload();
92              assertEquals(message.s, received.s);
93              assertEquals(1, received.i);
94              assertEquals(true, received.b);
95          }
96      }
97  
98      private void sendString(String message) throws Exception
99      {
100         MuleClient client = new MuleClient(muleContext);
101 
102         for (int i = 0; i < messages; i++)
103         {
104             client.dispatch("vm://in", new DefaultMuleMessage(message, muleContext));
105         }
106         for (int i = 0; i < messages; i++)
107         {
108             MuleMessage msg = client.request("vm://out", WAIT_MS);
109             assertEquals(message, new String((byte[])msg.getPayload()));
110         }
111     }
112 
113 }