directory-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=637345&view=rev
Log:
fixed bug in marshalling which does not preserve the last node reference when only one element
is in the tree

Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMarshaller.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/AvlTreeMarshaller.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMarshaller.java?rev=637345&r1=637344&r2=637345&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMarshaller.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMarshaller.java
Fri Mar 14 20:23:14 2008
@@ -116,6 +116,7 @@
         return data;
     }
 
+    
     /**
      * writes the content of the AVLTree to an output stream.
      * The current format is 
@@ -198,7 +199,7 @@
             
             tree.setFirst( nodes[0] );
             
-            if( nodes.length > 1 )
+            if( nodes.length >= 1 )
             {
                 tree.setLast( nodes[ nodes.length - 1 ] );
             }

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=637345&r1=637344&r2=637345&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:23:14 2008
@@ -99,8 +99,7 @@
 
 
     @Test
-    @Ignore( "marshaller fails to preserve last node reference" )
-    public void testFirstLast() throws IOException
+    public void testRoundTripOneEntryFirstLast() throws IOException
     {
         AvlTree<Integer> original = new AvlTree<Integer>( comparator );
         original.insert( 0 );
@@ -141,6 +140,34 @@
 
 
     @Test
+    public void testRoundTripTwoEntriesFirstLast() throws IOException
+    {
+        AvlTree<Integer> original = new AvlTree<Integer>( comparator );
+        original.insert( 0 );
+        original.insert( 1 );
+        byte[] bites = treeMarshaller.serialize( original );
+        AvlTree<Integer> deserialized = treeMarshaller.deserialize( bites );
+        assertFalse( deserialized.isEmpty() );
+        assertEquals( 2, deserialized.getSize() );
+        assertEquals( 0, ( int ) deserialized.getFirst().getKey() );
+        assertEquals( 1, ( int ) deserialized.getFirst().next.getKey() );
+
+        assertNotNull( original.getFirst() );
+        assertEquals( 0, ( int ) original.getFirst().getKey() );
+
+        assertNotNull( deserialized.getFirst() );
+        assertEquals( 0, ( int ) deserialized.getFirst().getKey() );
+
+        assertNotNull( original.getLast() );
+        assertEquals( 1, ( int ) original.getLast().getKey() );
+
+        // this marshaller fails to preserve last node reference
+        assertNotNull( deserialized.getLast() );
+        assertEquals( 1, ( int ) deserialized.getLast().getKey() );
+    }
+
+
+    @Test
     public void testRoundTripManyEntries() throws Exception
     {
         AvlTree<Integer> original = new AvlTree<Integer>( comparator );
@@ -160,6 +187,42 @@
             assertEquals( ii, ( int ) cursor.get() );
             cursor.next();
         }
+    }
+
+
+    @Test
+    public void testRoundTripManyEntriesFirstLast() throws Exception
+    {
+        AvlTree<Integer> original = new AvlTree<Integer>( comparator );
+        for ( int ii = 0; ii < 100; ii++ )
+        {
+            original.insert( ii );
+        }
+        byte[] bites = treeMarshaller.serialize( original );
+        AvlTree<Integer> deserialized = treeMarshaller.deserialize( bites );
+        assertFalse( deserialized.isEmpty() );
+        assertEquals( 100, deserialized.getSize() );
+
+        AvlTreeCursor<Integer> cursor = new AvlTreeCursor<Integer>( deserialized
);
+        cursor.first();
+        for ( int ii = 0; ii < 100; ii++ )
+        {
+            assertEquals( ii, ( int ) cursor.get() );
+            cursor.next();
+        }
+
+        assertNotNull( original.getFirst() );
+        assertEquals( 0, ( int ) original.getFirst().getKey() );
+
+        assertNotNull( deserialized.getFirst() );
+        assertEquals( 0, ( int ) deserialized.getFirst().getKey() );
+
+        assertNotNull( original.getLast() );
+        assertEquals( 99, ( int ) original.getLast().getKey() );
+
+        // this marshaller fails to preserve last node reference
+        assertNotNull( deserialized.getLast() );
+        assertEquals( 99, ( int ) deserialized.getLast().getKey() );
     }
 
 



Mime
View raw message