From 6d58dbef32fee838d6fa76709613a0ddc7a3a52f Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Wed, 28 Mar 2012 17:55:32 +0000 Subject: [PATCH] Adding new test to show an issue in the list lindex on removes. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1306515 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/kahadb/index/ListIndexTest.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java b/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java index 437b925208..b58df01b8f 100644 --- a/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java +++ b/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java @@ -32,6 +32,7 @@ import java.util.Random; import org.apache.kahadb.page.PageFile; import org.apache.kahadb.util.LongMarshaller; +import org.apache.kahadb.util.SequenceSet; import org.apache.kahadb.util.StringMarshaller; import org.apache.kahadb.util.VariableMarshaller; import org.slf4j.Logger; @@ -427,6 +428,81 @@ public class ListIndexTest extends IndexTestSupport { return "key:" + nf.format(i); } + public void testListIndexConsistancyOverTime() throws Exception { + + final int NUM_ITERATIONS = 100; + + pf = new PageFile(directory, getClass().getName()); + pf.setPageSize(4*1024); + pf.setEnablePageCaching(false); + pf.setWriteBatchSize(1); + pf.load(); + tx = pf.tx(); + long id = tx.allocate().getPageId(); + + ListIndex test = new ListIndex(pf, id); + test.setKeyMarshaller(StringMarshaller.INSTANCE); + test.setValueMarshaller(SequenceSet.Marshaller.INSTANCE); + test.load(tx); + tx.commit(); + + int expectedListEntries = 0; + int nextSequenceId = 0; + + LOG.info("Loading up the ListIndex with "+NUM_ITERATIONS+" entires and sparsely populating the sequences."); + + for (int i = 0; i < NUM_ITERATIONS; ++i) { + tx = pf.tx(); + test.add(tx, String.valueOf(expectedListEntries++), new SequenceSet()); + tx.commit(); + + tx = pf.tx(); + for (int j = 0; j < expectedListEntries; j++) { + + SequenceSet sequenceSet = test.get(tx, String.valueOf(j)); + + int startSequenceId = nextSequenceId; + for (int ix = 0; ix < NUM_ITERATIONS; ix++) { + sequenceSet.add(nextSequenceId++); + test.put(tx, String.valueOf(j), sequenceSet); + } + + sequenceSet = test.get(tx, String.valueOf(j)); + + for (int ix = 0; ix < NUM_ITERATIONS - 1; ix++) { + sequenceSet.remove(startSequenceId++); + test.put(tx, String.valueOf(j), sequenceSet); + } + } + tx.commit(); + } + + LOG.info("Checking if Index has the expected number of entries."); + + for (int i = 0; i < NUM_ITERATIONS; ++i) { + tx = pf.tx(); + assertTrue("List should contain Key["+i+"]",test.containsKey(tx, String.valueOf(i))); + assertNotNull("List contents of Key["+i+"] should not be null", test.get(tx, String.valueOf(i))); + tx.commit(); + } + + LOG.info("Index has the expected number of entries."); + + assertEquals(expectedListEntries, test.size()); + + for (int i = 0; i < NUM_ITERATIONS; ++i) { + LOG.info("Size of ListIndex before removal of entry ["+i+"] is: " + test.size()); + tx = pf.tx(); + +// assertTrue("List should contain Key["+i+"]",test.containsKey(tx, String.valueOf(i))); + assertNotNull("List contents of Key["+i+"] should not be null", test.remove(tx, String.valueOf(i))); + tx.commit(); + LOG.info("Size of ListIndex after removal of entry ["+i+"] is: " + test.size()); + + assertEquals(expectedListEntries - (i + 1), test.size()); + } + } + static class HashSetStringMarshaller extends VariableMarshaller> { final static HashSetStringMarshaller INSTANCE = new HashSetStringMarshaller();