directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r636271 - in /directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store: ./ src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/
Date Wed, 12 Mar 2008 10:17:05 GMT
Author: akarasulu
Date: Wed Mar 12 03:16:56 2008
New Revision: 636271

URL: http://svn.apache.org/viewvc?rev=636271&view=rev
Log:
jdbm store cleanup ...

 o added BTreeRedirectMarshaller to quickly serialize deserialize BTreeRedirects
 o added test cases for BTreeRedirectMarshaller
 o added MarshallerSerializerBridge which adapts the JDBM Serializer interface
   to a Marshaller interface
 o added a DupsContainer class to encapsulate either BTreeRedirects or AvlTrees
   for clarity in handling these objects in JdbmTable
 o cleaned up JdbmTable which now compiles
 o cleaned up test cases which did not compile

NOTE:
 
   Tests still fail but the project compiles and we are ready to start getting
   some test coverage for JdbmTable which should be easily finished off now 
   along with the Cursor implementations for the Jdbm store.


Added:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshaller.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainer.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MarshallerSerializerBridge.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshallerTest.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/pom.xml
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirect.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/pom.xml?rev=636271&r1=636270&r2=636271&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/pom.xml (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/pom.xml Wed Mar 12 03:16:56 2008
@@ -63,6 +63,12 @@
 
     <dependency>
       <groupId>${pom.groupId}</groupId>
+      <artifactId>apacheds-core-avl</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
       <artifactId>apacheds-btree-base</artifactId>
       <version>${pom.version}</version>
     </dependency>

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirect.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/BTreeRedirect.java?rev=636271&r1=636270&r2=636271&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirect.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirect.java
Wed Mar 12 03:16:56 2008
@@ -32,21 +32,16 @@
 {
     private static final long serialVersionUID = -4289810071005184834L;
 
-    private Long recId;
-
-    
-    public BTreeRedirect()
-    {
-    }
+    final long recId;
 
     
     public BTreeRedirect( long recId )
     {
-        this.recId = new Long( recId );
+        this.recId = recId;
     }
     
     
-    public Long getRecId()
+    public long getRecId()
     {
         return recId;
     }

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshaller.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/BTreeRedirectMarshaller.java?rev=636271&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshaller.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshaller.java
Wed Mar 12 03:16:56 2008
@@ -0,0 +1,134 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
+
+
+import java.io.IOException;
+
+import org.apache.directory.server.core.avltree.Marshaller;
+import org.apache.directory.shared.asn1.codec.binary.Hex;
+
+
+/**
+ * Serializes and deserializes a BTreeRedirect object to and from a byte[]
+ * representation.  The serialized form is a fixed size byte array of length
+ * 16.  The first 8 bytes are the ascii values for the String 'redirect' and
+ * the last 8 bytes encode the record identifier as a long for the BTree.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */public class BTreeRedirectMarshaller implements Marshaller<BTreeRedirect>
+{
+    /** fixed byte array size of 16 for serialized form */
+    static final int SIZE = 16;
+    /** a reusable instance of this Marshaller */
+    public static final BTreeRedirectMarshaller INSTANCE = new BTreeRedirectMarshaller();
+
+    /**
+     * @see Marshaller#serialize(Object)
+     */
+    public final byte[] serialize( BTreeRedirect redirect ) throws IOException
+    {
+        byte[] bites = new byte[SIZE];
+
+        bites[0] = 'r';
+        bites[1] = 'e';
+        bites[2] = 'd';
+        bites[3] = 'i';
+        bites[4] = 'r';
+        bites[5] = 'e';
+        bites[6] = 'c';
+        bites[7] = 't';
+
+        bites[8] =  ( byte ) ( redirect.recId >> 56 );
+        bites[9] =  ( byte ) ( redirect.recId >> 48 );
+        bites[10] = ( byte ) ( redirect.recId >> 40 );
+        bites[11] = ( byte ) ( redirect.recId >> 32 );
+        bites[12] = ( byte ) ( redirect.recId >> 24 );
+        bites[13] = ( byte ) ( redirect.recId >> 16 );
+        bites[14] = ( byte ) ( redirect.recId >> 8 );
+        bites[15] = ( byte ) redirect.recId;
+
+        return bites;
+    }
+
+
+    /**
+     * @see Marshaller#deserialize(byte[]) 
+     */
+    public final BTreeRedirect deserialize( byte[] bites ) throws IOException
+    {
+        if ( bites.length != SIZE ||
+                  bites[0] != 'r' ||
+                  bites[1] != 'e' ||
+                  bites[2] != 'd' ||
+                  bites[3] != 'i' ||
+                  bites[4] != 'r' ||
+                  bites[5] != 'e' ||
+                  bites[6] != 'c' ||
+                  bites[7] != 't' )
+        {
+            throw new IOException( "Not a serialized BTreeRedirect object: "
+                    + new String( Hex.encodeHex( bites ) ) );
+        }
+
+        long recId;
+        recId = bites[8] + ( ( bites[8] < 0 ) ? 256 : 0 );
+        recId <<= 8;
+        recId += bites[9] + ( ( bites[9] < 0 ) ? 256 : 0 );
+        recId <<= 8;
+        recId += bites[10] + ( ( bites[10] < 0 ) ? 256 : 0 );
+        recId <<= 8;
+        recId += bites[11] + ( ( bites[11] < 0 ) ? 256 : 0 );
+        recId <<= 8;
+        recId += bites[12] + ( ( bites[12] < 0 ) ? 256 : 0 );
+        recId <<= 8;
+        recId += bites[13] + ( ( bites[13] < 0 ) ? 256 : 0 );
+        recId <<= 8;
+        recId += bites[14] + ( ( bites[14] < 0 ) ? 256 : 0 );
+        recId <<= 8;
+        recId += bites[15] + ( ( bites[15] < 0 ) ? 256 : 0 );
+
+        return new BTreeRedirect( recId );
+    }
+
+
+    /**
+     * Checks to see if a byte[] does not contain a redirect.  It's faster
+     * to check invalid bytes then to check for validity.
+     *
+     * @param bites the bites to check for validity
+     * @return true if the bites do not contain a serialized BTreeRedirect,
+     * false if they do
+     */
+    public static boolean isNotRedirect( byte[] bites )
+    {
+        // faster to check if invalid than valid
+        return bites.length != SIZE ||
+                bites[0] != 'r' ||
+                bites[1] != 'e' ||
+                bites[2] != 'd' ||
+                bites[3] != 'i' ||
+                bites[4] != 'r' ||
+                bites[5] != 'e' ||
+                bites[6] != 'c' ||
+                bites[7] != 't';
+    }
+}

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainer.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/DupsContainer.java?rev=636271&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainer.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainer.java
Wed Mar 12 03:16:56 2008
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
+
+
+import org.apache.directory.server.core.avltree.AvlTree;
+
+
+/**
+ * A wrapper around duplicate key values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DupsContainer<V>
+{
+    private final AvlTree<V> avlTree;
+    private final BTreeRedirect btreeRedirect;
+
+
+    DupsContainer( AvlTree<V> avlTree )
+    {
+        this.avlTree = avlTree;
+        btreeRedirect = null;
+    }
+
+
+    DupsContainer( BTreeRedirect btreeRedirect )
+    {
+        avlTree = null;
+        this.btreeRedirect = btreeRedirect;
+    }
+
+
+    final boolean isBTreeRedirect()
+    {
+        return btreeRedirect != null;
+    }
+
+
+    final boolean isAvlTree()
+    {
+        return avlTree != null;
+    }
+
+
+    final AvlTree<V> getAvlTree()
+    {
+        return avlTree;
+    }
+
+
+    final BTreeRedirect getBTreeRedirect()
+    {
+        return btreeRedirect;
+    }
+}

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.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/JdbmTable.java?rev=636271&r1=636270&r2=636271&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
Wed Mar 12 03:16:56 2008
@@ -27,7 +27,6 @@
 
 import org.apache.directory.server.core.avltree.AvlTree;
 import org.apache.directory.server.core.avltree.AvlTreeMarshaller;
-import org.apache.directory.server.core.avltree.IntegerKeyMarshaller;
 import org.apache.directory.server.core.avltree.Marshaller;
 import org.apache.directory.server.core.cursor.Cursor;
 import org.apache.directory.server.core.partition.impl.btree.*;
@@ -73,6 +72,8 @@
     private Map<Long, BTree> duplicateBtrees = new HashMap<Long, BTree>();
     
     AvlTreeMarshaller<V> marshaller;
+
+
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R
     // ------------------------------------------------------------------------
@@ -112,7 +113,8 @@
         if( allowsDuplicates )
         {
             //TODO the IntegerKeyMarshaller should be replaced with the appropriate marshaller
for type V
-            marshaller = new AvlTreeMarshaller<V>( comparator.getValueComparator(),
valueSerializer );
+            marshaller = new AvlTreeMarshaller<V>( comparator.getValueComparator(),
+                    new MarshallerSerializerBridge<V>( valueSerializer ) );
             // the value serializer causes problems between BTree and AvlTree cause each
use it in a different way
             valueSerializer = null; // set this to null
         }
@@ -257,7 +259,7 @@
     {
         if ( !allowsDuplicates )
         {
-            if ( null == getRaw( key ) )
+            if ( null == getNoDups( key ) )
             {
                 return 0;
             }
@@ -267,7 +269,7 @@
             }
         }
 
-        Object values = getRaw( key );
+        DupsContainer values = getDups( key );
         
         if ( values == null )
         {
@@ -278,16 +280,16 @@
         // Handle the use of a AvlTree for storing duplicates
         // -------------------------------------------------------------------
 
-        if ( values instanceof AvlTree )
+        if ( values.isAvlTree() )
         {
-            return ( ( AvlTree ) values ).getSize();
+            return values.getAvlTree().getSize();
         }
 
         // -------------------------------------------------------------------
         // Handle the use of a BTree for storing duplicates
         // -------------------------------------------------------------------
 
-        return getBTree( ( BTreeRedirect ) values ).size();
+        return getBTree( values.getBTreeRedirect() ).size();
     }
 
 
@@ -309,25 +311,25 @@
     {
         if ( ! allowsDuplicates )
         {
-            return getRaw( key );
-        }
+            return getNoDups( key );
+        }                         
 
-        Object values = getRaw( key );
+        DupsContainer values = getDups( key );
         
         if ( values == null )
         {
             return null;
         }
         
-        if ( values instanceof AvlTree )
+        if ( values.isAvlTree() )
         {
             //noinspection unchecked
-            AvlTree<V> set = ( AvlTree<V> ) values;
+            AvlTree<V> set = values.getAvlTree();
             return set.getFirst().getKey();
         }
 
         // Handle values if they are stored in another BTree
-        BTree tree = getBTree( ( BTreeRedirect ) values );
+        BTree tree = getBTree( values.getBTreeRedirect() );
         
         if ( tree.size() == 0 )
         {
@@ -349,7 +351,7 @@
     {
         if ( !allowsDuplicates )
         {
-            Object rval = getRaw( key );
+            Object rval = getNoDups( key );
 
             // key does not exist so return nothing
             if ( null == rval )
@@ -391,16 +393,16 @@
             
         }
 
-        Object values = getRaw( key );
+        DupsContainer values = getDups( key );
         
         if ( values == null )
         {
             return false;
         }
         
-        if ( values instanceof AvlTree )
+        if ( values.isAvlTree() )
         {
-            AvlTree set = ( AvlTree ) values;
+            AvlTree set = values.getAvlTree();
             Object result;
     
             if ( isGreaterThan )
@@ -416,7 +418,7 @@
         }
         
         // last option is to try a btree with BTreeRedirects
-        BTree tree = getBTree( ( BTreeRedirect ) values );
+        BTree tree = getBTree( values.getBTreeRedirect() );
         return tree.size() != 0 && btreeHas( tree, val, isGreaterThan );
     }
     
@@ -514,23 +516,24 @@
     {
         if ( ! allowsDuplicates )
         {
-            Object obj = getRaw( key );
-            return null != obj && obj.equals( value );
+            V stored = getNoDups( key );
+            return null != stored && stored.equals( value );
         }
         
-        Object values = getRaw( key );
+        DupsContainer values = getDups( key );
         
         if ( values == null )
         {
             return false;
         }
         
-        if ( values instanceof AvlTree )
+        if ( values.isAvlTree() )
         {
-            return ( ( AvlTree ) values ).find( value ) != null;
+            //noinspection unchecked
+            return values.getAvlTree().find( value ) != null;
         }
         
-        return btreeHas( getBTree( ( BTreeRedirect ) values ), value );
+        return btreeHas( getBTree( values.getBTreeRedirect() ), value );
     }
     
 
@@ -539,7 +542,7 @@
      */
     public boolean has( K key ) throws IOException
     {
-        return getRaw( key ) != null;
+        return key != null && bt.find(key) != null;
     }
 
 
@@ -569,16 +572,16 @@
             return replaced;
         }
         
-        Object values = getRaw( key );
+        DupsContainer values = getDups( key );
         
         if ( values == null )
         {
-            values = new AvlTree<V>( comparator.getValueComparator() );
+            values = new DupsContainer( new AvlTree<V>( comparator.getValueComparator()
) );
         }
         
-        if ( values instanceof AvlTree )
+        if ( values.isAvlTree() )
         {
-            AvlTree<V> set = ( AvlTree ) values;
+            AvlTree<V> set = values.getAvlTree();
             
             V result = set.insert( value );
             
@@ -599,7 +602,8 @@
             {
                 replaced = ( V ) bt.insert( key, marshaller.serialize( set ), true );
             }
-            
+
+            // TODO this is a problem here since addSuccessful is not being set
             if ( addSuccessful )
             {
                 count++;
@@ -608,7 +612,7 @@
             return null;
         }
         
-        BTree tree = getBTree( ( BTreeRedirect ) values );
+        BTree tree = getBTree( values.getBTreeRedirect() );
         
         if ( insertDupIntoBTree( tree, value ) )
         {
@@ -626,7 +630,7 @@
     {
         if ( ! allowsDuplicates )
         {
-            V oldValue = getRaw( key );
+            V oldValue = getNoDups( key );
         
             // Remove the value only if it is the same as value.
             if ( oldValue != null && oldValue.equals( value ) )
@@ -639,16 +643,17 @@
             return null;
         }
 
-        Object values = getRaw( key );
+        DupsContainer values = getDups( key );
         
         if ( values == null )
         {
             return null;
         }
         
-        if ( values instanceof AvlTree )
+        if ( values.isAvlTree() )
         {
-            AvlTree set = ( AvlTree ) values;
+            //noinspection unchecked
+            AvlTree<V> set = values.getAvlTree();
 
             // If removal succeeds then remove if set is empty else replace it
             if ( set.remove( value ) != null )
@@ -670,7 +675,7 @@
 
         // TODO might be nice to add code here that reverts to a AvlTree
         // if the number of duplicates falls below the numDupLimit value
-        BTree tree = getBTree( ( BTreeRedirect ) values );
+        BTree tree = getBTree( values.getBTreeRedirect() );
         if ( removeDupFromBTree( tree, value ) )
         {
             if ( tree.size() == 0 )
@@ -707,7 +712,7 @@
         if ( returned instanceof byte[] )
         {
             //noinspection unchecked
-            AvlTree<V> set = ( AvlTree<V> ) marshaller.deserialize( ( byte[]
) returned );
+            AvlTree<V> set = marshaller.deserialize( ( byte[] ) returned );
             this.count -= set.getSize();
             return set.getFirst().getKey();
         }
@@ -774,17 +779,8 @@
     // ------------------------------------------------------------------------
 
 
-    /**
-     * Gets a Tuple value from the btree.
-     *
-     * @param key the key of the Tuple to get the value of 
-     * @return the raw value object from the btree
-     * @throws IOException if there are any problems accessing the btree.
-     */
-    private V getRaw( K key ) throws IOException
+    private V getNoDups( K key ) throws IOException
     {
-        V val;
-
         if ( null == key )
         {
             return null;
@@ -793,21 +789,37 @@
         if ( ! allowsDuplicates )
         {
             //noinspection unchecked
-            val = ( V ) bt.find( key );
+            return ( V ) bt.find( key );
         }
-        else
+
+        throw new IllegalStateException(
+                "This method should not be called when duplicates are enabled" );
+    }
+
+
+    private DupsContainer getDups( K key ) throws IOException
+    {
+        if ( null == key )
         {
-            //noinspection unchecked
-            val = ( V ) bt.find( key );
+            return null;
+        }
 
-            if( val != null && val instanceof byte[])
+        if ( allowsDuplicates )
+        {
+            byte[] serialized = ( byte[] ) bt.find( key );
+
+            if ( BTreeRedirectMarshaller.isNotRedirect( serialized ) )
             {
-                val = (V) marshaller.deserialize( ( byte[] ) val );
+                return new DupsContainer<V>( marshaller.deserialize( serialized ) );
+            }
+            else
+            {
+                return new DupsContainer<V>( BTreeRedirectMarshaller.INSTANCE.deserialize(
serialized ) );
             }
-            
         }
 
-        return val;
+        throw new IllegalStateException(
+                "This method should not be called when duplicates are enabled" );
     }
 
 
@@ -940,7 +952,7 @@
     }
     
 
-    private BTree convertToBTree( AvlTree set ) throws IOException
+    private BTree convertToBTree( AvlTree<V> set ) throws IOException
     {
         BTree tree = BTree.createInstance( recMan, comparator.getValueComparator() );
         List<V> keys = set.getKeys();

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MarshallerSerializerBridge.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/MarshallerSerializerBridge.java?rev=636271&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MarshallerSerializerBridge.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MarshallerSerializerBridge.java
Wed Mar 12 03:16:56 2008
@@ -0,0 +1,69 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
+
+
+import org.apache.directory.server.core.avltree.Marshaller;
+
+import java.io.IOException;
+
+import jdbm.helper.Serializer;
+
+
+/**
+ * A Marshaller which adapts a JDBM Serializer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class MarshallerSerializerBridge<E> implements Marshaller<E>
+{
+    /** the wrapped serializer */
+    private final Serializer serializer;
+
+
+    /**
+     *
+     * @param serializer the JDBM Serializer to wrap
+     */
+    public MarshallerSerializerBridge( Serializer serializer )
+    {
+        this.serializer = serializer;
+    }
+
+
+    /**
+     * @see Marshaller#serialize(Object)
+     */
+    public byte[] serialize( E object ) throws IOException
+    {
+        return serializer.serialize( object );
+    }
+
+
+    /**
+     * @see Marshaller#deserialize(byte[])
+     */
+    @SuppressWarnings({"unchecked"})
+    public E deserialize( byte[] bytes ) throws IOException
+    {
+        return ( E ) serializer.deserialize( bytes );
+    }
+}

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshallerTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshallerTest.java?rev=636271&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshallerTest.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshallerTest.java
Wed Mar 12 03:16:56 2008
@@ -0,0 +1,129 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
+
+
+import org.junit.Test;
+import org.junit.Before;
+import org.apache.directory.shared.ldap.util.ArrayUtils;
+
+import static junit.framework.Assert.*;
+
+import java.util.Random;
+import java.io.IOException;
+
+
+/**
+ * Test case for the BTreeRedirect serialization code.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BTreeRedirectMarshallerTest
+{
+    byte[] bites = new byte[BTreeRedirectMarshaller.SIZE];
+    BTreeRedirectMarshaller marshaller = new BTreeRedirectMarshaller();
+
+
+    @Before
+    public void setup()
+    {
+        bites[0] = 'r';
+        bites[1] = 'e';
+        bites[2] = 'd';
+        bites[3] = 'i';
+        bites[4] = 'r';
+        bites[5] = 'e';
+        bites[6] = 'c';
+        bites[7] = 't';
+
+        for ( int ii = 8; ii < BTreeRedirectMarshaller.SIZE; ii++ )
+        {
+            bites[ii] = 0;
+        }
+    }
+
+
+    @Test
+    public void testZero() throws IOException
+    {
+        assertEquals( 0, marshaller.deserialize( bites ).getRecId() );
+        assertTrue( ArrayUtils.isEquals( bites, marshaller.serialize( new BTreeRedirect(
0 ) ) ) );
+    }
+
+
+    @Test
+    public void testOne() throws IOException
+    {
+        bites[15] = 1;
+        assertEquals( 1, marshaller.deserialize( bites ).getRecId() );
+        assertTrue( ArrayUtils.isEquals( bites, marshaller.serialize( new BTreeRedirect(
1 ) ) ) );
+    }
+
+
+    @Test
+    public void testNegativeOne() throws IOException
+    {
+        for ( int ii = 8; ii < BTreeRedirectMarshaller.SIZE; ii++ )
+        {
+            bites[ii] =  ( byte ) 0xFF;
+        }
+
+        assertEquals( -1, marshaller.deserialize( bites ).getRecId() );
+        assertTrue( ArrayUtils.isEquals( bites, marshaller.serialize( new BTreeRedirect(
-1 ) ) ) );
+    }
+
+
+    @Test
+    public void testLongMinValue() throws IOException
+    {
+        bites[8] = ( byte ) 0x80;
+        assertEquals( Long.MIN_VALUE, marshaller.deserialize( bites ).getRecId() );
+        assertTrue( ArrayUtils.isEquals( bites, marshaller.serialize( new BTreeRedirect(
Long.MIN_VALUE ) ) ) );
+    }
+
+
+    @Test
+    public void testLongMaxValue() throws IOException
+    {
+        bites[8] = ( byte ) 0x7F;
+
+        for ( int ii = 9; ii < BTreeRedirectMarshaller.SIZE; ii++ )
+        {
+            bites[ii] =  ( byte ) 0xFF;
+        }
+
+        assertEquals( Long.MAX_VALUE, marshaller.deserialize( bites ).getRecId() );
+        assertTrue( ArrayUtils.isEquals( bites, marshaller.serialize( new BTreeRedirect(
Long.MAX_VALUE ) ) ) );
+    }
+
+
+    @Test
+    public void testRoundTripTests() throws IOException
+    {
+        Random random = new Random();
+        for ( int ii = 0; ii < 100; ii++ )
+        {
+            long orig = random.nextLong();
+            bites = marshaller.serialize( new BTreeRedirect( orig ) );
+            assertEquals( orig, marshaller.deserialize( bites ).getRecId() );
+        }
+    }
+}

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java?rev=636271&r1=636270&r2=636271&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
Wed Mar 12 03:16:56 2008
@@ -25,7 +25,6 @@
 import org.apache.directory.server.core.partition.impl.btree.Table;
 import org.apache.directory.server.core.partition.impl.btree.Tuple;
 import org.apache.directory.server.core.partition.impl.btree.TupleComparator;
-import org.apache.directory.server.core.avltree.IntegerKeyMarshaller;
 import org.apache.directory.server.core.cursor.Cursor;
 import org.apache.directory.server.schema.SerializableComparator;
 import org.apache.directory.server.schema.registries.ComparatorRegistry;
@@ -41,6 +40,7 @@
 import java.util.Iterator;
 
 import jdbm.RecordManager;
+import jdbm.helper.IntegerSerializer;
 import jdbm.recman.BaseRecordManager;
 
 import javax.naming.NamingException;
@@ -83,7 +83,7 @@
                 new DefaultTupleComparator<Integer,Integer>(
                         new SerializableComparator<Integer>( "" ),
                         new SerializableComparator<Integer>( "" ) );
-        table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator,
null, new IntegerKeyMarshaller() );
+        table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator,
null, new IntegerSerializer() );
         LOG.debug( "Created new table and populated it with data" );
     }
 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java?rev=636271&r1=636270&r2=636271&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
Wed Mar 12 03:16:56 2008
@@ -26,7 +26,6 @@
 import org.junit.Test;
 import static org.junit.Assert.*;
 
-import org.apache.directory.server.core.avltree.IntegerKeyMarshaller;
 import org.apache.directory.server.core.partition.impl.btree.Table;
 import org.apache.directory.server.core.partition.impl.btree.TupleComparator;
 import org.apache.directory.server.core.partition.impl.btree.DefaultTupleComparator;
@@ -40,6 +39,7 @@
 import java.util.Iterator;
 
 import jdbm.RecordManager;
+import jdbm.helper.IntegerSerializer;
 import jdbm.recman.BaseRecordManager;
 
 import javax.naming.NamingException;
@@ -81,7 +81,7 @@
                 new DefaultTupleComparator<Integer,Integer>(
                         new SerializableComparator<Integer>( "" ),
                         new SerializableComparator<Integer>( "" ) );
-        table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator,
null, new IntegerKeyMarshaller() );
+        table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator,
null, new IntegerSerializer() );
         LOG.debug( "Created new table and populated it with data" );
     }
 
@@ -107,7 +107,7 @@
             new DefaultTupleComparator<Integer,Integer>(
                     new SerializableComparator<Integer>( "" ),
                     new SerializableComparator<Integer>( "" ) );
-        table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator,
null, new IntegerKeyMarshaller() );
+        table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator,
null, new IntegerSerializer() );
         assertTrue( 2 == table.get( 1 ) );
     }
 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java?rev=636271&r1=636270&r2=636271&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
Wed Mar 12 03:16:56 2008
@@ -62,6 +62,7 @@
     KeyCursor<String> cursor;
 
 
+    @SuppressWarnings({"unchecked"})
     @Before
     public void createCursor() throws Exception
     {



Mime
View raw message