directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r637342 - in /directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src: main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java
Date Sat, 15 Mar 2008 03:10:42 GMT
Author: akarasulu
Date: Fri Mar 14 20:10:41 2008
New Revision: 637342

URL: http://svn.apache.org/viewvc?rev=637342&view=rev
Log:
fixing some issues with cursor and found new bug in marshalling which does not preserve the
last node reference

Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.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=637342&r1=637341&r2=637342&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 Mar 14 20:10:41 2008
@@ -156,10 +156,10 @@
         
         if ( isBeforeFirst )
         {
-            onNode = true;
+            node = tree.getFirst();
             isBeforeFirst = false;
             isAfterLast = false;
-            return true;
+            return onNode = node != null;
         }
 
         if ( isAfterLast )
@@ -168,6 +168,12 @@
         }
         else if ( onNode )
         {
+            if ( node == null )
+            {
+                node = tree.getFirst();
+                return true;
+            }
+            
             if ( node.next == null )
             {
                 onNode = false;
@@ -180,32 +186,34 @@
             return true;
         }
 
-        if ( node != null )
-        {
-            return onNode = true;
-        }
-        
-        return false;
+        return node != null && ( onNode = true );
     }
 
 
     public boolean previous() throws Exception
     {
         checkClosed( "previous" );
+
+        if ( isBeforeFirst )
+        {
+            return false;
+        }
+
         if ( isAfterLast )
         {
-            onNode = true;
+            node = tree.getLast();
             isBeforeFirst = false;
             isAfterLast = false;
-            return true;
-        }
-        
-        if ( isBeforeFirst )
-        {
-            return false;
+            return onNode = node != null;
         }
-        else if ( onNode )
+
+        if ( onNode )
         {
+            if ( node == null )
+            {
+                node = tree.getLast();
+                return true;
+            }
             if ( node.previous == null )
             {
                 onNode = false;

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java?rev=637342&r1=637341&r2=637342&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java
Fri Mar 14 20:10:41 2008
@@ -30,6 +30,7 @@
 
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.Ignore;
 
 
 /**
@@ -94,6 +95,33 @@
         assertFalse( deserialized.isEmpty() );
         assertEquals( 1, deserialized.getSize() );
         assertEquals( 0, ( int ) deserialized.getFirst().getKey() );
+    }
+
+
+    @Test
+    @Ignore( "marshaller fails to preserve last node reference" )
+    public void testFirstLast() throws IOException
+    {
+        AvlTree<Integer> original = new AvlTree<Integer>( comparator );
+        original.insert( 0 );
+        byte[] bites = treeMarshaller.serialize( original );
+        AvlTree<Integer> deserialized = treeMarshaller.deserialize( bites );
+        assertFalse( deserialized.isEmpty() );
+        assertEquals( 1, deserialized.getSize() );
+        assertEquals( 0, ( int ) deserialized.getFirst().getKey() );
+
+        assertNotNull( original.getFirst() );
+        assertEquals( 0, ( int ) original.getFirst().getKey() );
+
+        assertNotNull( deserialized.getFirst() );
+        assertEquals( 0, ( int ) deserialized.getFirst().getKey() );
+
+        assertNotNull( original.getLast() );
+        assertEquals( 0, ( int ) original.getLast().getKey() );
+
+        // this marshaller fails to preserve last node reference
+        assertNotNull( deserialized.getLast() );
+        assertEquals( 0, ( int ) deserialized.getLast().getKey() );
     }
 
 



Mime
View raw message