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 2007/07/03 10:24:28 UTC

svn commit: r552734 - in /activemq/trunk/activemq-core/src/test/java/org/apache/activemq: kaha/impl/index/tree/ kaha/impl/index/tree/TreeTest.java network/DuplexNetworkTest.java

Author: rajdavies
Date: Tue Jul  3 01:24:26 2007
New Revision: 552734

URL: http://svn.apache.org/viewvc?view=rev&rev=552734
Log:
Tests for internals

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java   (with props)
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java   (with props)

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java?view=auto&rev=552734
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java Tue Jul  3 01:24:26 2007
@@ -0,0 +1,133 @@
+/**
+ * 
+ * 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.kaha.impl.index.tree;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.activemq.kaha.Store;
+import org.apache.activemq.kaha.StoreEntry;
+import org.apache.activemq.kaha.impl.index.IndexItem;
+import org.apache.activemq.kaha.impl.index.IndexManager;
+import junit.framework.TestCase;
+
+/**
+ * Test a TreeIndex
+ * 
+ */
+public class TreeTest extends TestCase{
+
+    private static int COUNT=55;
+    private TreeIndex tree;
+    private File directory;
+    private IndexManager indexManager;
+    private boolean dumpTree=false;
+
+    /**
+     * @throws java.lang.Exception
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception{
+        super.setUp();
+        directory=new File("activemq-data");
+        directory.mkdirs();
+        indexManager=new IndexManager(directory,"im-test","rw",null);
+        this.tree=new TreeIndex(directory,"testTree",indexManager);
+        this.tree.setKeyMarshaller(Store.StringMarshaller);
+    }
+
+    public void testTreeWithCaching() throws Exception{
+        this.tree.setEnablePageCaching(true);
+        //doTest();
+    }
+
+    public void testTreeWithoutCaching() throws Exception{
+        this.tree.setEnablePageCaching(false);
+        //doTest();
+    }
+
+    public void doTest() throws Exception{
+        // doTest(300);
+        // tree.clear();
+        // tree.unload();
+        doTest(600);// count = 55 - this fails
+        // tree.clear();
+        // tree.unload();
+         //doTest(1024*16);
+    }
+
+    public void doTest(int pageSize) throws Exception{
+        String keyRoot="key:";
+        tree.setPageSize(pageSize);
+        this.tree.load();
+       // doInsert(keyRoot);
+       // checkRetrieve(keyRoot);
+       // doRemove(keyRoot);
+        doInsert(keyRoot);
+        doRemoveBackwards(keyRoot);
+    }
+
+    void doInsert(String keyRoot) throws Exception{
+        for(int i=0;i<COUNT;i++){
+            IndexItem value=indexManager.createNewIndex();
+            indexManager.storeIndex(value);
+            tree.store(keyRoot+i,value);
+        }
+    }
+
+    void checkRetrieve(String keyRoot) throws IOException{
+        for(int i=0;i<COUNT;i++){
+            IndexItem item=(IndexItem)tree.get(keyRoot+i);
+            assertNotNull(item);
+        }
+    }
+
+    void doRemove(String keyRoot) throws Exception{
+        for(int i=0;i<COUNT;i++){
+            tree.remove(keyRoot+i);
+            //System.out.println("Removed " + keyRoot+i);
+           // tree.getRoot().dump();
+            //System.out.println("");
+        }
+        for(int i=0;i<COUNT;i++){
+            IndexItem item=(IndexItem)tree.get(keyRoot+i);
+            assertNull(item);
+        }
+    }
+
+    void doRemoveBackwards(String keyRoot) throws Exception{
+        for(int i=COUNT-1;i>=0;i--){
+            tree.remove(keyRoot+i);
+            System.out.println("BACK Removed " + keyRoot+i);
+           tree.getRoot().dump();
+          System.out.println("");
+        }
+        for(int i=0;i<COUNT;i++){
+            IndexItem item=(IndexItem)tree.get(keyRoot+i);
+            assertNull(item);
+        }
+    }
+
+    /**
+     * @throws java.lang.Exception
+     * @see junit.framework.TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception{
+        super.tearDown();
+        File[] files=directory.listFiles();
+        for(File file:files){
+            file.delete();
+        }
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java?view=auto&rev=552734
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java Tue Jul  3 01:24:26 2007
@@ -0,0 +1,35 @@
+/**
+ * 
+ * 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.network;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class DuplexNetworkTest extends SimpleNetworkTest{
+
+    protected static final Log log=LogFactory.getLog(DuplexNetworkTest.class);
+/*
+    protected String getLocalBrokerURI(){
+        return "org/apache/activemq/network/duplexLocalBroker.xml";
+    }
+    */
+
+    protected BrokerService createRemoteBroker() throws Exception{
+        BrokerService broker=new BrokerService();
+        broker.addConnector("tcp://localhost:61617");
+        return broker;
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java
------------------------------------------------------------------------------
    svn:executable = *