activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1415870 - in /activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index: BTreeIndexTest.java IndexTestSupport.java ListIndexTest.java
Date Fri, 30 Nov 2012 22:02:52 GMT
Author: tabish
Date: Fri Nov 30 22:02:51 2012
New Revision: 1415870

URL: http://svn.apache.org/viewvc?rev=1415870&view=rev
Log:
apply patch for: https://issues.apache.org/jira/browse/AMQ-4158

Modified:
    activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/BTreeIndexTest.java
    activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/IndexTestSupport.java
    activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/ListIndexTest.java

Modified: activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/BTreeIndexTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/BTreeIndexTest.java?rev=1415870&r1=1415869&r2=1415870&view=diff
==============================================================================
--- activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/BTreeIndexTest.java
(original)
+++ activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/BTreeIndexTest.java
Fri Nov 30 22:02:51 2012
@@ -37,6 +37,7 @@ import org.apache.activemq.store.kahadb.
 import org.apache.activemq.store.kahadb.disk.util.LongMarshaller;
 import org.apache.activemq.store.kahadb.disk.util.StringMarshaller;
 import org.apache.activemq.store.kahadb.disk.util.VariableMarshaller;
+import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,24 +52,24 @@ public class BTreeIndexTest extends Inde
         nf.setMinimumIntegerDigits(6);
         nf.setGroupingUsed(false);
     }
-    
+
     @Override
     protected Index<String, Long> createIndex() throws Exception {
-        
+
         long id = tx.allocate().getPageId();
         tx.commit();
 
         BTreeIndex<String, Long> index = new BTreeIndex<String,Long>(pf, id);
         index.setKeyMarshaller(StringMarshaller.INSTANCE);
         index.setValueMarshaller(LongMarshaller.INSTANCE);
-        
+
         return index;
     }
 
     /**
-     * Yeah, the current implementation does NOT try to balance the tree.  Here is 
-     * a test case showing that it gets out of balance.  
-     * 
+     * Yeah, the current implementation does NOT try to balance the tree.  Here is
+     * a test case showing that it gets out of balance.
+     *
      * @throws Exception
      */
     public void disabled_testTreeBalancing() throws Exception {
@@ -77,9 +78,9 @@ public class BTreeIndexTest extends Inde
         BTreeIndex index = ((BTreeIndex)this.index);
         this.index.load(tx);
         tx.commit();
-        
+
         doInsert(50);
-        
+
         int minLeafDepth = index.getMinLeafDepth(tx);
         int maxLeafDepth = index.getMaxLeafDepth(tx);
         assertTrue("Tree is balanced", maxLeafDepth-minLeafDepth <= 1);
@@ -97,7 +98,8 @@ public class BTreeIndexTest extends Inde
 
         this.index.unload(tx);
     }
-    
+
+    @Test(timeout=60000)
     public void testPruning() throws Exception {
         createPageFileAndIndex(100);
 
@@ -105,14 +107,14 @@ public class BTreeIndexTest extends Inde
 
         this.index.load(tx);
         tx.commit();
-     
+
         int minLeafDepth = index.getMinLeafDepth(tx);
         int maxLeafDepth = index.getMaxLeafDepth(tx);
         assertEquals(1, minLeafDepth);
         assertEquals(1, maxLeafDepth);
-        
+
         doInsert(1000);
-        
+
         minLeafDepth = index.getMinLeafDepth(tx);
         maxLeafDepth = index.getMaxLeafDepth(tx);
         assertTrue("Depth of tree grew", minLeafDepth > 1);
@@ -130,15 +132,16 @@ public class BTreeIndexTest extends Inde
         tx.commit();
     }
 
+    @Test(timeout=60000)
     public void testIteration() throws Exception {
         createPageFileAndIndex(500);
         BTreeIndex<String,Long> index = ((BTreeIndex<String,Long>)this.index);
         this.index.load(tx);
         tx.commit();
-          
+
         // Insert in reverse order..
         doInsertReverse(1000);
-        
+
         this.index.unload(tx);
         tx.commit();
         this.index.load(tx);
@@ -149,7 +152,7 @@ public class BTreeIndexTest extends Inde
         // BTree should iterate it in sorted order.
         int counter=0;
         for (Iterator<Map.Entry<String,Long>> i = index.iterator(tx); i.hasNext();)
{
-            Map.Entry<String,Long> entry = (Map.Entry<String,Long>)i.next();
+            Map.Entry<String,Long> entry = i.next();
             assertEquals(key(counter),entry.getKey());
             assertEquals(counter,(long)entry.getValue());
             counter++;
@@ -158,38 +161,40 @@ public class BTreeIndexTest extends Inde
         this.index.unload(tx);
         tx.commit();
     }
-    
-    
+
+    @Test(timeout=60000)
     public void testVisitor() throws Exception {
         createPageFileAndIndex(100);
         BTreeIndex<String,Long> index = ((BTreeIndex<String,Long>)this.index);
         this.index.load(tx);
         tx.commit();
-          
+
         // Insert in reverse order..
         doInsert(1000);
-        
+
         this.index.unload(tx);
         tx.commit();
         this.index.load(tx);
         tx.commit();
 
         // BTree should iterate it in sorted order.
-        
+
         index.visit(tx, new BTreeVisitor<String, Long>(){
-            public boolean isInterestedInKeysBetween(String first, String second) {
+            @Override
+			public boolean isInterestedInKeysBetween(String first, String second) {
                 return true;
             }
-            public void visit(List<String> keys, List<Long> values) {
+            @Override
+			public void visit(List<String> keys, List<Long> values) {
             }
         });
-        
+
 
         this.index.unload(tx);
         tx.commit();
     }
 
-
+    @Test(timeout=60000)
     public void testRandomRemove() throws Exception {
 
         createPageFileAndIndex(100);
@@ -231,6 +236,7 @@ public class BTreeIndexTest extends Inde
         }
     }
 
+    @Test(timeout=300000)
     public void testRandomAddRemove() throws Exception {
 
         createPageFileAndIndex(1024);
@@ -273,6 +279,7 @@ public class BTreeIndexTest extends Inde
         }
     }
 
+    @Test(timeout=60000)
     public void testRemovePattern() throws Exception {
         createPageFileAndIndex(100);
         BTreeIndex<String,Long> index = ((BTreeIndex<String,Long>)this.index);
@@ -319,9 +326,10 @@ public class BTreeIndexTest extends Inde
         assertNull(index.getLast(tx));
     }
 
+    @Test(timeout=60000)
     public void testLargeValue() throws Exception {
         //System.setProperty("maxKahaDBTxSize", "" + (1024*1024*1024));
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(4*1024);
         //pf.setEnablePageCaching(false);
         pf.load();
@@ -366,8 +374,9 @@ public class BTreeIndexTest extends Inde
         tx.commit();
     }
 
+    @Test(timeout=60000)
     public void testLargeValueOverflow() throws Exception {
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(4*1024);
         pf.setWriteBatchSize(1);
         pf.load();
@@ -422,8 +431,9 @@ public class BTreeIndexTest extends Inde
         tx.commit();
     }
 
+    @Test(timeout=60000)
     public void testIndexRepeatFillClearIncrementingPageReuse() throws Exception {
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(4*1024);
         pf.load();
 
@@ -467,11 +477,12 @@ public class BTreeIndexTest extends Inde
         }
     }
 
+    @Test(timeout=60000)
     public void testListIndexConsistancyOverTime() throws Exception {
 
         final int NUM_ITERATIONS = 50;
 
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(4*1024);
         //pf.setEnablePageCaching(false);
         pf.setWriteBatchSize(1);
@@ -543,7 +554,7 @@ public class BTreeIndexTest extends Inde
     }
     /**
      * Overriding so that this generates keys that are the worst case for the BTree. Keys
that
-     * always insert to the end of the BTree.  
+     * always insert to the end of the BTree.
      */
     @Override
     protected String key(int i) {
@@ -553,7 +564,8 @@ public class BTreeIndexTest extends Inde
     static class HashSetStringMarshaller extends VariableMarshaller<HashSet<String>>
{
         final static HashSetStringMarshaller INSTANCE = new HashSetStringMarshaller();
 
-        public void writePayload(HashSet<String> object, DataOutput dataOut) throws
IOException {
+        @Override
+		public void writePayload(HashSet<String> object, DataOutput dataOut) throws IOException
{
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             ObjectOutputStream oout = new ObjectOutputStream(baos);
             oout.writeObject(object);
@@ -564,7 +576,8 @@ public class BTreeIndexTest extends Inde
             dataOut.write(data);
         }
 
-        public HashSet<String> readPayload(DataInput dataIn) throws IOException {
+        @Override
+		public HashSet<String> readPayload(DataInput dataIn) throws IOException {
             int dataLen = dataIn.readInt();
             byte[] data = new byte[dataLen];
             dataIn.readFully(data);

Modified: activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/IndexTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/IndexTestSupport.java?rev=1415870&r1=1415869&r2=1415870&view=diff
==============================================================================
--- activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/IndexTestSupport.java
(original)
+++ activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/IndexTestSupport.java
Fri Nov 30 22:02:51 2012
@@ -24,6 +24,8 @@ import junit.framework.TestCase;
 import org.apache.activemq.store.kahadb.disk.page.PageFile;
 import org.apache.activemq.store.kahadb.disk.page.Transaction;
 import org.apache.activemq.util.IOHelper;
+import org.junit.After;
+import org.junit.Test;
 
 /**
  * Test a HashIndex
@@ -37,28 +39,26 @@ public abstract class IndexTestSupport e
     protected PageFile pf;
     protected Transaction tx;
 
-    /**
-     * @throws java.lang.Exception
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception {
-        super.setUp();
-        directory = new File(IOHelper.getDefaultDataDirectory() + System.currentTimeMillis());
-        IOHelper.delete(directory);
-    }
-
-    protected void tearDown() throws Exception {
+    @Override
+	@After
+    public void tearDown() throws Exception {
         if( pf!=null ) {
             pf.unload();
             pf.delete();
         }
+    }
+
+    public File getDirectory() {
         if (directory != null) {
             IOHelper.delete(directory);
         }
+        directory = new File(IOHelper.getDefaultDataDirectory() + System.currentTimeMillis());
+        IOHelper.delete(directory);
+        return directory;
     }
 
     protected void createPageFileAndIndex(int pageSize) throws Exception {
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(pageSize);
         pf.load();
         tx = pf.tx();
@@ -67,6 +67,7 @@ public abstract class IndexTestSupport e
 
     abstract protected Index<String, Long> createIndex() throws Exception;
 
+    @Test(timeout=60000)
     public void testIndex() throws Exception {
         createPageFileAndIndex(500);
         this.index.load(tx);

Modified: activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/ListIndexTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/ListIndexTest.java?rev=1415870&r1=1415869&r2=1415870&view=diff
==============================================================================
--- activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/ListIndexTest.java
(original)
+++ activemq/trunk/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/ListIndexTest.java
Fri Nov 30 22:02:51 2012
@@ -36,6 +36,7 @@ import org.apache.activemq.store.kahadb.
 import org.apache.activemq.store.kahadb.disk.util.SequenceSet;
 import org.apache.activemq.store.kahadb.disk.util.StringMarshaller;
 import org.apache.activemq.store.kahadb.disk.util.VariableMarshaller;
+import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -64,6 +65,7 @@ public class ListIndexTest extends Index
         return index;
     }
 
+    @Test(timeout=60000)
     public void testSize() throws Exception {
         createPageFileAndIndex(100);
 
@@ -98,6 +100,7 @@ public class ListIndexTest extends Index
         tx.commit();
     }
 
+    @Test(timeout=60000)
     public void testPut() throws Exception {
         createPageFileAndIndex(100);
 
@@ -130,6 +133,7 @@ public class ListIndexTest extends Index
         tx.commit();
     }
 
+    @Test(timeout=60000)
     public void testAddFirst() throws Exception {
         createPageFileAndIndex(100);
 
@@ -155,7 +159,7 @@ public class ListIndexTest extends Index
         counter--;
         int count = 0;
         while (iterator.hasNext() && count < counter) {
-            Map.Entry<String, Long> entry = (Map.Entry<String, Long>) iterator.next();
+            Map.Entry<String, Long> entry = iterator.next();
             assertEquals(key(count), entry.getKey());
             assertEquals(count, (long) entry.getValue());
             count++;
@@ -163,6 +167,7 @@ public class ListIndexTest extends Index
         tx.commit();
     }
 
+    @Test(timeout=60000)
     public void testPruning() throws Exception {
         createPageFileAndIndex(100);
 
@@ -212,6 +217,7 @@ public class ListIndexTest extends Index
         tx.commit();
     }
 
+    @Test(timeout=60000)
     public void testIterationAddFirst() throws Exception {
         createPageFileAndIndex(100);
         ListIndex<String, Long> index = ((ListIndex<String, Long>) this.index);
@@ -229,7 +235,7 @@ public class ListIndexTest extends Index
 
         int counter = 0;
         for (Iterator<Map.Entry<String, Long>> i = index.iterator(tx); i.hasNext();
) {
-            Map.Entry<String, Long> entry = (Map.Entry<String, Long>) i.next();
+            Map.Entry<String, Long> entry = i.next();
             assertEquals(key(counter), entry.getKey());
             assertEquals(counter, (long) entry.getValue());
             counter++;
@@ -245,7 +251,7 @@ public class ListIndexTest extends Index
         tx.commit();
     }
 
-
+    @Test(timeout=60000)
     public void testIteration() throws Exception {
         createPageFileAndIndex(100);
         ListIndex<String, Long> index = ((ListIndex<String, Long>) this.index);
@@ -263,7 +269,7 @@ public class ListIndexTest extends Index
 
         int counter = 0;
         for (Iterator<Map.Entry<String, Long>> i = index.iterator(tx); i.hasNext();
) {
-            Map.Entry<String, Long> entry = (Map.Entry<String, Long>) i.next();
+            Map.Entry<String, Long> entry = i.next();
             assertEquals(key(counter), entry.getKey());
             assertEquals(counter, (long) entry.getValue());
             counter++;
@@ -274,6 +280,7 @@ public class ListIndexTest extends Index
         tx.commit();
     }
 
+    @Test(timeout=60000)
     public void testRandomRemove() throws Exception {
 
         createPageFileAndIndex(4*1024);
@@ -298,6 +305,7 @@ public class ListIndexTest extends Index
         }
     }
 
+    @Test(timeout=60000)
     public void testRemovePattern() throws Exception {
         createPageFileAndIndex(100);
         ListIndex<String, Long> index = ((ListIndex<String, Long>) this.index);
@@ -311,6 +319,7 @@ public class ListIndexTest extends Index
         index.remove(tx, key(1566));
     }
 
+    @Test(timeout=60000)
     public void testLargeAppendRemoveTimed() throws Exception {
         createPageFileAndIndex(1024*4);
         ListIndex<String, Long> listIndex = ((ListIndex<String, Long>) this.index);
@@ -345,8 +354,9 @@ public class ListIndexTest extends Index
         return min + (int)(Math.random() * ((max - min) + 1));
     }
 
+    @Test(timeout=60000)
     public void testLargeValueOverflow() throws Exception {
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(4*1024);
         pf.setEnablePageCaching(false);
         pf.setWriteBatchSize(1);
@@ -429,11 +439,12 @@ public class ListIndexTest extends Index
         return "key:" + nf.format(i);
     }
 
+    @Test(timeout=60000)
     public void testListIndexConsistencyOverTime() throws Exception {
 
         final int NUM_ITERATIONS = 100;
 
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(4*1024);
         pf.setEnablePageCaching(false);
         pf.setWriteBatchSize(1);
@@ -496,11 +507,12 @@ public class ListIndexTest extends Index
         }
     }
 
+    @Test(timeout=60000)
     public void testListLargeDataAddWithReverseRemove() throws Exception {
 
         final int NUM_ITERATIONS = 100;
 
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(4*1024);
         pf.setEnablePageCaching(false);
         pf.setWriteBatchSize(1);
@@ -568,7 +580,7 @@ public class ListIndexTest extends Index
         final int NUM_ITERATIONS = 200;
         final int RANGE = 200000;
 
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(4*1024);
         pf.load();
         tx = pf.tx();
@@ -599,11 +611,12 @@ public class ListIndexTest extends Index
         LOG.info("duration: " + (System.currentTimeMillis() - start));
     }
 
+    @Test(timeout=60000)
     public void testListLargeDataAddAndNonSequentialRemove() throws Exception {
 
         final int NUM_ITERATIONS = 100;
 
-        pf = new PageFile(directory, getClass().getName());
+        pf = new PageFile(getDirectory(), getClass().getName());
         pf.setPageSize(4*1024);
         pf.setEnablePageCaching(false);
         pf.setWriteBatchSize(1);
@@ -681,7 +694,8 @@ public class ListIndexTest extends Index
     static class HashSetStringMarshaller extends VariableMarshaller<HashSet<String>>
{
         final static HashSetStringMarshaller INSTANCE = new HashSetStringMarshaller();
 
-        public void writePayload(HashSet<String> object, DataOutput dataOut) throws
IOException {
+        @Override
+		public void writePayload(HashSet<String> object, DataOutput dataOut) throws IOException
{
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             ObjectOutputStream oout = new ObjectOutputStream(baos);
             oout.writeObject(object);
@@ -692,7 +706,8 @@ public class ListIndexTest extends Index
             dataOut.write(data);
         }
 
-        @SuppressWarnings("unchecked")
+        @Override
+		@SuppressWarnings("unchecked")
         public HashSet<String> readPayload(DataInput dataIn) throws IOException {
             int dataLen = dataIn.readInt();
             byte[] data = new byte[dataLen];



Mime
View raw message