From 530ab0420b51b22f9a6c70b78ecb3068a76ffe00 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Mon, 9 Aug 2010 13:43:39 +0000 Subject: [PATCH] test showing npe remove issue in kahadb index git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@983644 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/kahadb/index/BTreeIndexTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java b/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java index d1740c98b3..569c2b76d8 100644 --- a/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java +++ b/kahadb/src/test/java/org/apache/kahadb/index/BTreeIndexTest.java @@ -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 IndexTestSupport { this.index.unload(tx); tx.commit(); } + + + public void testRandomRemove() throws Exception { + + createPageFileAndIndex(100); + BTreeIndex index = ((BTreeIndex)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 index = ((BTreeIndex)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--) {