You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ra...@apache.org on 2006/04/20 16:15:38 UTC

svn commit: r395597 [3/3] - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/kaha/ main/java/org/apache/activemq/kaha/impl/ main/java/org/apache/activemq/store/kahadaptor/ test/java/org/apache/activemq/kaha/ test/java/org/a...

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/IndexLinkedListTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/IndexLinkedListTest.java?rev=395597&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/IndexLinkedListTest.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/IndexLinkedListTest.java Thu Apr 20 07:15:30 2006
@@ -0,0 +1,261 @@
+/**
+ *
+ * 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.kaha.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.TestCase;
+
+/** 
+* @version $Revision: 1.2 $
+*/
+public class IndexLinkedListTest extends TestCase{
+    static final int NUMBER = 10;
+    private IndexItem root;
+    private List testData = new ArrayList();
+    private IndexLinkedList list;
+    protected void setUp() throws Exception{
+        super.setUp();
+        for (int i =0; i < NUMBER; i++){
+            testData.add(new IndexItem());
+        }
+        root = new IndexItem();
+        list = new IndexLinkedList(root);
+    }
+
+    protected void tearDown() throws Exception{
+        super.tearDown();
+        testData.clear();
+        list = null;
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.getFirst()'
+     */
+    public void testGetFirst(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        assertTrue(list.getFirst()==testData.get(0));
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.getLast()'
+     */
+    public void testGetLast(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        assertTrue(list.getLast()==testData.get(testData.size()-1));
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.removeFirst()'
+     */
+    public void testRemoveFirst(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        assertTrue(list.removeFirst()==testData.get(0));
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.removeLast()'
+     */
+    public void testRemoveLast(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        assertTrue(list.removeLast()==testData.get(testData.size()-1));
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.addFirst(IndexItem)'
+     */
+    public void testAddFirst(){
+        for (int i =0; i < testData.size(); i++){
+            list.addFirst((IndexItem) testData.get(i));
+        }
+        int count = 0;
+        for (int i =testData.size()-1; i>=0; i--){
+            assertTrue(testData.get(i)==list.get(count++));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.addLast(IndexItem)'
+     */
+    public void testAddLast(){
+        for (int i =0; i < testData.size(); i++){
+            list.addLast((IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            assertTrue(testData.get(i)==list.get(i));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.size()'
+     */
+    public void testSize(){
+        for (int i =0; i < testData.size(); i++){
+            list.addLast((IndexItem) testData.get(i));
+            assertTrue(list.size()==i+1);
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.isEmpty()'
+     */
+    public void testIsEmpty(){
+        for (int i =0; i < testData.size(); i++){
+            list.addLast((IndexItem) testData.get(i));
+            assertTrue(list.size()==i+1);
+        }
+        list.clear();
+        assertTrue(list.isEmpty());
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.add(IndexItem)'
+     */
+    public void testAddIndexItem(){
+        for (int i =0; i < testData.size(); i++){
+            list.add((IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            assertTrue(testData.get(i)==list.get(i));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.clear()'
+     */
+    public void testClear(){
+        for (int i =0; i < testData.size(); i++){
+            list.addLast((IndexItem) testData.get(i));
+            assertTrue(list.size()==i+1);
+        }
+        list.clear();
+        assertTrue(list.isEmpty());
+    }
+
+    
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.add(int, IndexItem)'
+     */
+    public void testAddIntIndexItem(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            assertTrue(testData.get(i)==list.get(i));
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.remove(int)'
+     */
+    public void testRemoveInt(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            list.remove(0);
+        }
+        assertTrue(list.isEmpty());
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            list.remove(list.size()-1);
+        }
+        assertTrue(list.isEmpty());
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.indexOf(IndexItem)'
+     */
+    public void testIndexOf(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            assertTrue(list.indexOf((IndexItem) testData.get(i))==i);
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.getNextEntry(IndexItem)'
+     */
+    public void testGetNextEntry(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        IndexItem next = list.getFirst();
+        int count = 0;
+        while (next != null){
+            assertTrue(next==testData.get(count++));
+            next = list.getNextEntry(next);
+            assertTrue(next != root);
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.getPrevEntry(IndexItem)'
+     */
+    public void testGetPrevEntry(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        IndexItem next = list.getLast();
+        int count = testData.size()-1;
+        while (next != null){
+            assertTrue(next==testData.get(count--));
+            next = list.getPrevEntry(next);
+            assertTrue(next != root);
+        }
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.addBefore(IndexItem, IndexItem)'
+     */
+    public void testAddBefore(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        IndexItem test = new IndexItem();
+        list.addBefore(test, list.getFirst());
+        assertTrue(list.size()==testData.size()+1);
+        assertTrue(list.getFirst()==test);
+    }
+
+    /*
+     * Test method for 'org.apache.activemq.kaha.impl.IndexLinkedList.remove(IndexItem)'
+     */
+    public void testRemoveIndexItem(){
+        for (int i =0; i < testData.size(); i++){
+            list.add(i,(IndexItem) testData.get(i));
+        }
+        for (int i =0; i < testData.size(); i++){
+            list.remove((IndexItem)testData.get(i));
+            assertTrue(list.size()==testData.size()-i-1);
+        }
+    }
+}

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/KahaDurableTopicTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/KahaDurableTopicTest.java?rev=395597&r1=395596&r2=395597&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/KahaDurableTopicTest.java (original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/KahaDurableTopicTest.java Thu Apr 20 07:15:30 2006
@@ -16,21 +16,15 @@
  */
 package org.apache.activemq.perf;
 
-import javax.jms.ConnectionFactory;
-import javax.jms.DeliveryMode;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-
-import org.apache.activemq.ActiveMQConnectionFactory;
+import java.io.File;
 import org.apache.activemq.broker.BrokerService;
-import org.apache.activemq.xbean.BrokerFactoryBean;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
+import org.apache.activemq.store.kahadaptor.KahaPersistentAdaptor;
 /**
  * @version $Revision: 1.3 $
  */
 public class KahaDurableTopicTest extends SimpleDurableTopicTest {
     
+    /*
     protected BrokerService createBroker() throws Exception{
         Resource resource=new ClassPathResource( "org/apache/activemq/perf/kahaBroker.xml");
         BrokerFactoryBean factory=new BrokerFactoryBean(resource);
@@ -38,6 +32,14 @@
         BrokerService result=factory.getBroker();
         result.start();
         return result;
+    }
+    */
+    
+    protected void configureBroker(BrokerService answer) throws Exception{
+        KahaPersistentAdaptor adaptor = new KahaPersistentAdaptor(new File("activemq-data/perfTest"));
+        answer.setPersistenceAdapter(adaptor);
+        answer.addConnector(bindAddress);
+        answer.setDeleteAllMessagesOnStartup(true);
     }
 
     

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/KahaQueueTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/KahaQueueTest.java?rev=395597&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/KahaQueueTest.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/KahaQueueTest.java Thu Apr 20 07:15:30 2006
@@ -0,0 +1,38 @@
+/**
+ *
+ * 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.perf;
+
+import java.io.File;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.store.kahadaptor.KahaPersistentAdaptor;
+/**
+ * @version $Revision: 1.3 $
+ */
+public class KahaQueueTest extends SimpleQueueTest{
+    
+        
+    protected void configureBroker(BrokerService answer) throws Exception{
+        KahaPersistentAdaptor adaptor = new KahaPersistentAdaptor(new File("activemq-data/perfTest"));
+        answer.setPersistenceAdapter(adaptor);
+        answer.addConnector(bindAddress);
+        answer.setDeleteAllMessagesOnStartup(true);
+    }
+
+}
\ No newline at end of file

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/MemoryAllocationTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/MemoryAllocationTest.java?rev=395597&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/MemoryAllocationTest.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/MemoryAllocationTest.java Thu Apr 20 07:15:30 2006
@@ -0,0 +1,103 @@
+/**
+ * 
+ * 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.perf;
+
+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.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import junit.framework.TestCase;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+/**
+ * @version $Revision: 1.3 $
+ */
+public class MemoryAllocationTest extends TestCase{
+    protected static final int MESSAGE_COUNT=2000;
+    protected BrokerService broker;
+    protected String bindAddress="vm://localhost";
+    protected int topicCount=0;
+
+    public void testPerformance() throws Exception{
+        ConnectionFactory factory=createConnectionFactory();
+        Connection connection=factory.createConnection();
+        for(int i=0;i<MESSAGE_COUNT;i++){
+           
+            Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
+            Destination dest=session.createTemporaryTopic();
+            MessageConsumer mc=session.createConsumer(dest);
+            MessageProducer mp=session.createProducer(dest);
+            Message msg=session.createTextMessage("test"+i);
+            mp.send(msg);
+            session.close();
+           releaseDestination(dest);
+            if (i%500==0)System.out.println("Iterator "+i);
+        }
+        connection.close();
+    }
+
+    protected Destination getDestination(Session session) throws JMSException{
+        String topicName=getClass().getName()+"."+topicCount++;
+        return session.createTopic(topicName);
+    }
+
+    protected void releaseDestination(Destination dest) throws JMSException{
+        if(dest instanceof TemporaryTopic){
+            TemporaryTopic tt=(TemporaryTopic) dest;
+            tt.delete();
+        }else if(dest instanceof TemporaryQueue){
+            TemporaryQueue tq=(TemporaryQueue) dest;
+            tq.delete();
+        }
+    }
+
+    protected void setUp() throws Exception{
+        if(broker==null){
+            broker=createBroker();
+        }
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception{
+        super.tearDown();
+        
+        if(broker!=null){
+          broker.stop();
+        }
+    }
+
+    protected ActiveMQConnectionFactory createConnectionFactory() throws Exception{
+        ActiveMQConnectionFactory cf=new ActiveMQConnectionFactory(bindAddress);
+        return cf;
+    }
+
+    protected BrokerService createBroker() throws Exception{
+        BrokerService answer=new BrokerService();
+        configureBroker(answer);
+        answer.start();
+        return answer;
+    }
+
+    protected void configureBroker(BrokerService answer) throws Exception{
+        answer.setPersistent(false);
+        answer.addConnector(bindAddress);
+        answer.setDeleteAllMessagesOnStartup(true);
+    }
+}

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java?rev=395597&r1=395596&r2=395597&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java (original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java Thu Apr 20 07:15:30 2006
@@ -34,7 +34,10 @@
 public class SimpleTopicTest extends TestCase{
     private static final Log log=LogFactory.getLog(SimpleTopicTest.class);
     protected BrokerService broker;
-    protected String bindAddress="tcp://localhost:61616";
+    protected String bindAddress="tcp://localhost:61616?wireFormat.cacheEnabled=true&wireFormat.tightEncodingEnabled=true";
+    //protected String bindAddress="tcp://localhost:61616?wireFormat.cacheEnabled=true&wireFormat.tightEncodingEnabled=false";
+    //protected String bindAddress="vm://localhost?marshal=true";
+    //protected String bindAddress="vm://localhost";
     protected PerfProducer[] producers;
     protected PerfConsumer[] consumers;
     protected String DESTINATION_NAME=getClass().toString();
@@ -42,7 +45,7 @@
     protected int NUMBER_OF_PRODUCERS=1;
     protected BytesMessage payload;
     protected int PAYLOAD_SIZE=1024;
-    protected int MESSAGE_COUNT=1000000;
+    protected int MESSAGE_COUNT=100000;
     protected byte[] array=null;
     protected ConnectionFactory factory;
     protected Destination destination;
@@ -121,6 +124,7 @@
     protected void configureBroker(BrokerService answer) throws Exception{
         answer.addConnector(bindAddress);
         answer.setDeleteAllMessagesOnStartup(true);
+        
     }
 
     protected ActiveMQConnectionFactory createConnectionFactory() throws Exception{
@@ -133,7 +137,7 @@
 
     public void testPerformance() throws JMSException{
         for(int i=0;i<MESSAGE_COUNT;i++){
-            if(i%5000==0){
+            if(i%10000==0){
                 dumpProducerRate();
                 dumpConsumerRate();
             }

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/TemporaryTopicMemoryAllocationTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/TemporaryTopicMemoryAllocationTest.java?rev=395597&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/TemporaryTopicMemoryAllocationTest.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/TemporaryTopicMemoryAllocationTest.java Thu Apr 20 07:15:30 2006
@@ -0,0 +1,31 @@
+/**
+ * 
+ * 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.perf;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+/**
+ * @version $Revision: 1.3 $
+ */
+public class TemporaryTopicMemoryAllocationTest extends MemoryAllocationTest{
+    public TemporaryTopicMemoryAllocationTest(){
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+    protected Destination getDestination(Session session) throws JMSException{
+        return session.createTemporaryTopic();
+    }
+}