You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2008/03/16 06:32:22 UTC

svn commit: r637543 - 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/

Author: akarasulu
Date: Sat Mar 15 22:32:17 2008
New Revision: 637543

URL: http://svn.apache.org/viewvc?rev=637543&view=rev
Log:
added more test cases and cleaned up useless logic pointed out by coverage tools in DupsCursor

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=637543&r1=637542&r2=637543&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:32:17 2008
@@ -225,23 +225,18 @@
                 dupsCursor = new KeyCursor<V>( bt, table.getValueComparator() );
             }
 
-            // *** meant to be an assignment = instead of == ***
-            if ( valueAvailable = dupsCursor.first() )
-            {
-                returnedTuple.setKey( containerTuple.getKey() );
-                returnedTuple.setValue( dupsCursor.get() );
-            }
-            else
-            {
-                clearValue();
-                dupsCursor = null;
-            }
-
-            return valueAvailable;
+            /*
+             * Since only tables with duplicate keys enabled use this
+             * cursor, entries must have at least one value, and therefore
+             * call to last() will always return true.
+             */
+            dupsCursor.first();
+            valueAvailable =  true;
+            returnedTuple.setKey( containerTuple.getKey() );
+            returnedTuple.setValue( dupsCursor.get() );
+            return true;
         }
 
-        clearValue();
-        dupsCursor = null;
         return false;
     }
 
@@ -249,6 +244,8 @@
     public boolean last() throws Exception
     {
         clearValue();
+        dupsCursor = null;
+
         if ( containerCursor.last() )
         {
             containerTuple.setBoth( containerCursor.get() );
@@ -265,22 +262,18 @@
                 dupsCursor = new KeyCursor<V>( tree, table.getValueComparator() );
             }
 
-            // *** meant to be an assignment = instead of == ***
-            if ( valueAvailable = dupsCursor.last() )
-            {
-                returnedTuple.setKey( containerTuple.getKey() );
-                returnedTuple.setValue( dupsCursor.get() );
-            }
-            else
-            {
-                clearValue();
-                dupsCursor = null;
-            }
-            return valueAvailable;
+            /*
+             * Since only tables with duplicate keys enabled use this
+             * cursor, entries must have at least one value, and therefore
+             * call to last() will always return true.
+             */
+            dupsCursor.last();
+            valueAvailable = true;
+            returnedTuple.setKey( containerTuple.getKey() );
+            returnedTuple.setValue( dupsCursor.get() );
+            return true;
         }
 
-        clearValue();
-        dupsCursor = null;
         return false;
     }
 
@@ -300,7 +293,7 @@
          * If the iterator over the values of the current key is null or is
          * extinguished then we need to advance to the previous key.
          */
-        while ( null == dupsCursor || ! dupsCursor.previous() )
+        if ( null == dupsCursor || ! dupsCursor.previous() )
         {
             /*
              * If the underlying cursor has more elements we get the previous
@@ -323,11 +316,14 @@
                     dupsCursor = new KeyCursor<V>( tree, table.getValueComparator() );
                 }
 
+                /*
+                 * Since only tables with duplicate keys enabled use this
+                 * cursor, entries must have at least one value, and therefore
+                 * call to previous() after bringing the cursor to afterLast()
+                 * will always return true.
+                 */
                 dupsCursor.afterLast();
-                if ( dupsCursor.previous() )
-                {
-                    break;
-                }
+                dupsCursor.previous();
             }
             else
             {
@@ -348,7 +344,7 @@
          * If the iterator over the values of the current key is null or is
          * extinguished then we need to advance to the next key.
          */
-        while ( null == dupsCursor || ! dupsCursor.next() )
+        if ( null == dupsCursor || ! dupsCursor.next() )
         {
             /*
              * If the underlying cursor has more elements we get the next
@@ -370,11 +366,14 @@
                     dupsCursor = new KeyCursor<V>( tree, table.getValueComparator() );
                 }
 
+                /*
+                 * Since only tables with duplicate keys enabled use this
+                 * cursor, entries must have at least one value, and therefore
+                 * call to next() after bringing the cursor to beforeFirst()
+                 * will always return true.
+                 */
                 dupsCursor.beforeFirst();
-                if ( dupsCursor.next() )
-                {
-                    break;
-                }
+                dupsCursor.next();
             }
             else
             {

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=637543&r1=637542&r2=637543&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:32:17 2008
@@ -93,6 +93,23 @@
 
 
     @Test
+    public void testEmptyTableOperations() throws Exception
+    {
+        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+        assertFalse( cursor.next() );
+        
+        cursor.afterLast();
+        assertFalse( cursor.previous() );
+
+        cursor.beforeFirst();
+        assertFalse( cursor.next() );
+
+        assertFalse( cursor.first() );
+        assertFalse( cursor.last() );
+    }
+
+
+    @Test
     public void testNextNoDups() throws Exception
     {
         // first try without duplicates at all