Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9F135BB3D for ; Wed, 4 Jan 2012 05:22:04 +0000 (UTC) Received: (qmail 19864 invoked by uid 500); 4 Jan 2012 05:22:04 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 19806 invoked by uid 500); 4 Jan 2012 05:22:03 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 19799 invoked by uid 99); 4 Jan 2012 05:22:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jan 2012 05:22:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jan 2012 05:22:02 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E4583238897D for ; Wed, 4 Jan 2012 05:21:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1227046 - /camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java Date: Wed, 04 Jan 2012 05:21:41 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120104052141.E4583238897D@eris.apache.org> Author: davsclaus Date: Wed Jan 4 05:21:41 2012 New Revision: 1227046 URL: http://svn.apache.org/viewvc?rev=1227046&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/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java?rev=1227046&r1=1227045&r2=1227046&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java Wed Jan 4 05:21:41 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 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 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