Updated Branches: refs/heads/master a9ca68dc4 -> bf3210f14
CAMEL-6942: Fixed the very long running JmsPerformanceTest & JmsMediumQueuePerformanceTest. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bf3210f1 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bf3210f1 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bf3210f1 Branch: refs/heads/master Commit: bf3210f14eb309977cd9fca925495600b9eaa767 Parents: a9ca68d Author: Babak Vahdat <[email protected]> Authored: Wed Nov 6 22:25:39 2013 +0100 Committer: Babak Vahdat <[email protected]> Committed: Wed Nov 6 22:25:39 2013 +0100 ---------------------------------------------------------------------- .../jms/JmsMediumQueuePerformanceTest.java | 48 +------ .../camel/itest/jms/JmsPerformanceTest.java | 133 +++++++------------ .../src/test/resources/activemq7.xml | 33 ----- .../src/test/resources/activemq8.xml | 33 ----- 4 files changed, 50 insertions(+), 197 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/bf3210f1/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java index 4969ece..2805307 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java @@ -16,57 +16,13 @@ */ package org.apache.camel.itest.jms; -import javax.jms.ConnectionFactory; -import javax.naming.Context; - -import org.apache.activemq.ActiveMQConnectionFactory; -import org.apache.camel.component.jms.JmsComponent; -import org.apache.camel.util.jndi.JndiContext; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * @version */ public class JmsMediumQueuePerformanceTest extends JmsPerformanceTest { - private static final Logger LOG = LoggerFactory.getLogger(JmsMediumQueuePerformanceTest.class); - - protected int mediumQueueCount = 1000; - - @Override - protected String getActiveMQFileName() { - // using different port number to avoid clash - return "activemq8.xml"; - } - - @Override - protected Context createJndiContext() throws Exception { - JndiContext answer = new JndiContext(); - answer.bind("myBean", myBean); - - // add ActiveMQ client - ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker8"); - answer.bind("activemq", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); - - return answer; - } @Override - @Test - public void testSendingAndReceivingMessages() throws Exception { - int expected = mediumQueueCount + messageCount; - setExpectedMessageCount(expected); - - LOG.info("Sending {} messages first", mediumQueueCount); - sendLoop(0, mediumQueueCount); - LOG.info("Sent..."); - - Thread.sleep(1000); - - LOG.info("Now testing"); - timedSendLoop(mediumQueueCount, expected); - - assertExpectedMessagesReceived(); + protected int getMessageCount() { + return 1000; } } http://git-wip-us.apache.org/repos/asf/camel/blob/bf3210f1/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java index ac42f66..747e6ae 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java @@ -16,65 +16,49 @@ */ package org.apache.camel.itest.jms; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; +import java.util.ArrayList; +import java.util.List; -import javax.jms.ConnectionFactory; import javax.naming.Context; import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.pool.PooledConnectionFactory; +import org.apache.camel.Header; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.jms.JmsComponent; import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.camel.util.jndi.JndiContext; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.support.ClassPathXmlApplicationContext; /** - * @version + * @version */ public class JmsPerformanceTest extends CamelTestSupport { - private static final Logger LOG = LoggerFactory.getLogger(JmsPerformanceTest.class); - protected MyBean myBean = new MyBean(); - protected int messageCount = 1000; - protected CountDownLatch receivedCountDown = new CountDownLatch(messageCount); - protected long consumerSleep; - protected int expectedMessageCount; - protected ClassPathXmlApplicationContext applicationContext; - protected boolean useLocalBroker = true; - private int consumedMessageCount; - - protected String getActiveMQFileName() { - // using different port number to avoid clash - return "activemq7.xml"; - } + private List<Integer> receivedHeaders = new ArrayList<Integer>(getMessageCount()); + private List<Object> receivedMessages = new ArrayList<Object>(getMessageCount()); @Test public void testSendingAndReceivingMessages() throws Exception { - setExpectedMessageCount(messageCount); + log.info("Sending {} messages", getMessageCount()); + + sendLoop(getMessageCount()); - timedSendLoop(0, messageCount); + log.info("Sending {} messages completed, now will assert on their content as well as the order of their receipt", getMessageCount()); + + // should wait a bit to make sure all messages have been received by the MyBean#onMessage() method + // as this happens asynchronously, that's not inside the 'main' thread + Thread.sleep(3000); assertExpectedMessagesReceived(); } - - protected void sendLoop(int startIndex, int endIndex) { - for (int i = startIndex; i < endIndex; i++) { - sendMessage(i); - } + protected int getMessageCount() { + return 100; } - protected void timedSendLoop(int startIndex, int endIndex) { - StopWatch watch = new StopWatch("Sending"); - for (int i = startIndex; i < endIndex; i++) { - watch.start(); + protected void sendLoop(int messageCount) { + for (int i = 1; i <= messageCount; i++) { sendMessage(i); - watch.stop(); } } @@ -82,36 +66,42 @@ public class JmsPerformanceTest extends CamelTestSupport { template.sendBodyAndHeader("activemq:" + getQueueName(), "Hello:" + messageCount, "counter", messageCount); } - public String getQueueName() { + protected String getQueueName() { return "testSendingAndReceivingMessages"; } protected void assertExpectedMessagesReceived() throws InterruptedException { - assertTrue(receivedCountDown.await(50, TimeUnit.SECONDS)); + // assert on the expected message count + assertEquals("The expected message count does not match!", getMessageCount(), receivedMessages.size()); - assertEquals("Received message count", expectedMessageCount, consumedMessageCount); - - // TODO assert that messages are received in order - } + // assert on the expected message order + List<Integer> expectedHeaders = new ArrayList<Integer>(getMessageCount()); + for (int i = 1; i <= getMessageCount(); i++) { + expectedHeaders.add(i); + } - @Override - @Before - public void setUp() throws Exception { - if (useLocalBroker) { - applicationContext = new ClassPathXmlApplicationContext(getActiveMQFileName()); - applicationContext.start(); + List<Object> expectedMessages = new ArrayList<Object>(getMessageCount()); + for (int i = 1; i <= getMessageCount(); i++) { + expectedMessages.add("Hello:" + i); } - super.setUp(); + assertEquals("The expected header order does not match!", expectedHeaders, receivedHeaders); + assertEquals("The expected message order does not match!", expectedMessages, receivedMessages); } @Override - @After - public void tearDown() throws Exception { - super.tearDown(); - if (applicationContext != null) { - applicationContext.stop(); - } + protected Context createJndiContext() throws Exception { + JndiContext answer = new JndiContext(); + answer.bind("myBean", new MyBean()); + + // add AMQ client and make use of connection pooling we depend on because of the (large) number + // of the JMS messages we do produce + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker"); + PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(connectionFactory); + pooledConnectionFactory.setMaxConnections(10); + answer.bind("activemq", JmsComponent.jmsComponentAutoAcknowledge(pooledConnectionFactory)); + + return answer; } @Override @@ -123,38 +113,11 @@ public class JmsPerformanceTest extends CamelTestSupport { }; } - @Override - protected Context createJndiContext() throws Exception { - JndiContext answer = new JndiContext(); - answer.bind("myBean", myBean); - - // add ActiveMQ client - ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker7"); - answer.bind("activemq", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); - - return answer; - } - - public int getExpectedMessageCount() { - return expectedMessageCount; - } - - public void setExpectedMessageCount(int expectedMessageCount) { - this.expectedMessageCount = expectedMessageCount; - receivedCountDown = new CountDownLatch(expectedMessageCount); - } - protected class MyBean { - public void onMessage(String body) { - if (consumerSleep > 0) { - try { - Thread.sleep(consumerSleep); - } catch (InterruptedException e) { - LOG.warn("Caught: " + e, e); - } - } - consumedMessageCount++; - receivedCountDown.countDown(); + public void onMessage(@Header("counter") int counter, Object body) { + // the invocation of this method happens inside the same thread so no need for a thread-safe list here + receivedHeaders.add(counter); + receivedMessages.add(body); } } } http://git-wip-us.apache.org/repos/asf/camel/blob/bf3210f1/tests/camel-itest/src/test/resources/activemq7.xml ---------------------------------------------------------------------- diff --git a/tests/camel-itest/src/test/resources/activemq7.xml b/tests/camel-itest/src/test/resources/activemq7.xml deleted file mode 100644 index 937d744..0000000 --- a/tests/camel-itest/src/test/resources/activemq7.xml +++ /dev/null @@ -1,33 +0,0 @@ -<!-- - 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. ---> -<!-- START SNIPPET: example --> -<beans - xmlns="http://www.springframework.org/schema/beans" - xmlns:broker="http://activemq.apache.org/schema/core" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> - - <broker:broker id="broker7" useJmx="false" persistent="false" dataDirectory="target/activemq"> - <broker:transportConnectors> - <broker:transportConnector name="openwire" uri="vm:broker7"/> - </broker:transportConnectors> - </broker:broker> - - -</beans> -<!-- END SNIPPET: example --> http://git-wip-us.apache.org/repos/asf/camel/blob/bf3210f1/tests/camel-itest/src/test/resources/activemq8.xml ---------------------------------------------------------------------- diff --git a/tests/camel-itest/src/test/resources/activemq8.xml b/tests/camel-itest/src/test/resources/activemq8.xml deleted file mode 100644 index 561a506..0000000 --- a/tests/camel-itest/src/test/resources/activemq8.xml +++ /dev/null @@ -1,33 +0,0 @@ -<!-- - 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. ---> -<!-- START SNIPPET: example --> -<beans - xmlns="http://www.springframework.org/schema/beans" - xmlns:broker="http://activemq.apache.org/schema/core" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> - - <broker:broker id="broker8" useJmx="false" persistent="false" dataDirectory="target/activemq"> - <broker:transportConnectors> - <broker:transportConnector name="openwire" uri="vm:broker8"/> - </broker:transportConnectors> - </broker:broker> - - -</beans> -<!-- END SNIPPET: example -->
