Author: davsclaus Date: Wed Jan 4 05:29:50 2012 New Revision: 1227048 URL: http://svn.apache.org/viewvc?rev=1227048&view=rev Log: CAMEL-4842: Removing route should remove producer cache from JMX, as well from services to close list on CamelContext, to not eat up memory.
Modified: camel/branches/camel-2.8.x/ (props changed) camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java Propchange: camel/branches/camel-2.8.x/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Jan 4 05:29:50 2012 @@ -1 +1 @@ -/camel/trunk:1212504,1215477,1221565,1224674,1225077-1225078,1225766,1226081,1226387,1226430,1226867 +/camel/trunk:1212504,1215477,1221565,1224674,1225077-1225078,1225766,1226081,1226387,1226430,1226867,1227046 Propchange: camel/branches/camel-2.8.x/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java?rev=1227048&r1=1227047&r2=1227048&view=diff ============================================================================== --- camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java (original) +++ camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java Wed Jan 4 05:29:50 2012 @@ -40,7 +40,7 @@ public class ManagedRouteAddRemoveTest e }; } - public void testRouteAddRemoteRoute() throws Exception { + public void testRouteAddRemoteRouteWithTo() throws Exception { MockEndpoint result = getMockEndpoint("mock:result"); result.expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); @@ -88,4 +88,100 @@ public class ManagedRouteAddRemoveTest e log.info("Shutting down..."); } + public void testRouteAddRemoteRouteWithRecipientList() throws Exception { + MockEndpoint result = getMockEndpoint("mock:result"); + result.expectedMessageCount(1); + template.sendBody("direct:start", "Hello World"); + result.assertIsSatisfied(); + + MBeanServer mbeanServer = getMBeanServer(); + ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=services,name=ProducerCache*"); + + // number of producer caches + Set<ObjectName> names = mbeanServer.queryNames(on, null); + assertEquals(1, names.size()); + + log.info("Adding 2nd route"); + + // add a 2nd route + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:bar").routeId("bar").recipientList(header("bar")); + } + }); + + // and send a message to it + MockEndpoint bar = getMockEndpoint("mock:bar"); + bar.expectedMessageCount(1); + template.sendBodyAndHeader("direct:bar", "Hello World", "bar", "mock:bar"); + bar.assertIsSatisfied(); + + // there should be one more producer cache + names = mbeanServer.queryNames(on, null); + assertEquals(2, names.size()); + + log.info("Removing 2nd route"); + + // now remove the 2nd route + context.stopRoute("bar"); + boolean removed = context.removeRoute("bar"); + assertTrue(removed); + + // the producer cache should have been removed + on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=services,name=ProducerCache*"); + names = mbeanServer.queryNames(on, null); + assertEquals(1, names.size()); + + log.info("Shutting down..."); + } + + public void testRouteAddRemoteRouteWithRoutingSlip() throws Exception { + MockEndpoint result = getMockEndpoint("mock:result"); + result.expectedMessageCount(1); + template.sendBody("direct:start", "Hello World"); + result.assertIsSatisfied(); + + MBeanServer mbeanServer = getMBeanServer(); + ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=services,name=ProducerCache*"); + + // number of producer caches + Set<ObjectName> names = mbeanServer.queryNames(on, null); + assertEquals(1, names.size()); + + log.info("Adding 2nd route"); + + // add a 2nd route + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:bar").routeId("bar").routingSlip(header("bar")); + } + }); + + // and send a message to it + MockEndpoint bar = getMockEndpoint("mock:bar"); + bar.expectedMessageCount(1); + template.sendBodyAndHeader("direct:bar", "Hello World", "bar", "mock:bar"); + bar.assertIsSatisfied(); + + // there should be one more producer cache + names = mbeanServer.queryNames(on, null); + assertEquals(2, names.size()); + + log.info("Removing 2nd route"); + + // now remove the 2nd route + context.stopRoute("bar"); + boolean removed = context.removeRoute("bar"); + assertTrue(removed); + + // the producer cache should have been removed + on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=services,name=ProducerCache*"); + names = mbeanServer.queryNames(on, null); + assertEquals(1, names.size()); + + log.info("Shutting down..."); + } + } \ No newline at end of file