View Javadoc

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