activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1306515 - /activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java
Date Wed, 28 Mar 2012 17:55:32 GMT
Author: tabish
Date: Wed Mar 28 17:55:32 2012
New Revision: 1306515

URL: http://svn.apache.org/viewvc?rev=1306515&view=rev
Log:
Adding new test to show an issue in the list lindex on removes.

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

Modified: activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java?rev=1306515&r1=1306514&r2=1306515&view=diff
==============================================================================
--- activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java (original)
+++ activemq/trunk/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java Wed Mar
28 17:55:32 2012
@@ -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 Index
         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<String, SequenceSet> test = new ListIndex<String, SequenceSet>(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<HashSet<String>>
{
         final static HashSetStringMarshaller INSTANCE = new HashSetStringMarshaller();
 



Mime
View raw message