View Javadoc

1   /*
2    * $Id: FlowAynchronousProcessingStrategyTestCase.java 22655 2011-08-12 07:34:14Z mike.schilling $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.construct;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.client.MuleClient;
15  import org.mule.transaction.TransactionCoordination;
16  
17  public class FlowAynchronousProcessingStrategyTestCase extends FlowDefaultProcessingStrategyTestCase
18  {
19  
20      @Override
21      protected String getConfigResources()
22      {
23          return "org/mule/test/construct/flow-asynchronous-processing-strategy-config.xml";
24      }
25  
26      @Override
27      public void testDispatchToOneWayInboundTxOnly() throws Exception
28      {
29          MuleClient client = muleContext.getClient();
30          client.dispatch("vm://oneway-inboundtx-in", "a", null);
31          MuleMessage result = client.request("vm://dead-letter-queue", RECEIVE_TIMEOUT);
32          assertNotNull(result);
33      }
34  
35      public void testDispatchToOneWayTx() throws Exception
36      {
37          MuleClient client = muleContext.getClient();
38          client.dispatch("vm://onewaytx-in", "a", null);
39  
40          assertNull(client.request("vm://onewaytx-out", RECEIVE_TIMEOUT));
41  
42          // TODO Assert exception strategy was called
43  
44      }
45  
46      public void testSendToOneWayTx() throws Exception
47      {
48          MuleClient client = muleContext.getClient();
49  
50          try
51          {
52              client.send("vm://oneway-tx-in", "a", null);
53              fail("Exception expected");
54          }
55          catch (Exception e)
56          {
57              TransactionCoordination.getInstance().getTransaction().rollback();
58          }
59      }
60  
61      public void testSendRequestResponseInbound() throws Exception
62      {
63          MuleClient client = muleContext.getClient();
64          try
65          {
66              client.send("vm://requestresponse-in", "a", null);
67              fail("Exception expected");
68          }
69          catch (Exception e)
70          {
71          }
72      }
73  
74      public void testDispatchToRequestResponseInboundOneWayOutbound() throws Exception
75      {
76          MuleClient client = muleContext.getClient();
77  
78          client.dispatch("vm://requestresponse-oneway-in", "a", null);
79  
80          // Message never gets to reciever as receiver is not polling the queue
81          assertNull(client.request("vm://requestresponse-oneway-out", RECEIVE_TIMEOUT));
82  
83          // TODO Assert exception strategy was called
84  
85      }
86  
87      public void testSendToRequestResponseInboundOneWayOutbound() throws Exception
88      {
89          MuleClient client = muleContext.getClient();
90  
91          try
92          {
93              client.send("vm://requestresponse-oneway-in", "a", null);
94              fail("Exception expected");
95          }
96          catch (Exception e)
97          {
98          }
99      }
100 
101     protected void assertAllProcessingInClientThread(MuleMessage result)
102     {
103         assertSync(result);
104         assertEquals(Thread.currentThread().getName(), result.getInboundProperty("receiver-thread"));
105     }
106 
107     protected void assertAllProcessingInRecieverThread(MuleMessage result)
108     {
109         assertSync(result);
110         assertTrue(((String) result.getInboundProperty("receiver-thread")).startsWith("vm.receiver"));
111     }
112 
113     protected void assertSync(MuleMessage result)
114     {
115         assertNotNull(result);
116 
117         String receiverThread = result.getInboundProperty("receiver-thread");
118         String flowThread = result.getInboundProperty("processor-thread");
119         String dispatcherThread = result.getInboundProperty("dispatcher-thread");
120 
121         assertEquals(receiverThread, flowThread);
122         assertEquals(flowThread, dispatcherThread);
123     }
124 
125     protected void assertAllProcessingAsync(MuleMessage result)
126     {
127         assertNotNull(result);
128 
129         String receiverThread = result.getInboundProperty("receiver-thread");
130         String flowThread = result.getInboundProperty("processor-thread");
131         String dispatcherThread = result.getInboundProperty("dispatcher-thread");
132 
133         assertTrue(receiverThread.startsWith("vm.receiver"));
134         assertFalse(receiverThread.equals(flowThread));
135         assertFalse(flowThread.equals(dispatcherThread));
136         assertFalse(receiverThread.equals(dispatcherThread));
137     }
138 
139     public void testRequestResponseInboundFailingOneWayOutbound() throws Exception
140     {
141         MuleClient client = muleContext.getClient();
142 
143         try
144         {
145             MuleMessage response = client.send("vm://requestresponse-failingoneway-in", "a", null);
146             fail("exception expected");
147         }
148         catch (Exception e)
149         {
150 
151         }
152     }
153 
154 }