You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jl...@apache.org on 2006/03/09 12:11:13 UTC

svn commit: r384490 - in /incubator/activemq/trunk/activemq-soaktest: ./ src/ src/main/ src/main/resources/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/activemq/ src/test/java/org/apache/activemq/soakt...

Author: jlim
Date: Thu Mar  9 03:11:09 2006
New Revision: 384490

URL: http://svn.apache.org/viewcvs?rev=384490&view=rev
Log:
soak test module . module will not be included on the default build and will be ran now and again to test messages consumed and msg order  are correct on large for large amt of msg

Added:
    incubator/activemq/trunk/activemq-soaktest/
    incubator/activemq/trunk/activemq-soaktest/maven.xml
    incubator/activemq/trunk/activemq-soaktest/project.properties
    incubator/activemq/trunk/activemq-soaktest/project.xml
    incubator/activemq/trunk/activemq-soaktest/src/
    incubator/activemq/trunk/activemq-soaktest/src/main/
    incubator/activemq/trunk/activemq-soaktest/src/main/resources/
    incubator/activemq/trunk/activemq-soaktest/src/test/
    incubator/activemq/trunk/activemq-soaktest/src/test/java/
    incubator/activemq/trunk/activemq-soaktest/src/test/java/org/
    incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/
    incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/
    incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/
    incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/PublishThenConsumeSoakTest.java
    incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/SoakTestSupport.java
    incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/
    incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Consumer.java
    incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Producer.java

Added: incubator/activemq/trunk/activemq-soaktest/maven.xml
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-soaktest/maven.xml?rev=384490&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-soaktest/maven.xml (added)
+++ incubator/activemq/trunk/activemq-soaktest/maven.xml Thu Mar  9 03:11:09 2006
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Copyright 2005-2006 The Apache Software Foundation
+   
+    Licensed 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.
+-->
+<project default="default"
+    xmlns:j="jelly:core"
+    xmlns:u="jelly:util"
+    xmlns:ant="jelly:ant"
+    xmlns:util="jelly:util"
+    xmlns:artifact="artifact"
+    >
+
+
+  <goal name="default" prereqs="jar:install"/>
+
+  <postGoal name="clean">
+    <delete dir="${basedir}/activemq-data" />
+  </postGoal>
+</project>

Added: incubator/activemq/trunk/activemq-soaktest/project.properties
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-soaktest/project.properties?rev=384490&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-soaktest/project.properties (added)
+++ incubator/activemq/trunk/activemq-soaktest/project.properties Thu Mar  9 03:11:09 2006
@@ -0,0 +1,4 @@
+# -------------------------------------------------------------------
+# Build Properties
+# -------------------------------------------------------------------
+

Added: incubator/activemq/trunk/activemq-soaktest/project.xml
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-soaktest/project.xml?rev=384490&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-soaktest/project.xml (added)
+++ incubator/activemq/trunk/activemq-soaktest/project.xml Thu Mar  9 03:11:09 2006
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project>
+<!--
+    Copyright 2005-2006 The Apache Software Foundation
+   
+    Licensed 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.
+-->
+<project>
+  <pomVersion>3</pomVersion>
+  <extend>${basedir}/../etc/project.xml</extend>
+  <name>ActiveMQ :: SoakTest</name>
+  <id>activemq</id>
+  <shortDescription>ActiveMQ Assembly</shortDescription>
+  <description>ActiveMQ Assembly creates an ActiveMQ distribution</description>
+
+  <!-- ============ -->
+  <!-- Dependencies -->
+  <!-- ============ -->
+  <dependencies>
+
+      <dependency>
+        <groupId>${pom.groupId}</groupId>
+        <artifactId>activemq-core</artifactId>
+        <version>${pom.currentVersion}</version>
+        <properties>
+          <activemq.module>true</activemq.module>
+          <lib>true</lib>
+        </properties>
+      </dependency>
+
+
+      <dependency>
+        <groupId>activeio</groupId>
+        <artifactId>activeio</artifactId>
+        <version>${activeio_version}</version>
+        <properties>
+          <activemq.module>true</activemq.module>
+          <lib>true</lib>
+        </properties>
+      </dependency>
+
+
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>activemq-core-test</artifactId>
+      <version>${pom.currentVersion}</version>
+    </dependency>
+    
+
+
+    <!-- Derby DB used for testing JDBC message store -->
+    <dependency>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derby</artifactId>
+      <version>${derby_version}</version>
+      <properties>
+        <activemq.module>true</activemq.module>
+        <optional>true</optional>
+      </properties>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derbynet</artifactId>
+      <version>${derbynet_version}</version>
+    </dependency>
+
+
+
+  </dependencies>
+
+  <build>
+    <nagEmailAddress>dev@activemq.codehaus.org</nagEmailAddress>
+    <sourceDirectory>src/main/java</sourceDirectory>
+    <unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>
+
+    <integrationUnitTestSourceDirectory/>
+    <aspectSourceDirectory/>
+
+    <unitTest>
+      <resources>
+        <resource>
+          <directory>src/test/resources</directory>
+          <includes>
+            <include>**/*.properties</include>
+            <include>**/*.xml</include>
+          </includes>
+        </resource>
+      </resources>
+      <includes>
+        <include>**/*Test.*</include>
+      </includes>
+      <excludes>
+
+
+      </excludes>
+    </unitTest>
+
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <includes>
+          <include>**/*</include>
+        </includes>
+      </resource>
+    </resources>
+  </build>
+
+</project>
+

Added: incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/PublishThenConsumeSoakTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/PublishThenConsumeSoakTest.java?rev=384490&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/PublishThenConsumeSoakTest.java (added)
+++ incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/PublishThenConsumeSoakTest.java Thu Mar  9 03:11:09 2006
@@ -0,0 +1,47 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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;
+
+
+public class PublishThenConsumeSoakTest extends SoakTestSupport{
+
+
+    public void testPublishThenReceive() throws Exception {
+          messageCount = 5000000;
+
+          createProducers();
+          int counter = 0;
+          for (int i = 0; i < messageCount; i++) {
+
+                for (int k = 0; k < producers.length; k++) {
+                    producers[k].sendMessage(payload,"counter",counter);
+                    counter++;
+                }
+          }
+
+          allMessagesList.setAsParent(true);
+
+          createConsumers();
+          allMessagesList.waitForMessagesToArrive(messageCount*producers.length);
+          allMessagesList.assertMessagesReceived(messageCount*producers.length);
+          allMessagesList.assertMessagesReceivedAreInOrder(messageCount*producers.length);
+
+    }
+
+
+}

Added: incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/SoakTestSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/SoakTestSupport.java?rev=384490&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/SoakTestSupport.java (added)
+++ incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/soaktest/SoakTestSupport.java Thu Mar  9 03:11:09 2006
@@ -0,0 +1,183 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.tool.Producer;
+import org.apache.activemq.tool.Consumer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jms.*;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+
+
+public class SoakTestSupport  extends TestCase{
+
+    private static final Log log = LogFactory.getLog(SoakTestSupport.class);
+    protected BrokerService broker;
+    protected String brokerURL = "tcp://localhost:61616";
+    protected int consumerCount = 1;
+    protected int producerCount = 1;
+    protected int messageSize = 1024;
+    protected int messageCount = 1000;
+
+    protected Producer[] producers;
+    protected Consumer[] consumers;
+    protected String destinationName = "TOOL.DEFAULT";
+    protected Message payload;
+
+    protected ConnectionFactory connectionFactory;
+    protected Destination destination;
+    protected boolean createConnectionPerClient = true;
+    protected boolean topic = false;
+    protected boolean transacted = false;
+    protected boolean durable = true;
+    protected boolean useEmbeddedBroker = true;
+    protected boolean keepOnRunning = true;
+    protected int duration = 0;   //duration in minutes
+    protected boolean useConsumerListener = true;
+    protected Consumer allMessagesList = new Consumer();
+    private String dataFileRoot =  "activemq-data";
+
+
+    protected void setUp() throws Exception {
+        //clean up db store
+        File dataFile = new File(dataFileRoot);
+        recursiveDelete(dataFile);
+
+        if (useEmbeddedBroker) {
+            if (broker == null) {
+                broker = createBroker();
+            }
+        }
+
+        connectionFactory = createConnectionFactory();
+        Connection con = connectionFactory.createConnection();
+        Session session = con.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
+
+        if (topic) {
+            destination = session.createTopic(destinationName);
+        } else {
+            destination = session.createQueue(destinationName);
+        }
+
+        createPayload(session);
+
+        con.close();
+
+    }
+
+
+    protected void createPayload(Session session) throws JMSException {
+
+        byte[] array = new byte[messageSize];
+        for (int i = 0; i < array.length; i++) {
+            array[i] = (byte) i;
+        }
+
+        BytesMessage bystePayload = session.createBytesMessage();
+        bystePayload.writeBytes(array);
+        payload = (Message) bystePayload;
+    }
+
+
+    protected void createProducers() throws JMSException {
+        producers = new Producer[producerCount];
+        for (int i = 0; i < producerCount; i++) {
+            producers[i] = new Producer(connectionFactory, destination);
+            if (durable) {
+                producers[i].setDeliveryMode(DeliveryMode.PERSISTENT);
+            }
+             else {
+                producers[i].setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+            }
+            producers[i].start();
+        }
+
+    }
+
+    protected void createConsumers() throws JMSException {
+        consumers = new Consumer[consumerCount];
+        for (int i = 0; i < consumerCount; i++) {
+            consumers[i] = new Consumer(connectionFactory, destination);
+            consumers[i].setParent(allMessagesList);
+            if(useConsumerListener){
+               consumers[i].start();
+            }
+
+
+        }
+    }
+
+    protected ActiveMQConnectionFactory createConnectionFactory() throws JMSException {
+
+        if (useEmbeddedBroker) {
+            return new ActiveMQConnectionFactory("vm://localhost");
+        } else {
+            return new ActiveMQConnectionFactory(brokerURL);
+        }
+    }
+
+    protected BrokerService createBroker() throws Exception {
+        BrokerService broker = new BrokerService();
+        configureBroker(broker);
+        broker.start();
+        return broker;
+    }
+
+    protected void configureBroker(BrokerService broker) throws Exception {
+        broker.addConnector("vm://localhost");
+        broker.setDeleteAllMessagesOnStartup(true);
+    }
+
+    public void startTimer() {
+
+        Thread timer = new Thread(new Runnable() {
+            public void run() {
+                try {
+
+                    Thread.sleep(duration * 60 * 1000);
+                    keepOnRunning = true;
+                } catch (InterruptedException e) {
+
+                } finally {
+
+                }
+            }
+        }, "TimerThread");
+
+
+        log.info("Starting timer thread... Duration :" +duration + " minutes");
+        timer.start();
+    }
+
+    protected  void recursiveDelete(File file) {
+        if( file.isDirectory() ) {
+            File[] files = file.listFiles();
+            for (int i = 0; i < files.length; i++) {
+                recursiveDelete(files[i]);
+            }
+        }
+        file.delete();
+    }
+}

Added: incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Consumer.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Consumer.java?rev=384490&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Consumer.java (added)
+++ incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Consumer.java Thu Mar  9 03:11:09 2006
@@ -0,0 +1,116 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.tool;
+
+import org.apache.activemq.util.MessageIdList;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+import javax.jms.Topic;
+/**
+ * @version $Revision: 1.3 $
+ */
+public class Consumer extends MessageIdList implements MessageListener{
+    protected Connection connection;
+    protected MessageConsumer consumer;
+    protected long counter = 0;
+    protected boolean isParent = false;
+    protected boolean inOrder = true;
+
+
+    public Consumer() {
+        super();
+    }
+    public Consumer(ConnectionFactory fac,Destination dest,String consumerName) throws JMSException{
+        connection=fac.createConnection();
+        Session s=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
+        if(dest instanceof Topic&&consumerName!=null&&consumerName.length()>0){
+            consumer=s.createDurableSubscriber((Topic) dest,consumerName);
+        }else{
+            consumer=s.createConsumer(dest);
+        }
+        consumer.setMessageListener(this);
+    }
+    public Consumer(ConnectionFactory fac,Destination dest) throws JMSException{
+        this(fac,dest,null);
+    }
+    public void start() throws JMSException{
+        connection.start();
+    }
+    public void stop() throws JMSException{
+        connection.stop();
+    }
+    public void shutDown() throws JMSException{
+        connection.close();
+    }
+
+
+    public Message receive() throws JMSException{
+        return consumer.receive(); 
+    }
+
+    public Message receive(long wait) throws JMSException{
+        return consumer.receive(wait);
+    }
+
+    public void onMessage(Message msg){
+        super.onMessage(msg);
+        if(isParent) {
+           try {
+              long ctr = msg.getLongProperty("counter");
+              if (counter != ctr){
+                   inOrder = false;
+              }
+              counter ++;
+           }catch(Exception e) {
+               e.printStackTrace();
+           }
+        }
+    }
+
+
+    public boolean isInOrder() {
+        return inOrder;
+    }
+
+
+    public void setAsParent(boolean isParent) {
+        this.isParent = isParent;
+    }
+
+    public boolean isParent() {
+        return this.isParent;
+    }
+
+
+    /**
+     * Performs a testing assertion that the correct order  of messages have
+     * been received
+     *
+     * @param messageCount
+     */
+    public void assertMessagesReceivedAreInOrder(int messageCount) {
+        assertEquals("expected number of messages when received", messageCount, getMessageCount());
+    }
+
+}
\ No newline at end of file

Added: incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Producer.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Producer.java?rev=384490&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Producer.java (added)
+++ incubator/activemq/trunk/activemq-soaktest/src/test/java/org/apache/activemq/tool/Producer.java Thu Mar  9 03:11:09 2006
@@ -0,0 +1,68 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.tool;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+/**
+ * @version $Revision: 1.3 $
+ */
+public class Producer{
+    protected Connection connection;
+    protected MessageProducer producer;
+    public Producer(ConnectionFactory fac,Destination dest) throws JMSException{
+        connection=fac.createConnection();
+        Session s=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
+        producer=s.createProducer(dest);
+    }
+    public void setDeliveryMode(int mode) throws JMSException{
+        producer.setDeliveryMode(mode);
+    }
+    public void start() throws JMSException{
+        connection.start();
+    }
+    public void stop() throws JMSException{
+        connection.stop();
+    }
+    public void shutDown() throws JMSException{
+        connection.close();
+    }
+
+    public void sendMessage(Message msg) throws JMSException {
+        sendMessage(msg, null,0);
+    }
+
+    /*
+    *   allow producer to attach message counter on its header. This will be used to verify message order
+    *
+    */
+    public void sendMessage(Message msg, String headerName, long headerValue) throws JMSException{
+        if(headerName != null) {
+            msg.setLongProperty(headerName, headerValue);
+        }
+
+        producer.send(msg);
+
+    }
+
+}
\ No newline at end of file