View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.client;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertNotNull;
16  import static org.junit.Assert.fail;
17  
18  public class MuleClientInThreadTestCase extends FunctionalTestCase
19  {
20  
21      int numMessages = 100000;
22      
23      @Override
24      protected String getConfigResources()
25      {
26          return "org/mule/test/integration/client/client-in-thread.xml";
27      }
28  
29      @Test
30      public void testException() throws Exception
31      {
32          Thread tester1 = new Tester();
33          tester1.start();
34      }
35      
36      class Tester extends Thread
37      {
38          @Override
39          public void run()
40          {
41              try
42              {
43                  MuleClient client = new MuleClient(muleContext);
44                  
45                  for (int i = 0; i < numMessages; ++i)
46                  {
47                      client.dispatch("vm://in", "test", null);
48                  }
49      
50                  MuleMessage msg;
51                  for (int i = 0; i < numMessages; ++i)
52                  {
53                      msg = client.request("vm://out", 5000);
54                      assertNotNull(msg);
55                  }
56              }
57              catch (Exception e)
58              {
59                  fail(e.getMessage());
60              }
61          }        
62      };
63  }
64  
65