directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r761656 - in /directory/apacheds/branches/ldif-partition/avl-partition/src: main/java/org/apache/directory/server/core/partition/avl/ test/java/org/apache/directory/server/core/partition/avl/
Date Fri, 03 Apr 2009 12:55:33 GMT
Author: akarasulu
Date: Fri Apr  3 12:55:33 2009
New Revision: 761656

URL: http://svn.apache.org/viewvc?rev=761656&view=rev
Log:
added more test cases, found bugs and fixed them

Modified:
    directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTable.java
    directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTableDupsCursor.java
    directory/apacheds/branches/ldif-partition/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlTableTest.java

Modified: directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTable.java?rev=761656&r1=761655&r2=761656&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTable.java
(original)
+++ directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTable.java
Fri Apr  3 12:55:33 2009
@@ -50,15 +50,23 @@
     private final String name;
     private final Comparator<K> keyComparator;
     private final Comparator<V> valComparator;
+    private final Comparator<Tuple<K,V>> keyOnlytupleComparator;
     private int count;
     
     
-    public AvlTable( String name, Comparator<K> keyComparator, Comparator<V>
valComparator, boolean dupsEnabled )
+    public AvlTable( String name, final Comparator<K> keyComparator, final Comparator<V>
valComparator, boolean dupsEnabled )
     {
         this.name = name;
         this.keyComparator = keyComparator;
         this.valComparator = valComparator;
         this.avl = new AvlTreeMapImpl<K, V>( keyComparator, valComparator, dupsEnabled
);
+        this.keyOnlytupleComparator = new Comparator<Tuple<K, V>>()
+        {
+            public int compare( Tuple<K, V> t0, Tuple<K, V> t1 )
+            {
+                return keyComparator.compare( t0.getKey(), t1.getKey() );
+            }
+        };
     }
     
 
@@ -395,7 +403,8 @@
             return new KeyTupleAvlCursor<K,V>( node.getValue().getOrderedSet(), key
);
         }
         
-        return new SingletonCursor<Tuple<K,V>>( new Tuple<K,V>( key, node.getValue().getSingleton()
) );
+        return new SingletonCursor<Tuple<K,V>>( new Tuple<K,V>( key, node.getValue().getSingleton()
), 
+                keyOnlytupleComparator );
     }
 
     
@@ -420,7 +429,7 @@
             return new AvlTreeCursor<V>( node.getValue().getOrderedSet() );
         }
         
-        return new SingletonCursor<V>( node.getValue().getSingleton() );
+        return new SingletonCursor<V>( node.getValue().getSingleton(), valComparator
);
     }
 
 

Modified: directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTableDupsCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTableDupsCursor.java?rev=761656&r1=761655&r2=761656&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTableDupsCursor.java
(original)
+++ directory/apacheds/branches/ldif-partition/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlTableDupsCursor.java
Fri Apr  3 12:55:33 2009
@@ -29,7 +29,7 @@
 import org.apache.directory.server.core.cursor.SingletonCursor;
 import org.apache.directory.server.xdbm.AbstractTupleCursor;
 import org.apache.directory.server.xdbm.Tuple;
-import org.apache.directory.server.xdbm.TupleCursor;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,7 +53,7 @@
      * The underlying wrapped cursor which returns Tuples whose values are
      * either V objects or AvlTree objects.
      */
-    private final TupleCursor<K,SingletonOrOrderedSet<V>> wrappedCursor;
+    private final AvlSingletonOrOrderedSetCursor<K, V> wrappedCursor;
     
     /**
      * A Cursor over a set of value objects for the current key held in the
@@ -115,7 +115,7 @@
     public void beforeValue( K key, V value ) throws Exception
     {
         checkNotClosed( "beforeValue()" );
-        wrappedCursor.before( new Tuple<K, SingletonOrOrderedSet<V>>( key, null
) );
+        wrappedCursor.beforeKey( key );
         
         if ( wrappedCursor.next() )
         {
@@ -128,11 +128,13 @@
             }
             else
             {
-                dupsCursor = new SingletonCursor<V>( wrappedTuple.getValue().getSingleton()
);
+                dupsCursor = new SingletonCursor<V>( 
+                    wrappedTuple.getValue().getSingleton(), wrappedCursor.getValuComparator()
);
             }
             
             if ( value == null )
             {
+                clearValue();
                 return;
             }
     
@@ -147,6 +149,7 @@
                 dupsCursor.before( value );
             }
             
+            clearValue();
             return;
         }
         
@@ -194,11 +197,11 @@
 
         if ( value == null )
         {
-            wrappedCursor.after( new Tuple<K, SingletonOrOrderedSet<V>>( key,
null ) );
+            wrappedCursor.afterKey( key );
         }
         else
         {
-            wrappedCursor.before( new Tuple<K, SingletonOrOrderedSet<V>>( key,
null ) );
+            wrappedCursor.beforeKey( key );
         }
 
         if ( wrappedCursor.next() )
@@ -213,11 +216,12 @@
             }
             else
             {
-                dupsCursor = new SingletonCursor<V>( values.getSingleton() );
+                dupsCursor = new SingletonCursor<V>( values.getSingleton(), wrappedCursor.getValuComparator()
);
             }
 
             if ( value == null )
             {
+                clearValue();
                 return;
             }
 
@@ -227,6 +231,7 @@
                 dupsCursor.after( value );
             }
 
+            clearValue();
             return;
         }
 
@@ -302,7 +307,7 @@
             }
             else
             {
-                dupsCursor = new SingletonCursor<V>( values.getSingleton() );
+                dupsCursor = new SingletonCursor<V>( values.getSingleton(), wrappedCursor.getValuComparator()
);
             }
 
             /*
@@ -366,7 +371,7 @@
             }
             else
             {
-                dupsCursor = new SingletonCursor<V>( values.getSingleton() );
+                dupsCursor = new SingletonCursor<V>( values.getSingleton(), wrappedCursor.getValuComparator()
);
             }
 
             /*
@@ -412,7 +417,7 @@
                 }
                 else
                 {
-                    dupsCursor = new SingletonCursor<V>( values.getSingleton() );
+                    dupsCursor = new SingletonCursor<V>( values.getSingleton(), wrappedCursor.getValuComparator()
);
                 }
 
                 /*
@@ -472,7 +477,7 @@
                 }
                 else
                 {
-                    dupsCursor = new SingletonCursor<V>( values.getSingleton() );
+                    dupsCursor = new SingletonCursor<V>( values.getSingleton(), wrappedCursor.getValuComparator()
);
                 }
 
                 /*

Modified: directory/apacheds/branches/ldif-partition/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlTableTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlTableTest.java?rev=761656&r1=761655&r2=761656&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlTableTest.java
(original)
+++ directory/apacheds/branches/ldif-partition/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlTableTest.java
Fri Apr  3 12:55:33 2009
@@ -58,6 +58,53 @@
     }
     
     
+    public void testCursorWithKey() throws Exception
+    {
+        injectNoDupsData( nodups );
+        Cursor<Tuple<Integer, Integer>> cursor = nodups.cursor( 2 );
+        
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+        
+        assertTrue( cursor.next() );
+        Tuple<Integer, Integer> tuple = cursor.get();
+        assertEquals( 2, tuple.getKey().intValue() );
+        assertEquals( 1, tuple.getValue().intValue() );
+        
+        assertFalse( cursor.next() );
+        
+        
+        // ---- on duplicates ----
+        
+        
+        injectDupsData( dups );
+        cursor = dups.cursor( 3 );
+        assertFalse( cursor.available() );
+        
+        assertTrue( cursor.next() );
+        tuple = cursor.get();
+        assertEquals( 3, tuple.getKey().intValue() );
+        assertEquals( 0, tuple.getValue().intValue() );
+        
+        assertTrue( cursor.next() );
+        tuple = cursor.get();
+        assertEquals( 3, tuple.getKey().intValue() );
+        assertEquals( 8, tuple.getValue().intValue() );
+        
+        assertTrue( cursor.next() );
+        tuple = cursor.get();
+        assertEquals( 3, tuple.getKey().intValue() );
+        assertEquals( 9, tuple.getValue().intValue() );
+        
+        assertTrue( cursor.next() );
+        tuple = cursor.get();
+        assertEquals( 3, tuple.getKey().intValue() );
+        assertEquals( 10, tuple.getValue().intValue() );
+        
+        assertFalse( cursor.next() );
+    }
+    
+    
     public void testCursor() throws Exception
     {
         injectNoDupsData( nodups );
@@ -177,7 +224,67 @@
         assertEquals( 8934, tuple.getValue().intValue() );
         
         assertFalse( cursor.next() );
-        cursor.close();
+
+    
+        // test beforeFirst
+        
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+        assertTrue( cursor.next() );
+        tuple = cursor.get();
+        assertNotNull( tuple );
+        assertEquals( 0, tuple.getKey().intValue() );
+        assertEquals( 3, tuple.getValue().intValue() );
+        
+        // test afterLast
+        
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+        assertFalse( cursor.next() );
+        assertTrue( cursor.previous() );
+        tuple = cursor.get();
+        assertNotNull( tuple );
+        assertEquals( 23, tuple.getKey().intValue() );
+        assertEquals( 8934, tuple.getValue().intValue() );
+    }
+    
+    
+    /**
+     * Checks that cursor.after() behavior with duplicates enabled obeys 
+     * the required semantics.
+     */
+    public void testCursorAfterWithDups() throws Exception
+    {
+        injectDupsData( dups );
+        Cursor<Tuple<Integer, Integer>> cursor;
+        Tuple<Integer, Integer> tuple = new Tuple<Integer, Integer>();
+        
+        cursor = dups.cursor();
+        cursor.after( tuple.setKey( 1 ) );
+        assertFalse( cursor.available() );
+        assertTrue( cursor.next() );
+        tuple = cursor.get();
+        assertNotNull( tuple );
+        assertEquals( 2, tuple.getKey().intValue() );
+        assertEquals( 1, tuple.getValue().intValue() );
+        
+        tuple = new Tuple<Integer, Integer>();
+        cursor.after( tuple.setKey( 2 ) );
+        assertFalse( cursor.available() );
+        assertTrue( cursor.next() );
+        tuple = cursor.get();
+        assertNotNull( tuple );
+        assertEquals( 3, tuple.getKey().intValue() );
+        assertEquals( 0, tuple.getValue().intValue() );
+        
+        tuple = new Tuple<Integer, Integer>();
+        cursor.after( tuple.setKey( 3 ) );
+        assertFalse( cursor.available() );
+        assertTrue( cursor.next() );
+        tuple = cursor.get();
+        assertNotNull( tuple );
+        assertEquals( 23, tuple.getKey().intValue() );
+        assertEquals( 8934, tuple.getValue().intValue() );
     }
     
     



Mime
View raw message