activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r983644 - /activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java
Date Mon, 09 Aug 2010 13:43:39 GMT
Author: gtully
Date: Mon Aug  9 13:43:39 2010
New Revision: 983644

URL: http://svn.apache.org/viewvc?rev=983644&view=rev
Log:
test showing npe remove issue in kahadb index

Modified:
    activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java

Modified: activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java?rev=983644&r1=983643&r2=983644&view=diff
==============================================================================
--- activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java (original)
+++ activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java Mon Aug
 9 13:43:39 2010
@@ -21,6 +21,7 @@ import java.text.NumberFormat;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 
 import org.apache.kahadb.index.BTreeIndex;
 import org.apache.kahadb.index.Index;
@@ -173,6 +174,44 @@ public class BTreeIndexTest extends Inde
         this.index.unload(tx);
         tx.commit();
     }
+
+
+    public void testRandomRemove() throws Exception {
+
+        createPageFileAndIndex(100);
+        BTreeIndex<String,Long> index = ((BTreeIndex<String,Long>)this.index);
+        this.index.load(tx);
+        tx.commit();
+
+        final int count = 4000;
+        doInsert(count);
+
+        Random rand = new Random(System.currentTimeMillis());
+        int i = 0, prev = 0;
+        while (!index.isEmpty(tx)) {
+            prev = i;
+            i = rand.nextInt(count);
+            try {
+                index.remove(tx, key(i));
+            } catch (Exception e) {
+                e.printStackTrace();
+                fail("unexpected exception on " + i + ", prev: " + prev + ", ex: " + e);
+            }
+        }
+    }
+
+    public void testRemovePattern() throws Exception {
+        createPageFileAndIndex(100);
+        BTreeIndex<String,Long> index = ((BTreeIndex<String,Long>)this.index);
+        this.index.load(tx);
+        tx.commit();
+
+        final int count = 4000;
+        doInsert(count);
+
+        index.remove(tx, key(3697));
+        index.remove(tx, key(1566));
+    }
     
     void doInsertReverse(int count) throws Exception {
         for (int i = count-1; i >= 0; i--) {



Mime
View raw message