directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r637544 - /directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java
Date Sun, 16 Mar 2008 05:44:26 GMT
Author: akarasulu
Date: Sat Mar 15 22:44:24 2008
New Revision: 637544

URL: http://svn.apache.org/viewvc?rev=637544&view=rev
Log:
added more tests to dups cursor for 100% code coverage

Modified:
    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/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=637544&r1=637543&r2=637544&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:44:24 2008
@@ -338,7 +338,14 @@
     {
         for ( int ii = 0; ii < SIZE*3-1; ii++ )
         {
-            table.put( ii, ii );
+            if ( ii < 2 + SIZE ) // keys with multiple values
+            {
+                table.put( 0, ii );
+            }
+            else // keys with single values
+            {
+                table.put( ii, ii );
+            }
         }
         Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
 
@@ -346,8 +353,16 @@
         while ( cursor.next() )
         {
             Tuple<Integer,Integer> tuple = cursor.get();
-            assertEquals( ii, ( int ) tuple.getKey() );
-            assertEquals( ii, ( int ) tuple.getValue() );
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
             ii++;
         }
 
@@ -357,8 +372,16 @@
         do
         {
             Tuple<Integer,Integer> tuple = cursor.get();
-            assertEquals( ii, ( int ) tuple.getKey() );
-            assertEquals( ii, ( int ) tuple.getValue() );
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
             ii++;
         }
         while ( cursor.next() );
@@ -368,8 +391,247 @@
         while ( cursor.previous() )
         {
             Tuple<Integer,Integer> tuple = cursor.get();
-            assertEquals( ii, ( int ) tuple.getKey() );
-            assertEquals( ii, ( int ) tuple.getValue() );
+
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii--;
+        }
+
+        // now advance to last and go backwards again
+        cursor.last();
+        ii = SIZE*3-2;
+        do
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii--;
+        }
+        while ( cursor.previous() );
+
+        // advance to first then last and go backwards again
+        cursor.beforeFirst();
+        cursor.afterLast();
+        ii = SIZE*3-2;
+        while ( cursor.previous() )
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii--;
+        }
+    }
+
+
+    @Test
+    public void testFirstOverDupLimit() throws Exception
+    {
+        for ( int ii = 0; ii < SIZE*3-1; ii++ )
+        {
+            if ( ii < 2 + SIZE ) // keys with multiple values
+            {
+                table.put( 0, ii );
+            }
+            else // keys with single values
+            {
+                table.put( ii, ii );
+            }
+        }
+        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+
+        int ii = 0;
+        while ( cursor.next() )
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // now go back to first and traverse all over again
+        cursor.first();
+        ii = 0;
+        do
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+        while ( cursor.next() );
+
+        // now go backwards
+        ii = SIZE*3-2;
+        while ( cursor.previous() )
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii--;
+        }
+
+        // now advance to last and go backwards again
+        cursor.last();
+        ii = SIZE*3-2;
+        do
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii--;
+        }
+        while ( cursor.previous() );
+
+        // advance to first then last and go backwards again
+        cursor.beforeFirst();
+        cursor.afterLast();
+        ii = SIZE*3-2;
+        while ( cursor.previous() )
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii < 2 + SIZE )
+            {
+                assertEquals( 0, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii--;
+        }
+    }
+
+
+
+
+    @Test
+    public void testLastOverDupLimit() throws Exception
+    {
+        for ( int ii = 0; ii < SIZE*3-1; ii++ )
+        {
+            if ( ii > 2 + SIZE ) // keys with multiple values
+            {
+                table.put( 3 + SIZE, ii );
+            }
+            else // keys with single values
+            {
+                table.put( ii, ii );
+            }
+        }
+        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+
+        int ii = 0;
+        while ( cursor.next() )
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii > 2 + SIZE )
+            {
+                assertEquals( 3 + SIZE, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+
+        // now go back to first and traverse all over again
+        cursor.first();
+        ii = 0;
+        do
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+            if ( ii > 2 + SIZE )
+            {
+                assertEquals( 3 + SIZE, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            ii++;
+        }
+        while ( cursor.next() );
+
+        // now go backwards
+        ii = SIZE*3-2;
+        while ( cursor.previous() )
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+
+            if ( ii > 2 + SIZE )
+            {
+                assertEquals( 3 + SIZE, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
             ii--;
         }
 
@@ -379,8 +641,16 @@
         do
         {
             Tuple<Integer,Integer> tuple = cursor.get();
-            assertEquals( ii, ( int ) tuple.getKey() );
-            assertEquals( ii, ( int ) tuple.getValue() );
+            if ( ii > 2 + SIZE )
+            {
+                assertEquals( 3 + SIZE, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
             ii--;
         }
         while ( cursor.previous() );
@@ -392,8 +662,16 @@
         while ( cursor.previous() )
         {
             Tuple<Integer,Integer> tuple = cursor.get();
-            assertEquals( ii, ( int ) tuple.getKey() );
-            assertEquals( ii, ( int ) tuple.getValue() );
+            if ( ii > 2 + SIZE )
+            {
+                assertEquals( 3 + SIZE, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
+            else
+            {
+                assertEquals( ii, ( int ) tuple.getKey() );
+                assertEquals( ii, ( int ) tuple.getValue() );
+            }
             ii--;
         }
     }



Mime
View raw message