directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r649694 - in /directory/sandbox/akarasulu/bigbang/apacheds: core-avl/src/main/java/org/apache/directory/server/core/avltree/ jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ xdbm-search/src/main/java/org/...
Date Fri, 18 Apr 2008 21:22:35 GMT
Author: akarasulu
Date: Fri Apr 18 14:22:33 2008
New Revision: 649694

URL: http://svn.apache.org/viewvc?rev=649694&view=rev
Log:
changes for presence cursor and evaluator ...

 o added more test code for greater coverage
 o fixed bug with KeyTupleAvlCursor when calling afterLast() was not setting
   available and clearing values properly
 o fixed problem where null values were pluged into after() and before() on
   AvlTreeCursor, which now just returns the last() or first() value resp. if
   the element is null - this fixes an issue when advancing an index cursor 
   using an IndexEntry which does not have an Id value

Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleAvlCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceCursorTest.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java?rev=649694&r1=649693&r2=649694&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java
Fri Apr 18 14:22:33 2008
@@ -48,6 +48,13 @@
     public void after( K element ) throws Exception 
     {
         checkClosed( "after" );
+
+        if ( element == null )
+        {
+            afterLast();
+            return;
+        }
+
         LinkedAvlNode<K> found = tree.findGreater( element );
         
         if ( found == null )
@@ -85,6 +92,13 @@
     public void before( K element ) throws Exception 
     {
         checkClosed( "before" );
+
+        if ( element == null )
+        {
+            beforeFirst();
+            return;
+        }
+
         LinkedAvlNode<K> found = tree.findLess( element );
         if ( found == null )
         {

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleAvlCursor.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/KeyTupleAvlCursor.java?rev=649694&r1=649693&r2=649694&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleAvlCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleAvlCursor.java
Fri Apr 18 14:22:33 2008
@@ -102,6 +102,7 @@
     public void afterLast() throws Exception
     {
         wrapped.afterLast();
+        clearValue();
     }
 
 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java?rev=649694&r1=649693&r2=649694&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java
Fri Apr 18 14:22:33 2008
@@ -81,6 +81,7 @@
         {
             //noinspection unchecked
             presenceCursor.before( ( IndexEntry<String,Attributes> ) element );
+            return;
         }
 
         throw new UnsupportedOperationException( UNSUPPORTED_MSG );
@@ -93,6 +94,7 @@
         {
             //noinspection unchecked
             presenceCursor.after( ( IndexEntry<String,Attributes> ) element );
+            return;
         }
 
         throw new UnsupportedOperationException( UNSUPPORTED_MSG );
@@ -203,7 +205,14 @@
 
         if ( available )
         {
-            return ndnCursor.get();
+            /*
+             * The value of NDN indices is the normalized dn and we want the
+             * value to be the value of the attribute in question.  So we will
+             * set that accordingly here.
+             */
+            IndexEntry<String, Attributes> indexEntry = ndnCursor.get();
+            indexEntry.setValue( presenceEvaluator.getAttributeType().getOid() );
+            return indexEntry;
         }
 
         throw new InvalidCursorPositionException( "Cursor has not been positioned yet." );

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceCursorTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceCursorTest.java?rev=649694&r1=649693&r2=649694&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceCursorTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceCursorTest.java
Fri Apr 18 14:22:33 2008
@@ -26,10 +26,11 @@
 import org.apache.directory.server.schema.SerializableComparator;
 import org.apache.directory.server.schema.bootstrap.*;
 import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
 import org.apache.directory.server.xdbm.tools.StoreUtils;
-import org.apache.directory.server.xdbm.tools.IndexUtils;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.commons.io.FileUtils;
@@ -129,45 +130,110 @@
         PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
         PresenceCursor cursor = new PresenceCursor( store, evaluator );
 
+        assertEquals( node, evaluator.getExpression() );
+        assertTrue( cursor.isElementReused() );
+
         cursor.beforeFirst();
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 5, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 6, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 8, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 9, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 10, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 11, ( long ) cursor.get().getId() );
         assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // test first()
+        cursor.first();
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.CN_AT_OID, cursor.get().getValue() );
+
+        // test last()
+        cursor.last();
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.CN_AT_OID, cursor.get().getValue() );
+
+        // test beforeFirst()
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.CN_AT_OID, cursor.get().getValue() );
+
+        // test afterLast()
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.CN_AT_OID, cursor.get().getValue() );
+
+        // test before()
+        ForwardIndexEntry<String,Attributes> entry = new ForwardIndexEntry<String,Attributes>();
+        entry.setValue( SchemaConstants.CN_AT_OID );
+        cursor.before( entry );
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.CN_AT_OID, cursor.get().getValue() );
+
+        // test after()
+        entry = new ForwardIndexEntry<String,Attributes>();
+        cursor.after( entry );
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.CN_AT_OID, cursor.get().getValue() );
 
         node = new PresenceNode( SchemaConstants.OU_AT_OID );
         evaluator = new PresenceEvaluator( node, store, registries );
         cursor = new PresenceCursor( store, evaluator );
 
+        assertTrue( cursor.isElementReused() );
+
         cursor.beforeFirst();
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 2, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 3, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 4, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 5, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 6, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 7, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 8, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 9, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 11, ( long ) cursor.get().getId() );
         assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        assertFalse( cursor.isClosed() );
+        cursor.close();
+        assertTrue( cursor.isClosed() );
     }
 
 
@@ -178,22 +244,111 @@
         PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
         PresenceCursor cursor = new PresenceCursor( store, evaluator );
 
+        assertEquals( node, evaluator.getExpression() );
+        assertTrue( cursor.isElementReused() );
+
         cursor.beforeFirst();
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 8, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 6, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 5, ( long ) cursor.get().getId() );
         assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // test first()
+        cursor.first();
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.SN_AT_OID, cursor.get().getValue() );
+
+        // test last()
+        cursor.last();
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.SN_AT_OID, cursor.get().getValue() );
+
+        // test beforeFirst()
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.SN_AT_OID, cursor.get().getValue() );
+
+        // test afterLast()
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        assertEquals( SchemaConstants.SN_AT_OID, cursor.get().getValue() );
 
         node = new PresenceNode( SchemaConstants.O_AT_OID );
         evaluator = new PresenceEvaluator( node, store, registries );
         cursor = new PresenceCursor( store, evaluator );
 
+        assertTrue( cursor.isElementReused() );
+
         cursor.beforeFirst();
         assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
         assertEquals( 1, ( long ) cursor.get().getId() );
         assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        assertFalse( cursor.isClosed() );
+        cursor.close();
+        assertTrue( cursor.isClosed() );
+    }
+
+
+    @Test ( expected = InvalidCursorPositionException.class )
+    public void testInvalidCursorPositionException() throws Exception
+    {
+        PresenceNode node = new PresenceNode( SchemaConstants.SN_AT_OID );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceCursor cursor = new PresenceCursor( store, evaluator );
+        cursor.get();
+    }
+
+
+
+
+    @Test ( expected = InvalidCursorPositionException.class )
+    public void testInvalidCursorPositionException2() throws Exception
+    {
+        PresenceNode node = new PresenceNode( SchemaConstants.CN_AT_OID );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceCursor cursor = new PresenceCursor( store, evaluator );
+        cursor.get();
+    }
+
+
+    @Test ( expected = UnsupportedOperationException.class )
+    public void testUnsupportBeforeWithoutIndex() throws Exception
+    {
+        PresenceNode node = new PresenceNode( SchemaConstants.SN_AT_OID );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceCursor cursor = new PresenceCursor( store, evaluator );
+
+        // test before()
+        ForwardIndexEntry<String,Attributes> entry = new ForwardIndexEntry<String,Attributes>();
+        entry.setValue( SchemaConstants.SN_AT_OID );
+        cursor.before( entry );
+    }
+
+
+    @Test ( expected = UnsupportedOperationException.class )
+    public void testUnsupportAfterWithoutIndex() throws Exception
+    {
+        PresenceNode node = new PresenceNode( SchemaConstants.SN_AT_OID );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceCursor cursor = new PresenceCursor( store, evaluator );
+
+        // test before()
+        ForwardIndexEntry<String,Attributes> entry = new ForwardIndexEntry<String,Attributes>();
+        entry.setValue( SchemaConstants.SN_AT_OID );
+        cursor.after( entry );
     }
 }



Mime
View raw message