camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r618625 - in /activemq/camel/trunk/tests/camel-itest: ./ src/test/java/org/apache/camel/itest/jms/ src/test/resources/
Date Tue, 05 Feb 2008 12:28:48 GMT
Author: jstrachan
Date: Tue Feb  5 04:28:47 2008
New Revision: 618625

URL: http://svn.apache.org/viewvc?rev=618625&view=rev
Log:
added a simple performance test case for working with Camel and ActiveMQ

Added:
    activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java
  (with props)
    activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java
      - copied, changed from r613851, activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsIntegrationTest.java
    activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/StopWatch.java
  (with props)
    activemq/camel/trunk/tests/camel-itest/src/test/resources/activemq.xml   (with props)
Modified:
    activemq/camel/trunk/tests/camel-itest/pom.xml

Modified: activemq/camel/trunk/tests/camel-itest/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/pom.xml?rev=618625&r1=618624&r2=618625&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/pom.xml (original)
+++ activemq/camel/trunk/tests/camel-itest/pom.xml Tue Feb  5 04:28:47 2008
@@ -18,7 +18,7 @@
 -->
 
 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
 
   <modelVersion>4.0.0</modelVersion>
 
@@ -39,54 +39,60 @@
       <version>${camel-version}</version>
     </dependency>
 
-<!--
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-core</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-mina</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-http</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-jms</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-jbi</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-cxf</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-script</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-spring</artifactId>
-    </dependency>
--->
-<!--
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-core</artifactId>
-      <type>test-jar</type>
-      <optional>true</optional>
-      <scope>test</scope>
-    </dependency>
--->
+    <!--
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-core</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-mina</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-http</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-jms</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-jbi</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-cxf</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-script</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-spring</artifactId>
+        </dependency>
+    -->
+    <!--
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-core</artifactId>
+          <type>test-jar</type>
+          <optional>true</optional>
+          <scope>test</scope>
+        </dependency>
+    -->
 
     <!-- testing -->
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-all</artifactId>
+      <version>5.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>

Added: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java?rev=618625&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java
(added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java
Tue Feb  5 04:28:47 2008
@@ -0,0 +1,44 @@
+/**
+ *
+ * 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.itest.jms;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class JmsMediumQueuePerformanceTest extends JmsPerformanceTest {
+    protected int mediumQueueCount = 1000;
+
+    @Override
+    public void testSendingAndReceivingMessages() throws Exception {
+        int expected = mediumQueueCount + messageCount;
+        setExpectedMessageCount(messageCount);
+
+        System.out.println("Sending " + mediumQueueCount + " messages first");
+        sendLoop(0, mediumQueueCount);
+        System.out.println("Sent!");
+
+        Thread.sleep(20000);
+
+        // TODO now start the route!
+        
+        System.out.println("Now testing!");
+        timedSendLoop(mediumQueueCount, expected);
+
+        assertExpectedMessagesReceived();
+    }
+}

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java
(from r613851, activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsIntegrationTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java?p2=activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java&p1=activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsIntegrationTest.java&r1=613851&r2=618625&rev=618625&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsIntegrationTest.java
(original)
+++ activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java
Tue Feb  5 04:28:47 2008
@@ -16,41 +16,91 @@
  */
 package org.apache.camel.itest.jms;
 
+import javax.naming.Context;
+
 import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
-import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.jms.JmsComponent;
-
-import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
 import org.apache.camel.util.jndi.JndiContext;
-
-import javax.jms.ConnectionFactory;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.naming.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * @version $Revision:520964 $
  */
-public class JmsIntegrationTest extends ContextTestSupport {
-    protected CountDownLatch receivedCountDown = new CountDownLatch(1);
+public class JmsPerformanceTest extends ContextTestSupport {
+    private static final transient Log LOG = LogFactory.getLog(JmsPerformanceTest.class);
     protected MyBean myBean = new MyBean();
+    protected int messageCount = 1000;
+    protected CountDownLatch receivedCountDown = new CountDownLatch(messageCount);
+    protected long consumerSleep = 0L;
+    protected int expectedMessageCount;
+    protected ClassPathXmlApplicationContext applicationContext;
+    protected boolean useLocalBroker;
+
+    public void testSendingAndReceivingMessages() throws Exception {
+        setExpectedMessageCount(messageCount);
+
+        timedSendLoop(0, messageCount);
+
+        assertExpectedMessagesReceived();
+    }
+
+
+    protected void sendLoop(int startIndex, int endIndex) {
+        for (int i = startIndex; i < endIndex; i++) {
+            sendMessage(i);
+        }
+    }
+
+    protected void timedSendLoop(int startIndex, int endIndex) {
+        StopWatch watch = new StopWatch("Sending");
+        for (int i = startIndex; i < endIndex; i++) {
+            watch.start();
+            sendMessage(i);
+            watch.stop();
+        }
+    }
+
+    protected void sendMessage(int messageCount) {
+        template.sendBodyAndHeader("activemq:" + getQueueName(), "Hello:" + messageCount,
"counter", messageCount);
+    }
 
-    public void testOneWayInJmsOutPojo() throws Exception {
-        // Send a message to the JMS endpoint
-        template.sendBodyAndHeader("jms:test", "Hello", "cheese", 123);
+    public String getQueueName() {
+        return getName();
+    }
+
+    protected void assertExpectedMessagesReceived() throws InterruptedException {
+        assertTrue("The message ware received by the Pojo", receivedCountDown.await(50000,
TimeUnit.SECONDS));
+
+        // TODO assert that messages are received in order
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        if (useLocalBroker) {
+            applicationContext = new ClassPathXmlApplicationContext("activemq.xml");
+            applicationContext.start();
+        }
+
+        super.setUp();
+    }
 
-        // The Activated endpoint should send it to the pojo due to the configured route.
-        assertTrue("The message ware received by the Pojo", receivedCountDown.await(5, TimeUnit.SECONDS));
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (applicationContext != null) {
+            applicationContext.stop();
+        }
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                from("jms:test").to("bean:myBean");
+                from("activemq:" + getQueueName()).to("bean:myBean");
             }
         };
     }
@@ -59,18 +109,29 @@
     protected Context createJndiContext() throws Exception {
         JndiContext answer = new JndiContext();
         answer.bind("myBean", myBean);
-
-        // add ActiveMQ with embedded broker
-        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
-        answer.bind("jms", 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) {
-            log.info("Received: " + body);
+            if (consumerSleep > 0) {
+                try {
+                    Thread.sleep(consumerSleep);
+                }
+                catch (InterruptedException e) {
+                    LOG.warn("Caught: " + e, e);
+                }
+            }
             receivedCountDown.countDown();
         }
     }
-
-}
+}
\ No newline at end of file

Added: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/StopWatch.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/StopWatch.java?rev=618625&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/StopWatch.java
(added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/StopWatch.java
Tue Feb  5 04:28:47 2008
@@ -0,0 +1,110 @@
+/**
+ *
+ * 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.itest.jms;
+
+import java.text.NumberFormat;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class StopWatch {
+    private final String id;
+    private int loopCount;
+    private int totalLoops;
+    private long groupElapsed;
+    private long totalElapsed;
+    private long startTime;
+    private long minTime = Long.MAX_VALUE;
+    private long maxTime = Long.MIN_VALUE;
+    private int logFrequency = 1000;
+    private NumberFormat numberFormat = NumberFormat.getNumberInstance();
+
+    public StopWatch(String id) {
+        this.id = id;
+    }
+
+    public void start() {
+        startTime = System.currentTimeMillis();
+    }
+
+    public void stop() {
+        long elapsedTime = System.currentTimeMillis() - startTime;
+        groupElapsed += elapsedTime;
+        totalElapsed += elapsedTime;
+        loopCount++;
+        totalLoops++;
+
+        if (elapsedTime > maxTime) {
+            maxTime = elapsedTime;
+        }
+        if (elapsedTime < minTime) {
+            minTime = elapsedTime;
+        }
+        if (logFrequency > 0 && loopCount % logFrequency == 0) {
+            System.out.println(toString());
+            reset();
+        }
+    }
+
+    protected void reset() {
+        loopCount = 0;
+        groupElapsed = 0;
+        minTime = Long.MAX_VALUE;
+        maxTime = Long.MIN_VALUE;
+    }
+
+    @Override
+    public String toString() {
+        double average = totalElapsed;
+        average /= totalLoops;
+        average /= 1000;
+        return id + " count: " + loopCount + " elapsed: " + groupElapsed + " min: " + minTime
+ " max: " + maxTime + " average: " + formatSeconds(average);
+    }
+
+    public int getLogFrequency() {
+        return logFrequency;
+    }
+
+    public void setLogFrequency(int logFrequency) {
+        this.logFrequency = logFrequency;
+    }
+
+    public int getLoopCount() {
+        return loopCount;
+    }
+
+    public long getMaxTime() {
+        return maxTime;
+    }
+
+    public long getMinTime() {
+        return minTime;
+    }
+
+    public long getStartTime() {
+        return startTime;
+    }
+
+    public long getGroupElapsed() {
+        return groupElapsed;
+    }
+
+    protected String formatSeconds(double time) {
+        return numberFormat.format(time);
+    }
+}

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/StopWatch.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/tests/camel-itest/src/test/resources/activemq.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/resources/activemq.xml?rev=618625&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/resources/activemq.xml (added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/resources/activemq.xml Tue Feb  5 04:28:47
2008
@@ -0,0 +1,37 @@
+<!--
+    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:amq="http://activemq.org/config/1.0"
+  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-2.0.xsd
+  http://activemq.org/config/1.0 http://activemq.apache.org/schema/activemq-core.xsd">
+
+  <broker xmlns="http://activemq.org/config/1.0" dataDirectory="target/activemq">
+
+<!--
+    <transportConnectors>
+       <transportConnector name="openwire" uri="tcp://localhost:61616"/>
+    </transportConnectors>
+-->
+
+  </broker>
+
+
+</beans>
+<!-- END SNIPPET: example -->

Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/activemq.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message