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
This commit is contained in:
Gary Tully 2010-08-09 13:43:39 +00:00
parent 7629eafd0a
commit 530ab0420b
1 changed files with 39 additions and 0 deletions

View File

@ -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;
@ -174,6 +175,44 @@ public class BTreeIndexTest extends IndexTestSupport {
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--) {
index.put(tx, key(i), (long)i);