View Javadoc

1   /*
2    * $Id: MuleClientInThreadTestCase.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.test.integration.client;
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.assertNotNull;
24  import static org.junit.Assert.fail;
25  
26  public class MuleClientInThreadTestCase extends AbstractServiceAndFlowTestCase
27  {
28      int numMessages = 100000;
29  
30      @Parameters
31      public static Collection<Object[]> parameters()
32      {
33          return Arrays.asList(new Object[][]{
34              {ConfigVariant.SERVICE, "org/mule/test/integration/client/client-in-thread-service.xml"},
35              {ConfigVariant.FLOW, "org/mule/test/integration/client/client-in-thread-flow.xml"}
36          });
37      }
38  
39      public MuleClientInThreadTestCase(ConfigVariant variant, String configResources)
40      {
41          super(variant, configResources);
42      }
43  
44      @Test
45      public void testException() throws Exception
46      {
47          Thread tester1 = new Tester();
48          tester1.start();
49      }
50  
51      class Tester extends Thread
52      {
53          @Override
54          public void run()
55          {
56              try
57              {
58                  MuleClient client = new MuleClient(muleContext);
59  
60                  for (int i = 0; i < numMessages; ++i)
61                  {
62                      client.dispatch("vm://in", "test", null);
63                  }
64  
65                  MuleMessage msg;
66                  for (int i = 0; i < numMessages; ++i)
67                  {
68                      msg = client.request("vm://out", 5000);
69                      assertNotNull(msg);
70                  }
71              }
72              catch (Exception e)
73              {
74                  fail(e.getMessage());
75              }
76          }
77      }
78  }