directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r649882 - in /directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src: main/java/org/apache/directory/server/xdbm/search/impl/ test/java/org/apache/directory/server/xdbm/search/impl/
Date Sun, 20 Apr 2008 04:04:08 GMT
Author: akarasulu
Date: Sat Apr 19 21:04:07 2008
New Revision: 649882

URL: http://svn.apache.org/viewvc?rev=649882&view=rev
Log:
changes to scope cursors to get 100% coverage ...

 o turns out clover cannot handle conditional statements which also set a 
   variable like if ( available = cursor.previous() ) so this was broken 
   up in if statements and while loops
 o added addition test case for subtree scope cursor to gain 100% coverage


Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java?rev=649882&r1=649881&r2=649882&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java
Sat Apr 19 21:04:07 2008
@@ -159,13 +159,16 @@
             if ( evaluator.isDereferencing() )
             {
                 // advance until nothing is available or until we find a non-alias
-                while ( available = cursor.previous() )
+                do
                 {
-                    if ( db.getAliasIndex().reverseLookup( cursor.get().getId() ) == null
)
+                    available = cursor.previous();
+
+                    if ( available && db.getAliasIndex().reverseLookup( cursor.get().getId()
) == null )
                     {
                         break;
                     }
                 }
+                while ( available );
             }
             else
             {
@@ -181,19 +184,23 @@
          * scopeCursor and try a previous call after positioning past it's 
          * last element.
          */
-        if ( ! ( available = cursor.previous() ) )
+        available = cursor.previous();
+        if ( ! available )
         {
             cursor = scopeCursor;
             cursor.afterLast();
 
             // advance until nothing is available or until we find a non-alias
-            while ( available = cursor.previous() )
+            do
             {
-                if ( db.getAliasIndex().reverseLookup( cursor.get().getId() ) == null )
+                available = cursor.previous();
+
+                if ( available && db.getAliasIndex().reverseLookup( cursor.get().getId()
) == null )
                 {
                     break;
                 }
             }
+            while ( available );
 
             return available;
         }
@@ -217,13 +224,16 @@
         if ( evaluator.isDereferencing() )
         {
             // advance until nothing is available or until we find a non-alias
-            while ( available = cursor.next() )
+            do
             {
-                if ( db.getAliasIndex().reverseLookup( cursor.get().getId() ) == null )
+                available = cursor.next();
+
+                if ( available && db.getAliasIndex().reverseLookup( cursor.get().getId()
) == null )
                 {
                     break;
                 }
             }
+            while ( available );
         }
         else
         {

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeCursor.java?rev=649882&r1=649881&r2=649882&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeCursor.java
Sat Apr 19 21:04:07 2008
@@ -158,13 +158,15 @@
             if ( evaluator.isDereferencing() )
             {
                 // advance until nothing is available or until we find a non-alias
-                while ( available = cursor.previous() )
+                do
                 {
-                    if ( db.getAliasIndex().reverseLookup( cursor.get().getId() ) == null
)
+                    available = cursor.previous();
+                    if ( available && db.getAliasIndex().reverseLookup( cursor.get().getId()
) == null )
                     {
                         break;
                     }
                 }
+                while ( available );
             }
             else
             {
@@ -180,19 +182,23 @@
          * scopeCursor and try a previous call after positioning past it's
          * last element.
          */
-        if ( ! ( available = cursor.previous() ) )
+        available = cursor.previous();
+        if ( ! available )
         {
             cursor = scopeCursor;
             cursor.afterLast();
 
             // advance until nothing is available or until we find a non-alias
-            while ( available = cursor.previous() )
+            do
             {
-                if ( db.getAliasIndex().reverseLookup( cursor.get().getId() ) == null )
+                available = cursor.previous();
+
+                if ( available && db.getAliasIndex().reverseLookup( cursor.get().getId()
) == null )
                 {
                     break;
                 }
             }
+            while ( available );
 
             return available;
         }
@@ -216,13 +222,16 @@
         if ( evaluator.isDereferencing() )
         {
             // advance until nothing is available or until we find a non-alias
-            while ( available = cursor.next() )
+            do
             {
-                if ( db.getAliasIndex().reverseLookup( cursor.get().getId() ) == null )
+                available = cursor.next();
+
+                if ( available && db.getAliasIndex().reverseLookup( cursor.get().getId()
) == null )
                 {
                     break;
                 }
             }
+            while ( available );
         }
         else
         {

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java?rev=649882&r1=649881&r2=649882&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java
Sat Apr 19 21:04:07 2008
@@ -406,8 +406,101 @@
     }
 
 
+
+
     @Test
     public void testCursorWithDereferencing2() throws Exception
+    {
+        ScopeNode node = new ScopeNode( AliasDerefMode.DEREF_IN_SEARCHING,
+            SchemaConstants.OU_AT_OID + "=apache," +
+            SchemaConstants.OU_AT_OID + "=board of directors," +
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.SUBTREE_SCOPE );
+        SubtreeScopeEvaluator<Attributes> evaluator = new SubtreeScopeEvaluator<Attributes>(
store, node );
+        SubtreeScopeCursor cursor = new SubtreeScopeCursor( store, evaluator );
+
+        assertTrue( cursor.isElementReused() );
+
+
+        // --------- Test beforeFirst() ---------
+
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        IndexEntry<Long,Attributes> indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test first() ---------
+
+        cursor = new SubtreeScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.first();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test afterLast() ---------
+
+        cursor = new SubtreeScopeCursor( store, evaluator );
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test last() ---------
+
+        cursor = new SubtreeScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.last();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test previous() before positioning ---------
+
+        cursor = new SubtreeScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.previous();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+    }
+
+
+    @Test
+    public void testCursorWithDereferencing3() throws Exception
     {
         LdapDN dn = new LdapDN(
             SchemaConstants.CN_AT_OID + "=jd," +



Mime
View raw message