directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r637541 - in /directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src: main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/
Date Sun, 16 Mar 2008 05:04:59 GMT
Author: akarasulu
Date: Sat Mar 15 22:04:48 2008
New Revision: 637541

URL: http://svn.apache.org/viewvc?rev=637541&view=rev
Log:
more tests for greater code coverage of dups cursor

Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java?rev=637541&r1=637540&r2=637541&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
Sat Mar 15 22:04:48 2008
@@ -15,6 +15,9 @@
 
 /**
  * A Cursor over a BTree which manages duplicate keys.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
  */
 class DupsCursor<K,V> extends AbstractCursor<Tuple<K,V>>
 {
@@ -88,7 +91,7 @@
                 AvlTree<V> set = values.getAvlTree();
                 dupsCursor = new AvlTreeCursor<V>( set );
             }
-            else if ( values.isBTreeRedirect() )
+            else
             {
                 BTree tree = table.getBTree( values.getBTreeRedirect() );
                 dupsCursor = new KeyCursor<V>( tree, table.getValueComparator() );
@@ -99,13 +102,12 @@
                 return;
             }
 
-            // don't bother advancing the dupsCursor unless we're on same key
-            if ( table.getKeyComparator().compare( containerTuple.getKey(), element.getKey()
) != 0 )
+            // advance the dupsCursor only if we're on same key
+            if ( table.getKeyComparator().compare( containerTuple.getKey(), element.getKey()
) == 0 )
             {
-                return;
+                dupsCursor.before( element.getValue() );
             }
 
-            dupsCursor.before( element.getValue() );
             return;
         }
 
@@ -157,7 +159,7 @@
                 AvlTree<V> set = values.getAvlTree();
                 dupsCursor = new AvlTreeCursor<V>( set );
             }
-            else if ( values.isBTreeRedirect() )
+            else
             {
                 BTree tree = table.getBTree( values.getBTreeRedirect() );
                 dupsCursor = new KeyCursor<V>( tree, table.getValueComparator() );
@@ -168,13 +170,12 @@
                 return;
             }
 
-            // don't bother advancing the dupsCursor unless we're on same key
-            if ( table.getKeyComparator().compare( containerTuple.getKey(), element.getKey()
) != 0 )
+            // only advance the dupsCursor if we're on same key
+            if ( table.getKeyComparator().compare( containerTuple.getKey(), element.getKey()
) == 0 )
             {
-                return;
+                dupsCursor.after( element.getValue() );
             }
 
-            dupsCursor.after( element.getValue() );
             return;
         }
 
@@ -258,7 +259,7 @@
                 AvlTree<V> set = values.getAvlTree();
                 dupsCursor = new AvlTreeCursor<V>( set );
             }
-            else if ( values.isBTreeRedirect() )
+            else
             {
                 BTree tree = table.getBTree( values.getBTreeRedirect() );
                 dupsCursor = new KeyCursor<V>( tree, table.getValueComparator() );
@@ -316,7 +317,7 @@
                     AvlTree<V> set = values.getAvlTree();
                     dupsCursor = new AvlTreeCursor<V>( set );
                 }
-                else if ( values.isBTreeRedirect() )
+                else
                 {
                     BTree tree = table.getBTree( values.getBTreeRedirect() );
                     dupsCursor = new KeyCursor<V>( tree, table.getValueComparator()
);
@@ -363,7 +364,7 @@
                     AvlTree<V> set = values.getAvlTree();
                     dupsCursor = new AvlTreeCursor<V>( set );
                 }
-                else if ( values.isBTreeRedirect() )
+                else
                 {
                     BTree tree = table.getBTree( values.getBTreeRedirect() );
                     dupsCursor = new KeyCursor<V>( tree, table.getValueComparator()
);

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java?rev=637541&r1=637540&r2=637541&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java
Sat Mar 15 22:04:48 2008
@@ -24,6 +24,7 @@
 import org.apache.directory.server.core.partition.impl.btree.Table;
 import org.apache.directory.server.core.partition.impl.btree.Tuple;
 import org.apache.directory.server.core.cursor.Cursor;
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
 import org.apache.directory.server.schema.SerializableComparator;
 import org.junit.Before;
 import org.junit.After;
@@ -479,6 +480,65 @@
             ii++;
         }
 
+        // test before to advance just before a key with a single value but
+        // with a null tuple value which should not advance the dupsCursor
+        ii = 5;
+        cursor = table.cursor();
+        cursor.before( new Tuple<Integer,Integer>( 5, null ) );
+        while ( cursor.next() )
+        {
+            if ( ii > 17 && ii < 21 )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii > 12 && ii < 17 )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // test before to advance just before a key value pair where the key
+        // does not exist - using value so we hit check for key equality
+        ii = 21;
+        cursor = table.cursor();
+        cursor.before( new Tuple<Integer,Integer>( 18, 18 ) );
+        while ( cursor.next() )
+        {
+            if ( ii > 17 && ii < 21 )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii > 12 && ii < 17 )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // test after to advance just after the end
+        cursor = table.cursor();
+        cursor.after( new Tuple<Integer,Integer>( 111, null ) );
+        assertFalse( cursor.next() );
+
         // test after to advance just before a key with a single value
         ii = 6;
         cursor = table.cursor();
@@ -601,6 +661,319 @@
                 assertEquals( ii, ( int ) tuple.getValue() );
             }
             ii++;
+        }
+
+        // test after to advance just before a key and value where the key
+        // does not exist - used to force key comparison in after()
+        cursor = table.cursor();
+        cursor.after( new Tuple<Integer,Integer>( 18, 18 ) );
+
+        cursor.next();
+        tuple = cursor.get();
+        assertEquals( 21, ( int ) tuple.getKey() );
+        assertEquals( 21, ( int ) tuple.getValue() );
+        ii=22;
+
+        while ( cursor.next() )
+        {
+            if ( ii > 17 && ii < 21 )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            tuple = cursor.get();
+            if ( ii > 12 && ii < 17 )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+    }
+
+
+    @Test
+    public void testBeforeAfterOverDupLimit() throws Exception
+    {
+        for ( int ii = 0; ii < SIZE*3 - 1; ii++ )
+        {
+            if ( ii > 12 && ii < 17 + SIZE ) // keys with multiple values
+            {
+                table.put( 13, ii );
+            }
+            else if ( ii > 17 + SIZE  && ii < 21 + SIZE ) // adds hole with
no keys for ii
+            {
+            }
+            else // keys with single values
+            {
+                table.put( ii, ii );
+            }
+        }
+
+        // test before to advance just before a key with a single value
+        int ii = 5;
+        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+        cursor.before( new Tuple<Integer,Integer>( 5, 5 ) );
+        while ( cursor.next() )
+        {
+            if ( ii > 17 + SIZE && ii < 21 + SIZE )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii > 12 && ii < 17 + SIZE )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // test before to advance just before a key with a single value but
+        // with a null tuple value which should not advance the dupsCursor
+        ii = 5;
+        cursor = table.cursor();
+        cursor.before( new Tuple<Integer,Integer>( 5, null ) );
+        while ( cursor.next() )
+        {
+            if ( ii > 17 + SIZE && ii < 21 + SIZE )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii > 12 && ii < 17 + SIZE )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // test before to advance just before a key value pair where the key
+        // does not exist - using value so we hit check for key equality
+        ii = 21 + SIZE;
+        cursor = table.cursor();
+        cursor.before( new Tuple<Integer,Integer>( 18 + SIZE, 18 + SIZE ) );
+        while ( cursor.next() )
+        {
+            if ( ii > 17 + SIZE && ii < 21 + SIZE )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii > 12 && ii < 17 + SIZE )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // test after to advance just after the end
+        cursor = table.cursor();
+        cursor.after( new Tuple<Integer,Integer>( 111, null ) );
+        assertFalse( cursor.next() );
+
+        // test after to advance just before a key with a single value
+        ii = 6;
+        cursor = table.cursor();
+        cursor.after( new Tuple<Integer,Integer>( 5, null ) );
+        while ( cursor.next() )
+        {
+            if ( ii > 17 + SIZE && ii < 21 + SIZE )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii > 12 && ii < 17 + SIZE )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // test before to advance just before a key & value with multiple
+        // values for the key - we should advance just before the value
+        cursor = table.cursor();
+        cursor.before( new Tuple<Integer,Integer>( 13, 14 ) );
+
+        cursor.next();
+        Tuple<Integer,Integer> tuple = cursor.get();
+        assertEquals( 13, ( int ) tuple.getKey() );
+        assertEquals( 14, ( int ) tuple.getValue() );
+        ii = 15;
+
+        while ( cursor.next() )
+        {
+            if ( ii > 17 + SIZE && ii < 21 + SIZE )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            tuple = cursor.get();
+            if ( ii > 12 && ii < 17 + SIZE )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // test after to advance just before a key & value with multiple
+        // values for the key - we should advance just before the value
+        cursor = table.cursor();
+        cursor.after( new Tuple<Integer,Integer>( 13, 14 ) );
+
+        cursor.next();
+        tuple = cursor.get();
+        assertEquals( 13, ( int ) tuple.getKey() );
+        assertEquals( 15, ( int ) tuple.getValue() );
+        ii=16;
+
+        while ( cursor.next() )
+        {
+            if ( ii > 17 + SIZE && ii < 21 + SIZE )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            tuple = cursor.get();
+            if ( ii > 12 && ii < 17 + SIZE )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // test after to advance just before a key that does not exist
+        cursor = table.cursor();
+        cursor.after( new Tuple<Integer,Integer>( 18 + SIZE, null ) );
+
+        cursor.next();
+        tuple = cursor.get();
+        assertEquals( 21 + SIZE, ( int ) tuple.getKey() );
+        assertEquals( 21 + SIZE, ( int ) tuple.getValue() );
+        ii=22 + SIZE;
+
+        while ( cursor.next() )
+        {
+            if ( ii > 17 + SIZE && ii < 21 + SIZE )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            tuple = cursor.get();
+            if ( ii > 12 && ii < 17 + SIZE )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // test after to advance just before a key and value where the key
+        // does not exist - used to force key comparison in after()
+        cursor = table.cursor();
+        cursor.after( new Tuple<Integer,Integer>( 18 + SIZE , 18 + SIZE ) );
+
+        cursor.next();
+        tuple = cursor.get();
+        assertEquals( 21 + SIZE, ( int ) tuple.getKey() );
+        assertEquals( 21 + SIZE, ( int ) tuple.getValue() );
+        ii=22+ SIZE;
+
+        while ( cursor.next() )
+        {
+            if ( ii > 17 + SIZE && ii < 21 + SIZE )
+            {
+                assertFalse( table.has( ii ) );
+                continue;
+            }
+
+            tuple = cursor.get();
+            if ( ii > 12 && ii < 17 + SIZE )
+            {
+                assertEquals( 13, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+    }
+
+
+    @Test
+    public void testMiscellaneous() throws Exception
+    {
+        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+        assertNotNull( cursor );
+        assertTrue( cursor.isElementReused() );
+
+        try
+        {
+            cursor.get();
+            fail( "Should never get here due to invalid cursor position exception." );
+        }
+        catch( InvalidCursorPositionException e )
+        {
         }
     }
 }



Mime
View raw message