Updated Branches: refs/heads/master ea325e32d -> 5721e40ef
CAMEL-6093: Multiple consumers exists on the same JMS endpoint uri and if you remove a consumer the other active consumers do not receive any messages anymore. Added unit test Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5721e40e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5721e40e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5721e40e Branch: refs/heads/master Commit: 5721e40ef3af68952c2eb7adf3518faf956cac40 Parents: ea325e3 Author: cmueller <cmuel...@apache.org> Authored: Sun Aug 25 22:18:30 2013 +0200 Committer: cmueller <cmuel...@apache.org> Committed: Sun Aug 25 22:18:30 2013 +0200 ---------------------------------------------------------------------- .../jms/TwoConsumerOnSameQueueTest.java | 117 +++++++++++++++++++ .../jms/TwoConsumerOnSameTopicTest.java | 5 +- 2 files changed, 118 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5721e40e/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameQueueTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameQueueTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameQueueTest.java new file mode 100644 index 0000000..3cdfd9e --- /dev/null +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameQueueTest.java @@ -0,0 +1,117 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jms; + +import javax.jms.ConnectionFactory; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Ignore; +import org.junit.Test; + +import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge; + +public class TwoConsumerOnSameQueueTest extends CamelTestSupport { + + @Test + public void testTwoConsumerOnSameQueue() throws Exception { + sendTwoMessagesWhichShouldReceivedOnBothEndpointsAndAssert(); + } + + @Test + public void testStopAndStartOneRoute() throws Exception { + sendTwoMessagesWhichShouldReceivedOnBothEndpointsAndAssert(); + + // now stop route A + context.stopRoute("a"); + + // send new message should go to B only + resetMocks(); + + getMockEndpoint("mock:a").expectedMessageCount(0); + getMockEndpoint("mock:b").expectedBodiesReceived("Bye World", "Bye World"); + + template.sendBody("activemq:queue:foo", "Bye World"); + template.sendBody("activemq:queue:foo", "Bye World"); + + assertMockEndpointsSatisfied(); + + // now start route A + context.startRoute("a"); + + // send new message should go to both A and B + resetMocks(); + + sendTwoMessagesWhichShouldReceivedOnBothEndpointsAndAssert(); + } + + @Test + @Ignore + public void testRemoveOneRoute() throws Exception { + sendTwoMessagesWhichShouldReceivedOnBothEndpointsAndAssert(); + + // now stop and remove route A + context.stopRoute("a"); + assertTrue(context.removeRoute("a")); + + // send new message should go to B only + resetMocks(); + + getMockEndpoint("mock:a").expectedMessageCount(0); + getMockEndpoint("mock:b").expectedBodiesReceived("Bye World", "Bye World"); + + template.sendBody("activemq:queue:foo", "Bye World"); + template.sendBody("activemq:queue:foo", "Bye World"); + + assertMockEndpointsSatisfied(); + } + + private void sendTwoMessagesWhichShouldReceivedOnBothEndpointsAndAssert() throws InterruptedException { + getMockEndpoint("mock:a").expectedBodiesReceived("Hello World"); + getMockEndpoint("mock:b").expectedBodiesReceived("Hello World"); + + template.sendBody("activemq:queue:foo", "Hello World"); + template.sendBody("activemq:queue:foo", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + protected CamelContext createCamelContext() throws Exception { + CamelContext camelContext = super.createCamelContext(); + + ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); //CamelJmsTestHelper.createConnectionFactory(); + camelContext.addComponent("activemq", jmsComponentAutoAcknowledge(connectionFactory)); + + return camelContext; + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("activemq:queue:foo").routeId("a") + .to("mock:a"); + + from("activemq:queue:foo").routeId("b") + .to("mock:b"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/5721e40e/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameTopicTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameTopicTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameTopicTest.java index a389fa2..90d02fc 100644 --- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameTopicTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameTopicTest.java @@ -25,9 +25,6 @@ import org.junit.Test; import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge; -/** - * - */ public class TwoConsumerOnSameTopicTest extends CamelTestSupport { @Test @@ -83,7 +80,7 @@ public class TwoConsumerOnSameTopicTest extends CamelTestSupport { // now stop and remove route A context.stopRoute("a"); - context.removeRoute("a"); + assertTrue(context.removeRoute("a")); // send new message should go to B only resetMocks();