directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r637566 - 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 08:48:32 GMT
Author: akarasulu
Date: Sun Mar 16 01:48:31 2008
New Revision: 637566

URL: http://svn.apache.org/viewvc?rev=637566&view=rev
Log:
more tests and 100% coverage for DupsContainerCursor

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursorTest.java
      - copied, changed from r637553, directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursorTest.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.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/DupsContainerCursor.java?rev=637566&r1=637565&r2=637566&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
Sun Mar 16 01:48:31 2008
@@ -108,36 +108,17 @@
             //noinspection unchecked
             K next = ( K ) jdbmTuple.getKey();
 
-            //noinspection unchecked
             int nextCompared = table.getKeyComparator().compare( next, element.getKey() );
 
-            if ( nextCompared <= 0 )
-            {
-                // just continue
-            }
-            else if ( nextCompared > 0 )
+            if ( nextCompared > 0 )
             {
-                /*
-                 * If we just have values greater than the element argument
-                 * then we are before the first element and cannot backup, and
-                 * the call below to getPrevious() will fail.  In this special
-                 * case we just reset the Cursor's browser and return.
-                 */
-                if ( browser.getPrevious( jdbmTuple ) )
-                {
-                }
-                else
-                {
-                    browser = table.getBTree().browse( element.getKey() );
-                }
-
+                browser.getPrevious( jdbmTuple );
                 clearValue();
                 return;
             }
         }
 
         clearValue();
-        // just return
     }
 
 
@@ -217,7 +198,6 @@
     {
         if ( valueAvailable )
         {
-            //noinspection unchecked
             return returnedTuple;
         }
 
@@ -227,6 +207,6 @@
 
     public boolean isElementReused()
     {
-        return false;
+        return true;
     }
 }

Copied: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursorTest.java
(from r637553, directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursorTest.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/DupsContainerCursorTest.java?p2=directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursorTest.java&p1=directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursorTest.java&r1=637553&r2=637566&rev=637566&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursorTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursorTest.java
Sun Mar 16 01:48:31 2008
@@ -21,7 +21,6 @@
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-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;
@@ -39,26 +38,27 @@
 import java.util.Iterator;
 
 import jdbm.RecordManager;
+import jdbm.helper.IntegerSerializer;
 import jdbm.recman.BaseRecordManager;
 
 import javax.naming.NamingException;
 
 
 /**
- * Tests the Cursor functionality of a JdbmTable when duplicate keys are not
- * supported.
+ * Tests the DupsContainerCursor.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class NoDupsCursorTest
+public class DupsContainerCursorTest
 {
     private static final Logger LOG = LoggerFactory.getLogger( NoDupsCursorTest.class.getSimpleName()
);
     private static final String TEST_OUTPUT_PATH = "test.output.path";
 
-    transient Table<Integer,Integer> table;
+    transient JdbmTable<Integer,Integer> table;
     transient File dbFile;
     transient RecordManager recman;
+    private static final int SIZE = 15;
 
 
     @Before
@@ -75,8 +75,13 @@
 
         // gosh this is a terrible use of a global static variable
         SerializableComparator.setRegistry( new MockComparatorRegistry() );
-        table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>(
"" ), null, null );
+
+        table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
+                new SerializableComparator<Integer>( "" ),
+                new SerializableComparator<Integer>( "" ),
+                null, new IntegerSerializer() );
         LOG.debug( "Created new table and populated it with data" );
+
     }
 
 
@@ -92,23 +97,46 @@
     }
 
 
+    @Test( expected=IllegalStateException.class )
+    public void testUsingNoDuplicates() throws Exception
+    {
+        File tmpDir = null;
+        if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
+        {
+            tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
+        }
+
+        dbFile = File.createTempFile( getClass().getSimpleName(), "db", tmpDir );
+        recman = new BaseRecordManager( dbFile.getAbsolutePath() );
+
+        // gosh this is a terrible use of a global static variable
+        SerializableComparator.setRegistry( new MockComparatorRegistry() );
+        table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>(
"" ), null, null );
+
+        Cursor<Tuple<Integer,DupsContainer<Integer>>> cursor =
+            new DupsContainerCursor<Integer,Integer>( table );
+        assertNotNull( cursor );
+    }
+
+
     @Test( expected=InvalidCursorPositionException.class )
     public void testEmptyTable() throws Exception
     {
-        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+        Cursor<Tuple<Integer,DupsContainer<Integer>>> cursor =
+            new DupsContainerCursor<Integer,Integer>( table );
         assertNotNull( cursor );
-        
+
         assertFalse( cursor.available() );
         assertFalse( cursor.isClosed() );
         assertTrue( cursor.isElementReused() );
 
-        cursor = table.cursor();
+        cursor = new DupsContainerCursor<Integer,Integer>( table );
         assertFalse( cursor.previous() );
 
-        cursor = table.cursor();
+        cursor = new DupsContainerCursor<Integer,Integer>( table );
         assertFalse( cursor.next() );
 
-        cursor.after( new Tuple<Integer,Integer>(7,7) );
+        cursor.after( new Tuple<Integer,DupsContainer<Integer>>( 7, null ) );
         cursor.get();
     }
 
@@ -117,19 +145,20 @@
     public void testOnTableWithSingleEntry() throws Exception
     {
         table.put( 1, 1 );
-        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+        Cursor<Tuple<Integer,DupsContainer<Integer>>> cursor =
+            new DupsContainerCursor<Integer,Integer>( table );
         assertTrue( cursor.first() );
-    
-        Tuple<Integer,Integer> tuple = cursor.get();
+
+        Tuple<Integer,DupsContainer<Integer>> tuple = cursor.get();
         assertTrue( tuple.getKey().equals( 1 ) );
-        assertTrue( tuple.getValue().equals( 1 ) );
-    
+        assertEquals( 1, ( int ) tuple.getValue().getAvlTree().getFirst().getKey() );
+
         cursor.beforeFirst();
         assertFalse( cursor.previous() );
         assertTrue( cursor.next() );
     }
 
-    
+
     @Test
     public void testOnTableWithMultipleEntries() throws Exception
     {
@@ -137,51 +166,52 @@
         {
             table.put( i, i );
         }
-    
-        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
-        
-        cursor.after( new Tuple<Integer,Integer>( 2,2 ) );
+
+        Cursor<Tuple<Integer,DupsContainer<Integer>>> cursor =
+            new DupsContainerCursor<Integer,Integer>( table );
+
+        cursor.after( new Tuple<Integer,DupsContainer<Integer>>( 2, null ) );
         assertTrue( cursor.next() );
-    
-        Tuple<Integer,Integer> tuple = cursor.get();
+
+        Tuple<Integer,DupsContainer<Integer>> tuple = cursor.get();
         assertTrue( tuple.getKey().equals( 3 ) );
-        assertTrue( tuple.getValue().equals( 3 ) );
-    
-        cursor.before( new Tuple<Integer,Integer>(7,7) );
+        assertEquals( 3, ( int ) tuple.getValue().getAvlTree().getFirst().getKey() );
+
+        cursor.before( new Tuple<Integer,DupsContainer<Integer>>( 7, null ) );
         cursor.next();
         tuple = cursor.get();
         assertTrue( tuple.getKey().equals( 7 ) );
-        assertTrue( tuple.getValue().equals( 7 ) );
-    
+        assertEquals( 7, ( int ) tuple.getValue().getAvlTree().getFirst().getKey() );
+
         cursor.last();
         cursor.next();
         tuple = cursor.get();
         assertTrue( tuple.getKey().equals( 9 ) );
-        assertTrue( tuple.getValue().equals( 9 ) );
-    
+        assertEquals( 9, ( int ) tuple.getValue().getAvlTree().getFirst().getKey() );
+
         cursor.beforeFirst();
         cursor.next();
         tuple = cursor.get();
         assertTrue( tuple.getKey().equals( 1 ) );
-        assertTrue( tuple.getValue().equals( 1 ) );
-    
+        assertEquals( 1, ( int ) tuple.getValue().getAvlTree().getFirst().getKey() );
+
         cursor.afterLast();
         assertFalse( cursor.next() );
 
         cursor.beforeFirst();
         assertFalse( cursor.previous() );
-        
+
         // just to clear the jdbmTuple value so that line 127 inside after(tuple) method
         // can be executed as part of the below after(tuple) call
-        cursor.before(new Tuple<Integer,Integer>( 1,1 )); 
-        cursor.after( new Tuple<Integer,Integer>( 0,0 ) );
-        
+        cursor.before(new Tuple<Integer,DupsContainer<Integer>>( 1, null ) );
+        cursor.after( new Tuple<Integer,DupsContainer<Integer>>( 0, null ) );
+
         cursor.next();
         tuple = cursor.get();
         assertTrue( tuple.getKey().equals( 1 ) );
-        assertTrue( tuple.getValue().equals( 1 ) );
+        assertEquals( 1, ( int ) tuple.getValue().getAvlTree().getFirst().getKey() );
     }
-    
+
 
     @Test
     public void testMiscellaneous() throws Exception
@@ -248,4 +278,4 @@
         {
         }
     }
-}
+}
\ No newline at end of file



Mime
View raw message