View Javadoc

1   /*
2    * $Id: MuleClientInThreadTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.client;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  
17  public class MuleClientInThreadTestCase extends FunctionalTestCase
18  {
19      int numMessages = 100000;
20      
21      @Override
22      protected String getConfigResources()
23      {
24          return "org/mule/test/integration/client/client-in-thread.xml";
25      }
26  
27      public void testException() throws Exception
28      {
29          Thread tester1 = new Tester();
30          tester1.start();
31      }
32      
33      class Tester extends Thread
34      {
35          @Override
36          public void run()
37          {
38              try
39              {
40                  MuleClient client = new MuleClient(muleContext);
41                  
42                  for (int i = 0; i < numMessages; ++i)
43                  {
44                      client.dispatch("vm://in", "test", null);
45                  }
46      
47                  MuleMessage msg;
48                  for (int i = 0; i < numMessages; ++i)
49                  {
50                      msg = client.request("vm://out", 5000);
51                      assertNotNull(msg);
52                  }
53              }
54              catch (Exception e)
55              {
56                  fail(e.getMessage());
57              }
58          }        
59      };
60  }
61  
62