View Javadoc

1   /*
2    * $Id: CxfClientPassivateTestCase.java 19692 2010-09-21 23:50:35Z aperepel $
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.transport.cxf;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.processor.MessageProcessor;
15  import org.mule.endpoint.AbstractEndpointBuilder;
16  import org.mule.module.client.MuleClient;
17  import org.mule.module.cxf.CxfOutboundMessageProcessor;
18  import org.mule.module.cxf.config.FlowConfiguringMessageProcessor;
19  import org.mule.tck.FunctionalTestCase;
20  
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.apache.cxf.endpoint.Client;
25  
26  public class CxfClientPassivateTestCase extends FunctionalTestCase
27  {
28  
29      @Override
30      protected String getConfigResources()
31      {
32          return "org/mule/test/integration/transport/cxf/cxf-memoryleak-config.xml";
33      }
34  
35      /**
36       * Test that CxfMessageDispatcher's passivate method cleans up the CXF
37       * client request and response contexts. This is needed in order to release
38       * the memory occupied by that objects, which could be a lot of wasted
39       * memory because of the number of CxfMessageDispatchers that live in the
40       * dispatcher pool. See MULE-4899 for more details.
41       */
42      public void testPassivateCleansClientRequestAndResponseContext() throws Exception
43      {
44          MuleClient muleClient = new MuleClient(muleContext);
45  
46          // Sends data to process
47          muleClient.send("vm://in", TEST_MESSAGE, null);
48  
49          // Waits for a response
50          MuleMessage message = muleClient.request("vm://out", 5000);
51          assertNotNull(message);
52  
53          CxfOutboundMessageProcessor processor = getOutboundMessageProcessor();
54  
55          Client client = processor.getClient();
56  
57          final Map<String, Object> requestContext = client.getRequestContext();
58          assertTrue("Request context should be empty", requestContext.isEmpty());
59  
60          final Map<String, Object> responseContext = client.getResponseContext();
61          assertTrue("Response context should be empty", responseContext.isEmpty());
62      }
63  
64      private CxfOutboundMessageProcessor getOutboundMessageProcessor()
65      {
66          AbstractEndpointBuilder epbuilder = (AbstractEndpointBuilder) muleContext.getRegistry().lookupEndpointBuilder("clientEndpoint");
67          
68          List<MessageProcessor> mps = epbuilder.getMessageProcessors();
69          return (CxfOutboundMessageProcessor) ((FlowConfiguringMessageProcessor)mps.get(0)).getWrappedMessageProcessor();
70      }
71  
72  }