From 0a997b7eaebff2c36b5c8c1c8aa0cadc9b3ce566 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Tue, 19 Aug 2008 12:05:45 +0000 Subject: [PATCH] added a local broker load test git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@687033 13f79535-47bb-0310-9956-ffa450edef68 --- .../soaktest/localBroker/CounterBean.java | 63 +++++++++++++++++++ .../localBroker/LocalBrokerConsumeTest.java | 40 ++++++++++++ .../LocalBrokerConsumeTest-context.xml | 47 ++++++++++++++ ...BrokerParallelProducerLoadTest-context.xml | 13 +++- 4 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 activemq-camel-loadtest/src/test/java/org/apache/activemq/soaktest/localBroker/CounterBean.java create mode 100644 activemq-camel-loadtest/src/test/java/org/apache/activemq/soaktest/localBroker/LocalBrokerConsumeTest.java create mode 100644 activemq-camel-loadtest/src/test/resources/org/apache/activemq/soaktest/localBroker/LocalBrokerConsumeTest-context.xml diff --git a/activemq-camel-loadtest/src/test/java/org/apache/activemq/soaktest/localBroker/CounterBean.java b/activemq-camel-loadtest/src/test/java/org/apache/activemq/soaktest/localBroker/CounterBean.java new file mode 100644 index 0000000000..5ffc05a9ee --- /dev/null +++ b/activemq-camel-loadtest/src/test/java/org/apache/activemq/soaktest/localBroker/CounterBean.java @@ -0,0 +1,63 @@ +/** + * + * 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.activemq.soaktest.localBroker; + +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.InitializingBean; + +/** + * @version $Revision: 1.1 $ + */ +public class CounterBean implements InitializingBean, Processor { + private static final transient Log LOG = LogFactory.getLog(CounterBean.class); + protected static final long SAMPLES = Integer.parseInt(System.getProperty("SAMPLES", "" + 10000)); + protected static final long SAMPLE_DURATION = Integer.parseInt(System.getProperty("SAMPLES_DURATION", "" + 1000 * 5)); + final AtomicLong counter = new AtomicLong(); + + public void process(Exchange exchange) throws Exception { + counter.incrementAndGet(); + } + + public void afterPropertiesSet() throws Exception { + Thread thread = new Thread() { + @Override + public void run() { + LOG.info("Starting to monitor consumption"); + + for (int i = 0; i < SAMPLES; i++) { + try { + Thread.sleep(SAMPLE_DURATION); + } + catch (InterruptedException e) { + LOG.warn("Caught: " + e, e); + } + + long count = counter.getAndSet(0); + LOG.info(" Total: " + (1000.0 * count / SAMPLE_DURATION) + " messages per second."); + } + } + }; + thread.setDaemon(false); + thread.start(); + } +} diff --git a/activemq-camel-loadtest/src/test/java/org/apache/activemq/soaktest/localBroker/LocalBrokerConsumeTest.java b/activemq-camel-loadtest/src/test/java/org/apache/activemq/soaktest/localBroker/LocalBrokerConsumeTest.java new file mode 100644 index 0000000000..8af7740372 --- /dev/null +++ b/activemq-camel-loadtest/src/test/java/org/apache/activemq/soaktest/localBroker/LocalBrokerConsumeTest.java @@ -0,0 +1,40 @@ +/** + * + * 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.activemq.soaktest.localBroker; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.mock.MockEndpoint; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests; + +/** + * Runs a load test on a separate broker on localhost + * + * @version $Revision: 1.1 $ + */ +@ContextConfiguration +public class LocalBrokerConsumeTest extends AbstractJUnit38SpringContextTests { + @Autowired + protected CamelContext camelContext; + + public void testRun() throws Exception { + Thread.sleep(100000); + //MockEndpoint.assertIsSatisfied(camelContext); + } +} \ No newline at end of file diff --git a/activemq-camel-loadtest/src/test/resources/org/apache/activemq/soaktest/localBroker/LocalBrokerConsumeTest-context.xml b/activemq-camel-loadtest/src/test/resources/org/apache/activemq/soaktest/localBroker/LocalBrokerConsumeTest-context.xml new file mode 100644 index 0000000000..e49fda15ae --- /dev/null +++ b/activemq-camel-loadtest/src/test/resources/org/apache/activemq/soaktest/localBroker/LocalBrokerConsumeTest-context.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/activemq-camel-loadtest/src/test/resources/org/apache/activemq/soaktest/localBroker/LocalBrokerParallelProducerLoadTest-context.xml b/activemq-camel-loadtest/src/test/resources/org/apache/activemq/soaktest/localBroker/LocalBrokerParallelProducerLoadTest-context.xml index 3b9176e50b..ab94fcf8e8 100644 --- a/activemq-camel-loadtest/src/test/resources/org/apache/activemq/soaktest/localBroker/LocalBrokerParallelProducerLoadTest-context.xml +++ b/activemq-camel-loadtest/src/test/resources/org/apache/activemq/soaktest/localBroker/LocalBrokerParallelProducerLoadTest-context.xml @@ -30,16 +30,17 @@ - + - + @@ -51,6 +52,14 @@ + + + + + + +