directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r617021 - in /directory/sandbox/akarasulu/bigbang/apacheds: btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ jdbm-store/src/...
Date Thu, 31 Jan 2008 06:45:45 GMT
Author: akarasulu
Date: Wed Jan 30 22:45:36 2008
New Revision: 617021

URL: http://svn.apache.org/viewvc?rev=617021&view=rev
Log:
checkpointing work where I got stuck realizing that we need something more than a TreeSet

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
  (with props)
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/resources/log4j.properties
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Tuple.java
    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/JdbmDupsCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Tuple.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Tuple.java?rev=617021&r1=617020&r2=617021&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Tuple.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Tuple.java
Wed Jan 30 22:45:36 2008
@@ -119,4 +119,16 @@
         this.value = value;
         return this;
     }
+    
+    
+    public String toString()
+    {
+        StringBuilder buf = new StringBuilder();
+        buf.append( "Tuple( '" );
+        buf.append( key );
+        buf.append(  " )', '" );
+        buf.append( value );
+        buf.append( "' )" );
+        return buf.toString();
+    }
 }

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=617021&r1=617020&r2=617021&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 Jan 30 22:45:36 2008
@@ -50,4 +50,14 @@
     {
         return recId;
     }
+    
+    
+    public String toString()
+    {
+        StringBuilder buf = new StringBuilder();
+        buf.append( "BTreeRedirect[" );
+        buf.append( recId );
+        buf.append( "]" );
+        return buf.toString();
+    }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.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/JdbmDupsCursor.java?rev=617021&r1=617020&r2=617021&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java
Wed Jan 30 22:45:36 2008
@@ -8,6 +8,8 @@
 import org.apache.directory.server.core.cursor.AbstractCursor;
 import org.apache.directory.server.core.partition.impl.btree.Tuple;
 import org.apache.directory.shared.ldap.NotImplementedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.*;
 
@@ -17,6 +19,8 @@
  */
 public class JdbmDupsCursor<K,V> extends AbstractCursor<Tuple<K,V>>
 {
+    private static final Logger LOG = LoggerFactory.getLogger( JdbmDupsCursor.class.getSimpleName()
);
+    
     /**
      * The JDBM backed table this Cursor traverses over.
      */
@@ -28,7 +32,7 @@
      * positions it may return different values for the same key if the table
      * supports duplicate keys.
      */
-    private final Tuple<K,V> tuple = new Tuple<K,V>();
+    private final Tuple<K,V> dupsTuple = new Tuple<K,V>();
 
     /**
      * The underlying Cursor which is simply returns Tuples with key value
@@ -80,13 +84,41 @@
     }
 
 
-    public void before( Tuple element ) throws Exception
+    /**
+     * Advances this Cursor just before the record with key and value equal to 
+     * those provided in the Tuple argument.  If the key is not present the 
+     * Cursor advances to just before the greatest value of the key less than 
+     * but not greater than the one provided by the Tuple argument.  If the 
+     * key is present but the value is not present the Cursor advances to the 
+     * element with the same key containing a value less than but not greater
+     * than the value in the Tuple.
+     */
+    public void before( Tuple<K,V> element ) throws Exception
     {
-        throw new NotImplementedException();
+        noDupsCursor.before( element );
+        
+        if ( noDupsCursor.next() )
+        {
+            noDupsTuple = noDupsCursor.get();
+            
+            if ( noDupsTuple.getValue() instanceof TreeSet )
+            {
+                LOG.debug( "Duplicates tuple {} stored in a TreeSet", noDupsTuple );
+                TreeSet<V> set = ( TreeSet<V> ) noDupsTuple.getValue();
+            }
+            else 
+            {
+                LOG.debug( "Duplicates tuple {} are stored in a BTree", noDupsTuple );
+                BTreeRedirect redirect = ( BTreeRedirect ) noDupsTuple.getValue();
+                
+                
+            }
+        }
+//        throw new NotImplementedException();
     }
 
 
-    public void after(Tuple element) throws Exception
+    public void after( Tuple<K,V> element ) throws Exception
     {
         throw new NotImplementedException();
     }
@@ -112,8 +144,8 @@
 
     private void clearValue()
     {
-        tuple.setKey( null );
-        tuple.setValue( null );
+        dupsTuple.setKey( null );
+        dupsTuple.setValue( null );
         valueAvailable = false;
     }
 
@@ -128,7 +160,7 @@
             if ( values instanceof TreeSet)
             {
                 //noinspection unchecked
-                TreeSet<V> set = ( TreeSet ) noDupsTuple.getValue();
+                TreeSet<V> set = ( TreeSet<V> ) noDupsTuple.getValue();
                 List<V> list = new ArrayList<V>( set.size() );
                 list.addAll( set );
                 dupCursor = new ListCursor<V>( list );
@@ -142,7 +174,7 @@
             {
                 BTree tree = table.getBTree( ( BTreeRedirect ) values );
                 //noinspection unchecked
-                dupCursor = new KeyCursor( tree, table.getComparator().getKeyComparator()
);
+                dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getComparator().getKeyComparator()
);
                 if ( ! dupCursor.previous() )
                 {
                     clearValue();
@@ -157,8 +189,8 @@
              * need to do is populate our tuple object with the key and the value
              * in the cursor.
              */
-            tuple.setKey( noDupsTuple.getKey() );
-            tuple.setValue( dupCursor.get() );
+            dupsTuple.setKey( noDupsTuple.getKey() );
+            dupsTuple.setValue( dupCursor.get() );
             return valueAvailable = true;
         }
 
@@ -198,7 +230,7 @@
                 {
                     BTree tree = table.getBTree( ( BTreeRedirect ) values );
                     //noinspection unchecked
-                    dupCursor = new KeyCursor( tree, table.getComparator().getKeyComparator()
);
+                    dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getComparator().getKeyComparator()
);
                     dupCursor.previous();
                 }
             }
@@ -215,8 +247,8 @@
          * need to do is populate our tuple object with the key and the value
          * in the cursor.
          */
-        tuple.setKey( noDupsTuple.getKey() );
-        tuple.setValue( dupCursor.get() );
+        dupsTuple.setKey( noDupsTuple.getKey() );
+        dupsTuple.setValue( dupCursor.get() );
         return valueAvailable = true;
     }
 
@@ -241,7 +273,7 @@
                 if ( values instanceof TreeSet)
                 {
                     //noinspection unchecked
-                    TreeSet<V> set = ( TreeSet ) noDupsTuple.getValue();
+                    TreeSet<V> set = ( TreeSet<V> ) noDupsTuple.getValue();
                     List<V> list = new ArrayList<V>( set.size() );
                     list.addAll( set );
                     dupCursor = new ListCursor<V>( list );
@@ -251,7 +283,7 @@
                 {
                     BTree tree = table.getBTree( ( BTreeRedirect ) values );
                     //noinspection unchecked
-                    dupCursor = new KeyCursor( tree, table.getComparator().getKeyComparator()
);
+                    dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getComparator().getKeyComparator()
);
                     dupCursor.next();
                 }
             }
@@ -268,8 +300,8 @@
          * need to do is populate our tuple object with the key and the value
          * in the cursor.
          */
-        tuple.setKey( noDupsTuple.getKey() );
-        tuple.setValue( dupCursor.get() );
+        dupsTuple.setKey( noDupsTuple.getKey() );
+        dupsTuple.setValue( dupCursor.get() );
         return valueAvailable = true;
     }
 
@@ -283,7 +315,7 @@
             throw new InvalidCursorPositionException();
         }
 
-        return tuple;
+        return dupsTuple;
     }
 
 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.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/JdbmNoDupsCursor.java?rev=617021&r1=617020&r2=617021&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java
Wed Jan 30 22:45:36 2008
@@ -39,7 +39,7 @@
  */
 public class JdbmNoDupsCursor<K,V> extends AbstractCursor<Tuple<K,V>>
 {
-    private final JdbmTable table;
+    private final JdbmTable<K,V> table;
 
     private jdbm.helper.Tuple jdbmTuple = new jdbm.helper.Tuple();
     private Tuple<K,V> returnedTuple = new Tuple<K,V>();
@@ -53,7 +53,7 @@
      * @param table the JDBM Table to build a Cursor over
      * @throws IOException of there are problems accessing the BTree
      */
-    public JdbmNoDupsCursor( JdbmTable table ) throws IOException
+    public JdbmNoDupsCursor( JdbmTable<K,V> table ) throws IOException
     {
         this.table = table;
     }
@@ -81,14 +81,14 @@
      * @param element the tuple who's key is used to position this Cursor
      * @throws IOException if there are failures to position the Cursor
      */
-    public void before( Tuple element ) throws IOException
+    public void before( Tuple<K,V> element ) throws IOException
     {
         browser = table.getBTree().browse( element.getKey() );
         clearValue();
     }
 
 
-    public void after( Tuple element ) throws IOException
+    public void after( Tuple<K,V> element ) throws IOException
     {
         browser = table.getBTree().browse( element.getKey() );
 
@@ -101,7 +101,7 @@
          */
         while ( browser.getNext( jdbmTuple ) )
         {
-            Object next = jdbmTuple.getKey();
+            K next = ( K ) jdbmTuple.getKey();
 
             //noinspection unchecked
             int nextCompared = table.getComparator().getKeyComparator().compare( next, element.getKey()
);

Added: 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=617021&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
Wed Jan 30 22:45:36 2008
@@ -0,0 +1,215 @@
+/*
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.directory.server.core.partition.impl.btree.DefaultTupleComparator;
+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.cursor.Cursor;
+import org.apache.directory.server.schema.SerializableComparator;
+import org.apache.directory.server.schema.registries.ComparatorRegistry;
+import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;import static org.junit.Assert.assertFalse;
+
+import java.io.File;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import jdbm.RecordManager;
+import jdbm.recman.BaseRecordManager;
+
+import javax.naming.NamingException;
+
+
+/**
+ * Tests the Cursor functionality of a JdbmTable when duplicate keys are 
+ * supported.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class JdbmDupsCursorTest
+{
+    private static final Logger LOG = LoggerFactory.getLogger( JdbmDupsCursorTest.class.getSimpleName()
);
+    private static final String TEST_OUTPUT_PATH = "test.output.path";
+    private static final int SIZE = 15;
+
+    transient Table<Integer,Integer> table;
+    transient File dbFile;
+    transient RecordManager recman;
+
+
+    @Before
+    public void createTable() throws Exception
+    {
+        File tmpDir = null;
+        if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
+        {
+            tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
+        }
+
+        dbFile = File.createTempFile( getClass().getSimpleName(), "db", tmpDir );
+        recman = new BaseRecordManager( dbFile.getAbsolutePath() );
+
+        // gosh this is a terrible use of a global static variable
+        SerializableComparator.setRegistry( new MockComparatorRegistry() );
+
+        TupleComparator<Integer,Integer> comparator = 
+                new DefaultTupleComparator<Integer,Integer>(
+                        new SerializableComparator<Integer>( "" ),
+                        new SerializableComparator<Integer>( "" ) );
+        table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator,
null, null );
+        LOG.debug( "Created new table and populated it with data" );
+    }
+
+
+    @After
+    public void destryTable() throws Exception
+    {
+        table.close();
+        table = null;
+        recman.close();
+        recman = null;
+        dbFile.deleteOnExit();
+        dbFile = null;
+    }
+
+
+    @Test
+    public void testOnEmptyTable() throws Exception
+    {
+        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+        assertNotNull( cursor );
+        assertFalse( cursor.isClosed() );
+        
+        cursor.before( new Tuple<Integer, Integer>( 1, 2 ) );
+        assertFalse( cursor.available() );
+    }
+
+    
+    @Test
+    public void testOverDupLimit() throws Exception
+    {
+        table.put( 5, 5 );
+        table.put( 6, 6 );
+        for ( int ii = 0; ii < 20; ii++ )
+        {
+            table.put( 7, ii );
+        }
+        table.put( 8, 8 );
+        table.put( 9, 9 );
+        
+        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+        assertNotNull( cursor );
+        assertFalse( cursor.isClosed() );
+        
+        cursor.before( new Tuple<Integer, Integer>( 7, 2 ) );
+        assertFalse( cursor.available() );
+    }
+
+    
+    @Test
+    public void testUnderDupLimit() throws Exception
+    {
+        table.put( 5, 5 );
+        table.put( 6, 6 );
+        for ( int ii = 0; ii < 10; ii++ )
+        {
+            table.put( 7, ii );
+        }
+        table.put( 8, 8 );
+        table.put( 9, 9 );
+        
+        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+        assertNotNull( cursor );
+        assertFalse( cursor.isClosed() );
+        
+        cursor.before( new Tuple<Integer, Integer>( 7, 2 ) );
+        assertFalse( cursor.available() );
+    }
+
+    
+    private class MockComparatorRegistry implements ComparatorRegistry
+    {
+        private Comparator<Integer> comparator = new Comparator<Integer>()
+        {
+            public int compare( Integer i1, Integer i2 )
+            {
+                return i1.compareTo( i2 );
+            }
+        };
+
+        public String getSchemaName( String oid ) throws NamingException
+        {
+            return null;
+        }
+
+
+        public void register( ComparatorDescription description, Comparator comparator )
throws NamingException
+        {
+        }
+
+
+        public Comparator lookup( String oid ) throws NamingException
+        {
+            return comparator;
+        }
+
+
+        public boolean hasComparator( String oid )
+        {
+            return true;
+        }
+
+
+        public Iterator<String> oidIterator()
+        {
+            return null;
+        }
+
+
+        public Iterator<ComparatorDescription> comparatorDescriptionIterator()
+        {
+            return null;
+        }
+
+
+        public void unregister( String oid ) throws NamingException
+        {
+        }
+
+
+        public void unregisterSchemaElements( String schemaName )
+        {
+        }
+
+
+        public void renameSchema( String originalSchemaName, String newSchemaName )
+        {
+        }
+    }
+}

Propchange: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
------------------------------------------------------------------------------
    svn:executable = *

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=617021&r1=617020&r2=617021&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 Jan 30 22:45:36 2008
@@ -61,7 +61,7 @@
     transient RecordManager recman;
 
     
-    @Before
+    @Before 
     public void createTable() throws Exception
     {
         File tmpDir = null;

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/resources/log4j.properties?rev=617021&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/resources/log4j.properties
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/resources/log4j.properties
Wed Jan 30 22:45:36 2008
@@ -0,0 +1,22 @@
+#############################################################################
+#    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.
+#############################################################################
+log4j.rootCategory=ERROR, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+



Mime
View raw message