You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/08/05 19:55:16 UTC

svn commit: r801340 [12/13] - in /directory/apacheds/trunk: core-entry/src/main/java/org/apache/directory/server/core/entry/ core-entry/src/test/java/org/apache/directory/server/core/entry/ core-integ/src/main/java/org/apache/directory/server/core/inte...

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java?rev=801340&r1=801339&r2=801340&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java Wed Aug  5 17:55:15 2009
@@ -1,399 +1,399 @@
-/*
- * 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.junit.Before;
-import org.junit.After;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-import org.apache.directory.server.xdbm.Table;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.registries.ComparatorRegistry;
-import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescription;
-
-import java.io.File;
-import java.util.Comparator;
-import java.util.Iterator;
-
-import jdbm.RecordManager;
-import jdbm.recman.BaseRecordManager;
-
-import javax.naming.NamingException;
-
-
-/**
- * Document me!
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class JdbmTableNoDuplicatesTest
-{
-    private static final Logger LOG = LoggerFactory.getLogger( JdbmTableNoDuplicatesTest.class.getSimpleName() );
-    private static final String TEST_OUTPUT_PATH = "test.output.path";
-
-    transient Table<Integer,Integer> table;
-    transient File dbFile;
-    transient RecordManager recman;
-
-
-    @Before
-    public void createTable() throws Exception
-    {
-        destryTable();
-        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() );
-        table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>( "" ), null, null );
-        LOG.debug( "Created new table and populated it with data" );
-    }
-
-
-    @After
-    public void destryTable() throws Exception
-    {
-        if ( table != null )
-        {
-            table.close();
-        }
-
-        table = null;
-
-        if ( recman != null )
-        {
-            recman.close();
-        }
-
-        recman = null;
-
-        if ( dbFile != null )
-        {
-            String fileToDelete = dbFile.getAbsolutePath();
-            new File( fileToDelete + ".db" ).delete();
-            new File( fileToDelete + ".lg" ).delete();
-
-            dbFile.delete();
-        }
-        
-        dbFile = null;
-    }
-    
-
-    @Test
-    public void testCloseReopen() throws Exception
-    {
-        table.put( 1, 2 );
-        table.close();
-        table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>( "" ), null, null );
-        assertTrue( 2 == table.get( 1 ) );
-    }
-
-    
-    @Test 
-    public void testConfigMethods() throws Exception
-    {
-        assertFalse( table.isDupsEnabled() );
-        assertEquals( "test", table.getName() );
-        assertNotNull( table.getKeyComparator() );
-    }
-
-    
-    @Test
-    public void testWhenEmpty() throws Exception
-    {
-        // Test the count methods
-        assertEquals( 0, table.count() );
-        assertEquals( 0, table.count( 1 ) );
-
-        // Test get method
-        assertNull( table.get( 0 ) );
-        
-        // Test remove methods
-        table.remove( 1 );
-        assertNull( table.get( 1 ) );
-        
-        // Test has operations
-        assertFalse( table.has( 1 ) );
-        assertFalse( table.has( 1, 0 ) );
-        assertFalse( table.hasGreaterOrEqual( 1 ) );
-        assertFalse( table.hasLessOrEqual( 1 ) );
-
-        try
-        {
-            assertFalse( table.hasGreaterOrEqual( 1, 0 ) );
-            fail( "Should never get here." );
-        }
-        catch ( UnsupportedOperationException e )
-        {
-        }
-
-        try
-        {
-            assertFalse( table.hasLessOrEqual( 1, 0 ) );
-            fail( "Should never get here." );
-        }
-        catch ( UnsupportedOperationException e )
-        {
-        }
-    }
-
-    
-    @Test
-    public void testLoadData() throws Exception
-    {
-        // add some data to it
-        for ( int ii = 0; ii < 10; ii++ )
-        {
-            table.put( ii, ii );
-        }
-        
-        assertEquals( 10, table.count() );
-        assertEquals( 1, table.count( 0 ) );
-        
-        /*
-         * If counts are exact then we can test for exact values.  Again this 
-         * is not a critical function but one used for optimization so worst 
-         * case guesses are allowed.
-         */
-        
-        if ( table.isCountExact() )
-        {
-            assertEquals( 5, table.lessThanCount( 5 ) );
-            assertEquals( 4, table.greaterThanCount( 5 ) );
-        }
-        else
-        {
-            assertEquals( 10, table.lessThanCount( 5 ) );
-            assertEquals( 10, table.greaterThanCount( 5 ) );
-        }
-    }
-    
-    
-    /**
-     * Let's test keys with a null or lack of any values.
-     * @throws Exception on error
-     */
-    @Test
-    public void testNullOrEmptyKeyValue() throws Exception
-    {
-        assertEquals( 0, table.count() );
-        
-        try
-        {
-            table.put( 1, null );
-            fail( "should never get here due to IllegalArgumentException" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-        
-        try
-        {
-            table.put( null, 2 );
-            fail( "should never get here due to IllegalArgumentException" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-        
-        assertEquals( 0, table.count() );
-        assertEquals( null, table.get( 1 ) );
-        
-        // Let's add the key with a valid value and remove just the value
-        assertEquals( 0, table.count( 1 ) );
-        table.remove( 1 );
-        assertEquals( 0, table.count( 1 ) );
-        table.put( 1, 1 );
-        assertEquals( 1, table.count( 1 ) );
-        table.remove( 1, 1 );
-        assertEquals( 0, table.count( 1 ) );
-        assertNull( table.get( 1 ) );
-        assertFalse( table.has( 1 ) );
-    }
-    
-
-    @Test
-    public void testRemove() throws Exception
-    {
-        table.put( 1, 1 );
-        table.remove( 1 );
-        assertNull( table.get( 1 ) );
-
-        table.put( 10, 10 );
-        
-        table.remove( 10, 11 );
-        assertFalse( table.has( 10, 11 ) );
-        
-//        assertNull( table.remove( null ) );
-//        assertNull( table.remove( null, null ) );
-    }
-
-
-    @Test
-    public void testPut() throws Exception
-    {
-        final int SIZE = 15;
-
-        for ( int ii = 0; ii < SIZE; ii++ )
-        {
-            table.put( ii, ii );
-        }
-        assertEquals( SIZE, table.count() );
-        table.put( 0, 0 );
-        assertTrue( table.has( 0, 0 ) );
-    }
-    
-
-    @Test
-    public void testHas() throws Exception
-    {
-        assertFalse( table.has( 1 ) );
-        final int SIZE = 15;
-        
-        for ( int ii = 0; ii < SIZE; ii++ )
-        {
-            table.put( ii, ii );
-        }
-        assertEquals( SIZE, table.count() );
-
-        assertFalse( table.has( -1 ) );
-        assertTrue( table.hasGreaterOrEqual( -1 ) );
-        assertFalse( table.hasLessOrEqual( -1 ) );
-        
-        assertTrue( table.has( 0 ) );
-        assertTrue( table.hasGreaterOrEqual( 0 ) );
-        assertTrue( table.hasLessOrEqual( 0 ) );
-        
-        assertTrue( table.has( SIZE - 1 ) );
-        assertTrue( table.hasGreaterOrEqual( SIZE - 1 ) );
-        assertTrue( table.hasLessOrEqual( SIZE - 1 ) );
-        
-        assertFalse( table.has( SIZE ) );
-        assertFalse( table.hasGreaterOrEqual( SIZE ) );
-        assertTrue( table.hasLessOrEqual( SIZE ) );
-        table.remove( 10 );
-        table.remove( 11 );
-        assertTrue( table.hasLessOrEqual( 11 ) );
-        
-        try
-        {
-            assertFalse( table.hasGreaterOrEqual( 1, 1 ) );
-            fail( "Should never get here." );
-        }
-        catch ( UnsupportedOperationException e )
-        {
-        }
-
-        try
-        {
-            assertFalse( table.hasLessOrEqual( 1, 1 ) );
-            fail( "Should never get here." );
-        }
-        catch ( UnsupportedOperationException e )
-        {
-        }
-
-        try
-        {
-            assertTrue( table.hasLessOrEqual( 1, 2 ) );
-            fail( "Should never get here since no dups tables " +
-                  "freak when they cannot find a value comparator" );
-        } 
-        catch ( UnsupportedOperationException e )
-        {
-            assertNotNull( e );
-        }
-    }
-    
-    
-    private class MockComparatorRegistry implements ComparatorRegistry
-    {
-        private Comparator 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> iterator()
-        {
-            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 )
-        {
-        }
-    }
-}
+/*
+ * 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.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.apache.directory.server.xdbm.Table;
+import org.apache.directory.server.schema.SerializableComparator;
+import org.apache.directory.server.schema.registries.ComparatorRegistry;
+import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescription;
+
+import java.io.File;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import jdbm.RecordManager;
+import jdbm.recman.BaseRecordManager;
+
+import javax.naming.NamingException;
+
+
+/**
+ * Document me!
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class JdbmTableNoDuplicatesTest
+{
+    private static final Logger LOG = LoggerFactory.getLogger( JdbmTableNoDuplicatesTest.class.getSimpleName() );
+    private static final String TEST_OUTPUT_PATH = "test.output.path";
+
+    transient Table<Integer,Integer> table;
+    transient File dbFile;
+    transient RecordManager recman;
+
+
+    @Before
+    public void createTable() throws Exception
+    {
+        destryTable();
+        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() );
+        table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>( "" ), null, null );
+        LOG.debug( "Created new table and populated it with data" );
+    }
+
+
+    @After
+    public void destryTable() throws Exception
+    {
+        if ( table != null )
+        {
+            table.close();
+        }
+
+        table = null;
+
+        if ( recman != null )
+        {
+            recman.close();
+        }
+
+        recman = null;
+
+        if ( dbFile != null )
+        {
+            String fileToDelete = dbFile.getAbsolutePath();
+            new File( fileToDelete + ".db" ).delete();
+            new File( fileToDelete + ".lg" ).delete();
+
+            dbFile.delete();
+        }
+        
+        dbFile = null;
+    }
+    
+
+    @Test
+    public void testCloseReopen() throws Exception
+    {
+        table.put( 1, 2 );
+        table.close();
+        table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>( "" ), null, null );
+        assertTrue( 2 == table.get( 1 ) );
+    }
+
+    
+    @Test 
+    public void testConfigMethods() throws Exception
+    {
+        assertFalse( table.isDupsEnabled() );
+        assertEquals( "test", table.getName() );
+        assertNotNull( table.getKeyComparator() );
+    }
+
+    
+    @Test
+    public void testWhenEmpty() throws Exception
+    {
+        // Test the count methods
+        assertEquals( 0, table.count() );
+        assertEquals( 0, table.count( 1 ) );
+
+        // Test get method
+        assertNull( table.get( 0 ) );
+        
+        // Test remove methods
+        table.remove( 1 );
+        assertNull( table.get( 1 ) );
+        
+        // Test has operations
+        assertFalse( table.has( 1 ) );
+        assertFalse( table.has( 1, 0 ) );
+        assertFalse( table.hasGreaterOrEqual( 1 ) );
+        assertFalse( table.hasLessOrEqual( 1 ) );
+
+        try
+        {
+            assertFalse( table.hasGreaterOrEqual( 1, 0 ) );
+            fail( "Should never get here." );
+        }
+        catch ( UnsupportedOperationException e )
+        {
+        }
+
+        try
+        {
+            assertFalse( table.hasLessOrEqual( 1, 0 ) );
+            fail( "Should never get here." );
+        }
+        catch ( UnsupportedOperationException e )
+        {
+        }
+    }
+
+    
+    @Test
+    public void testLoadData() throws Exception
+    {
+        // add some data to it
+        for ( int ii = 0; ii < 10; ii++ )
+        {
+            table.put( ii, ii );
+        }
+        
+        assertEquals( 10, table.count() );
+        assertEquals( 1, table.count( 0 ) );
+        
+        /*
+         * If counts are exact then we can test for exact values.  Again this 
+         * is not a critical function but one used for optimization so worst 
+         * case guesses are allowed.
+         */
+        
+        if ( table.isCountExact() )
+        {
+            assertEquals( 5, table.lessThanCount( 5 ) );
+            assertEquals( 4, table.greaterThanCount( 5 ) );
+        }
+        else
+        {
+            assertEquals( 10, table.lessThanCount( 5 ) );
+            assertEquals( 10, table.greaterThanCount( 5 ) );
+        }
+    }
+    
+    
+    /**
+     * Let's test keys with a null or lack of any values.
+     * @throws Exception on error
+     */
+    @Test
+    public void testNullOrEmptyKeyValue() throws Exception
+    {
+        assertEquals( 0, table.count() );
+        
+        try
+        {
+            table.put( 1, null );
+            fail( "should never get here due to IllegalArgumentException" );
+        }
+        catch( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+        
+        try
+        {
+            table.put( null, 2 );
+            fail( "should never get here due to IllegalArgumentException" );
+        }
+        catch( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+        
+        assertEquals( 0, table.count() );
+        assertEquals( null, table.get( 1 ) );
+        
+        // Let's add the key with a valid value and remove just the value
+        assertEquals( 0, table.count( 1 ) );
+        table.remove( 1 );
+        assertEquals( 0, table.count( 1 ) );
+        table.put( 1, 1 );
+        assertEquals( 1, table.count( 1 ) );
+        table.remove( 1, 1 );
+        assertEquals( 0, table.count( 1 ) );
+        assertNull( table.get( 1 ) );
+        assertFalse( table.has( 1 ) );
+    }
+    
+
+    @Test
+    public void testRemove() throws Exception
+    {
+        table.put( 1, 1 );
+        table.remove( 1 );
+        assertNull( table.get( 1 ) );
+
+        table.put( 10, 10 );
+        
+        table.remove( 10, 11 );
+        assertFalse( table.has( 10, 11 ) );
+        
+//        assertNull( table.remove( null ) );
+//        assertNull( table.remove( null, null ) );
+    }
+
+
+    @Test
+    public void testPut() throws Exception
+    {
+        final int SIZE = 15;
+
+        for ( int ii = 0; ii < SIZE; ii++ )
+        {
+            table.put( ii, ii );
+        }
+        assertEquals( SIZE, table.count() );
+        table.put( 0, 0 );
+        assertTrue( table.has( 0, 0 ) );
+    }
+    
+
+    @Test
+    public void testHas() throws Exception
+    {
+        assertFalse( table.has( 1 ) );
+        final int SIZE = 15;
+        
+        for ( int ii = 0; ii < SIZE; ii++ )
+        {
+            table.put( ii, ii );
+        }
+        assertEquals( SIZE, table.count() );
+
+        assertFalse( table.has( -1 ) );
+        assertTrue( table.hasGreaterOrEqual( -1 ) );
+        assertFalse( table.hasLessOrEqual( -1 ) );
+        
+        assertTrue( table.has( 0 ) );
+        assertTrue( table.hasGreaterOrEqual( 0 ) );
+        assertTrue( table.hasLessOrEqual( 0 ) );
+        
+        assertTrue( table.has( SIZE - 1 ) );
+        assertTrue( table.hasGreaterOrEqual( SIZE - 1 ) );
+        assertTrue( table.hasLessOrEqual( SIZE - 1 ) );
+        
+        assertFalse( table.has( SIZE ) );
+        assertFalse( table.hasGreaterOrEqual( SIZE ) );
+        assertTrue( table.hasLessOrEqual( SIZE ) );
+        table.remove( 10 );
+        table.remove( 11 );
+        assertTrue( table.hasLessOrEqual( 11 ) );
+        
+        try
+        {
+            assertFalse( table.hasGreaterOrEqual( 1, 1 ) );
+            fail( "Should never get here." );
+        }
+        catch ( UnsupportedOperationException e )
+        {
+        }
+
+        try
+        {
+            assertFalse( table.hasLessOrEqual( 1, 1 ) );
+            fail( "Should never get here." );
+        }
+        catch ( UnsupportedOperationException e )
+        {
+        }
+
+        try
+        {
+            assertTrue( table.hasLessOrEqual( 1, 2 ) );
+            fail( "Should never get here since no dups tables " +
+                  "freak when they cannot find a value comparator" );
+        } 
+        catch ( UnsupportedOperationException e )
+        {
+            assertNotNull( e );
+        }
+    }
+    
+    
+    private class MockComparatorRegistry implements ComparatorRegistry
+    {
+        private Comparator 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> iterator()
+        {
+            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 )
+        {
+        }
+    }
+}

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java?rev=801340&r1=801339&r2=801340&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java Wed Aug  5 17:55:15 2009
@@ -1,631 +1,631 @@
-/*
- * 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.junit.Before;
-import org.junit.After;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-import org.apache.directory.server.xdbm.Table;
-import org.apache.directory.server.xdbm.Tuple;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.registries.ComparatorRegistry;
-import org.apache.directory.shared.ldap.cursor.Cursor;
-import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescription;
-
-import java.io.File;
-import java.util.Comparator;
-import java.util.Iterator;
-
-import jdbm.RecordManager;
-import jdbm.helper.IntegerSerializer;
-import jdbm.recman.BaseRecordManager;
-
-import javax.naming.NamingException;
-
-
-/**
- * Tests JdbmTable operations with duplicates.  Does not test Cursor capabilities.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class JdbmTableWithDuplicatesTest
-{
-    private static final Logger LOG = LoggerFactory.getLogger( JdbmTableWithDuplicatesTest.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
-    {
-        destryTable();
-        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() );
-
-        table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
-                new SerializableComparator<Integer>( "" ),
-                new SerializableComparator<Integer>( "" ),
-                new IntegerSerializer(), new IntegerSerializer() );
-        LOG.debug( "Created new table and populated it with data" );
-    }
-
-
-    @After
-    public void destryTable() throws Exception
-    {
-        if ( table != null )
-        {
-            table.close();
-        }
-
-        table = null;
-
-        if ( recman != null )
-        {
-            recman.close();
-        }
-
-        recman = null;
-
-        if ( dbFile != null )
-        {
-            String fileToDelete = dbFile.getAbsolutePath();
-            new File( fileToDelete + ".db" ).delete();
-            new File( fileToDelete + ".lg" ).delete();
-
-            dbFile.delete();
-        }
-
-        dbFile = null;
-    }
-
-
-    @Test
-    public void testSerializers() throws Exception
-    {
-        assertNotNull( ( ( JdbmTable ) table ).getKeySerializer() );
-        assertNotNull( ( ( JdbmTable ) table ).getValueSerializer() );
-    }
-
-
-    @Test
-    public void testCountOneArg() throws Exception
-    {
-        assertEquals( 0, table.count( 3 ) );
-        assertEquals( 0, table.count( null ) );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void testNullKeyComparator() throws Exception
-    {
-        assertNotNull( ( ( JdbmTable ) table ).getKeyComparator() );
-        new JdbmTable<Integer,Integer>( "test", SIZE, recman,
-            null,
-            new SerializableComparator<Integer>( "" ),
-            null, new IntegerSerializer() );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void testNullValueComparator() throws Exception
-    {
-        assertNotNull( ( ( JdbmTable ) table ).getValueComparator() );
-        new JdbmTable<Integer,Integer>( "test", SIZE, recman,
-            new SerializableComparator<Integer>( "" ),
-            null,
-            null, new IntegerSerializer() );
-    }
-
-
-    @Test
-    public void testCloseReopen() throws Exception
-    {
-        table.put( 1, 2 );
-        assertTrue( 2 == table.get( 1 ) );
-        table.close();
-        table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
-                new SerializableComparator<Integer>( "" ),
-                new SerializableComparator<Integer>( "" ),
-                new IntegerSerializer(), new IntegerSerializer() );
-        assertTrue( 2 == table.get( 1 ) );
-    }
-
-    
-    @Test 
-    public void testConfigMethods() throws Exception
-    {
-        assertTrue( table.isDupsEnabled() );
-        assertEquals( "test", table.getName() );
-        assertNotNull( table.getKeyComparator() );
-    }
-
-    
-    @Test
-    public void testWhenEmpty() throws Exception
-    {
-        // Test the count methods
-        assertEquals( 0, table.count() );
-        assertEquals( 0, table.count( 1 ) );
-
-        // Test get method
-        assertNull( table.get( 0 ) );
-        assertNull( table.get( null ) );
-
-        // Test remove methods
-        table.remove( 1 );
-        assertFalse( table.has( 1 ) );
-        
-        // Test has operations
-        assertFalse( table.has( 1 ) );
-        assertFalse( table.has( 1, 0 ) );
-        assertFalse( table.hasGreaterOrEqual( 1 ) );
-        assertFalse( table.hasLessOrEqual( 1 ) );
-        assertFalse( table.hasGreaterOrEqual( 1, 0 ) );
-        assertFalse( table.hasLessOrEqual( 1, 0 ) );
-    }
-
-
-    @Test
-    public void testPut() throws Exception
-    {
-        final int SIZE = 15;
-
-        for ( int ii = 0; ii < SIZE; ii++ )
-        {
-            table.put( ii, ii );
-        }
-        assertEquals( SIZE, table.count() );
-        table.put( 0, 0 );
-        assertTrue( table.has( 0, 0 ) );
-
-        // add some duplicates
-        for ( int ii = 0; ii < SIZE*2; ii++ )
-        {
-            table.put( SIZE*2, ii );
-        }
-        assertEquals( SIZE*3, table.count() );
-        
-        table.put( 0, 0 );
-        assertTrue( table.has( 0, 0 ) );
-        
-        table.put( SIZE*2, 0 );
-        assertTrue( table.has( SIZE*2, 0 ) );
-    }
-
-
-    @Test
-    public void testHas() throws Exception
-    {
-        assertFalse( table.has( 1 ) );
-        
-        for ( int ii = 0; ii < SIZE*2; ii++ )
-        {
-            table.put( 1, ii );
-        }
-        assertEquals( SIZE*2, table.count() );
-
-        assertTrue( table.has( 1 ) );
-        assertTrue( table.has( 1, 0 ) );
-        assertFalse( table.has( 1, SIZE*2 ) );
-
-        assertTrue( table.hasGreaterOrEqual( 1, 0 ) );
-        assertTrue( table.hasLessOrEqual( 1, 0 ) );
-        assertFalse( table.hasLessOrEqual( 1, -1 ) );
-
-        assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 - 1 ) );
-        assertTrue( table.hasLessOrEqual( 1, SIZE*2 - 1 ) );
-        assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 - 1 ) );
-        assertTrue( table.hasLessOrEqual( 1, SIZE*2 ) );
-        assertFalse( table.hasGreaterOrEqual( 1, SIZE*2 ) );
-        assertFalse( table.has( 1, SIZE*2 ) );
-
-        // let's go over the this limit now and ask the same questions
-        table.put( 1, SIZE*2 );
-
-        assertTrue( table.has( 1 ) );
-        assertTrue( table.has( 1, 0 ) );
-        assertTrue( table.has( 1, SIZE*2 ) );
-        assertFalse( table.has( null, null ) );
-
-        assertTrue( table.hasGreaterOrEqual( 1, 0 ) );
-        assertTrue( table.hasLessOrEqual( 1, 0 ) );
-        assertFalse( table.hasLessOrEqual( 1, -1 ) );
-        assertFalse( table.hasGreaterOrEqual( null, null ) );
-        assertFalse( table.hasLessOrEqual( null, null ) );
-
-        assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 ) );
-        assertTrue( table.hasLessOrEqual( 1, SIZE*2 ) );
-        assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 ) );
-        assertTrue( table.hasLessOrEqual( 1, SIZE*2 + 1 ) );
-        assertFalse( table.hasGreaterOrEqual( 1, SIZE*2 + 1 ) );
-        assertFalse( table.has( 1, SIZE*2 + 1 ) );
-        
-        // now do not add duplicates and check has( key, boolean )
-        for ( int ii = 0; ii < SIZE; ii++ )
-        {
-            // note we are not adding duplicates not put( 1, ii )
-            table.put( ii, ii );
-        }
-        
-        assertFalse( table.has( -1 ) );
-        assertTrue( table.hasGreaterOrEqual( -1 ) );
-        assertFalse( table.hasLessOrEqual( -1 ) );
-        
-        assertTrue( table.has( 0 ) );
-        assertTrue( table.hasGreaterOrEqual( 0 ) );
-        assertTrue( table.hasLessOrEqual( 0 ) );
-        
-        assertTrue( table.has( SIZE - 1 ) );
-        assertTrue( table.hasGreaterOrEqual( SIZE - 1 ) );
-        assertTrue( table.hasLessOrEqual( SIZE - 1 ) );
-        
-        assertFalse( table.has( SIZE ) );
-        assertFalse( table.hasGreaterOrEqual( SIZE ) );
-        assertTrue( table.hasLessOrEqual( SIZE ) );
-
-        for ( int ii = 0; ii < SIZE; ii++ )
-        {
-            if ( ii == 1 ) // don't delete the node which had multiple values
-            {
-                continue;
-            }
-            table.remove( ii, ii );
-        }
-        
-        // delete all values of the duplicate key one by one
-        for ( int ii = 0; ii < SIZE * 2 + 1; ii++ )
-        {
-            table.remove( 1, ii );
-        }
-
-        Cursor<Tuple<Integer, Integer>> cursor = table.cursor();
-        //System.out.println( "remaining ..." );
-        cursor.beforeFirst();
-        while ( cursor.next() )
-        {
-            //System.out.println( cursor.get() );
-        }
-
-        assertFalse( table.hasLessOrEqual( 1 ) );
-        assertFalse( table.hasLessOrEqual( 1, 10 ) );
-        assertFalse( table.hasGreaterOrEqual( 1 ) );
-        assertFalse( table.hasGreaterOrEqual( 1, 0 ) );
-
-        table.put( 1, 0 );
-
-    }
-
-    
-    @Test
-    public void testRemove() throws Exception
-    {
-        assertEquals( 0, table.count() );
-
-        table.put( 1, 1 );
-        table.put( 1, 2 );
-        assertEquals( 2, table.count() );
-        table.remove( 1 );
-        assertFalse( table.has( 1 ) );
-        assertEquals( 0, table.count() );
-
-        table.put( 10, 10 );
-        assertEquals( 1, table.count() );
-        table.remove( 10, 11 );
-        assertFalse( table.has( 10, 11 ) );
-        assertEquals( 1, table.count() );
-        table.remove( 10, 10 );
-        assertFalse( table.has( 10, 10 ) );
-        assertEquals( 0, table.count() );
-
-        // add duplicates
-        for ( int ii = 0; ii < SIZE*2; ii++ )
-        {
-            table.put( 0, ii );
-        }
-
-        assertEquals( SIZE*2, table.count() );
-        table.remove( 0, 100 );
-        assertFalse( table.has( 0, 100 ) );
-        assertEquals( SIZE*2, table.count() );
-        
-        table.remove( 0 );
-        assertNull( table.get( 0 ) );
-    }
-    
-    
-    @Test
-    public void testLoadData() throws Exception
-    {
-        // add some data to it
-        for ( int ii = 0; ii < SIZE; ii++ )
-        {
-            table.put( ii, ii );
-        }
-        
-        assertEquals( 15, table.count() );
-        assertEquals( 1, table.count( 0 ) );
-        
-        /*
-         * If counts are exact then we can test for exact values.  Again this 
-         * is not a critical function but one used for optimization so worst 
-         * case guesses are allowed.
-         */
-        
-        if ( table.isCountExact() )
-        {
-            assertEquals( 5, table.lessThanCount( 5 ) );
-            assertEquals( 9, table.greaterThanCount( 5 ) );
-        }
-        else
-        {
-            assertEquals( SIZE, table.lessThanCount( 5 ) );
-            assertEquals( SIZE, table.greaterThanCount( 5 ) );
-        }
-    }
-    
-
-    @Test
-    public void testDuplicateLimit() throws Exception
-    {
-        for ( int ii = 0; ii < SIZE; ii++ )
-        {
-            table.put( 1, ii );
-        }
-        assertEquals( SIZE, table.count() );
-        assertEquals( SIZE, table.count( 1 ) );
-
-        // this switches to B+Trees from AvlTree
-        table.put( 1, SIZE );
-        assertEquals( SIZE + 1, table.count() );
-        assertEquals( SIZE + 1, table.count( 1 ) );
-
-        // go one more over still a B+Tree
-        table.put( 1, SIZE + 1 );
-        assertEquals( SIZE + 2, table.count() );
-        assertEquals( SIZE + 2, table.count( 1 ) );
-        assertEquals( 0, ( int ) table.get( 1 ) );
-        
-        // now start removing and see what happens 
-        table.remove( 1, SIZE + 1 );
-        assertFalse( table.has( 1, SIZE + 1 ) );
-        assertTrue( table.has( 1, SIZE ) );
-        assertEquals( SIZE + 1, table.count() );
-        assertEquals( SIZE + 1, table.count( 1 ) );
-
-        // this switches to AvlTree from B+Trees
-        table.remove( 1, SIZE );
-        assertFalse( table.has( 1, SIZE ) );
-        assertEquals( SIZE, table.count() );
-        assertEquals( SIZE, table.count( 1 ) );
-        assertTrue( 0 == table.get( 1 ) );
-    
-        for ( int ii = SIZE - 1; ii >= 0; ii-- )
-        {
-            table.remove( 1, ii );
-        }
-        assertEquals( 0, table.count() );
-
-        for ( int ii = 0; ii < SIZE - 1; ii++ )
-        {
-            table.put( 1, ii );
-        }
-        assertEquals( SIZE - 1, table.count() );
-        table.remove( 1 );
-        assertEquals( 0, table.count() );
-    }
-    
-    
-    /**
-     * Let's test keys with a null or lack of any values.
-     * @throws Exception on error
-     */
-    @Test
-    public void testNullOrEmptyKeyValueAfterDuplicateLimit() throws Exception
-    {
-        testDuplicateLimit();
-        assertEquals( 0, table.count() );
-        
-        try
-        {
-            table.put( 1, null );
-            fail( "should never get here due to IllegalArgumentException" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-        
-        try
-        {
-            table.put( null, 1 );
-            fail( "should never get here due to IllegalArgumentException" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-        
-        assertEquals( 0, table.count() );
-        assertEquals( null, table.get( 1 ) );
-        
-        // Let's add the key with two valid values and remove all values
-        table.remove( 1 );
-        table.put( 1, 1 );
-        table.put( 1, 2 );
-        assertEquals( 2, table.count( 1 ) );
-        table.remove( 1, 1 );
-        assertEquals( 1, table.count( 1 ) );
-        assertTrue( 2 == table.get( 1 ) );
-
-        table.remove( 1, 2 );
-        assertNull( table.get( 1 ) );
-        assertEquals( 0, table.count( 1 ) );
-        assertFalse( table.has( 1 ) );
-    }
-
-
-    @Test
-    public void testMiscellaneous() throws Exception
-    {
-        assertNotNull( ( ( JdbmTable ) table ).getMarshaller() );
-        ( ( JdbmTable ) table ).close();
-
-        // test value btree creation without serializer
-        table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
-                new SerializableComparator<Integer>( "" ),
-                new SerializableComparator<Integer>( "" ),
-                new IntegerSerializer(), null );
-        assertNull( ( ( JdbmTable ) table ).getValueSerializer() );
-        for ( int ii = 0; ii < SIZE + 1; ii++ )
-        {
-            table.put( 0, ii );
-        }
-        table.remove( 0 );
-        assertFalse( table.has( 0 ) );
-    }
-
-    
-    /**
-     * Let's test keys with a null or lack of any values.
-     * @throws Exception on error
-     */
-    @Test
-    public void testNullOrEmptyKeyValue() throws Exception
-    {
-        assertEquals( 0, table.count() );
-        
-        try
-        {
-            table.put( 1, null );
-            fail( "should never get here due to IllegalArgumentException" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-        
-        try
-        {
-            table.put( null, 2 );
-            fail( "should never get here due to IllegalArgumentException" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-        
-        assertEquals( 0, table.count() );
-        assertEquals( null, table.get( 1 ) );
-        
-        // Let's add the key with two valid values and remove all values
-        table.remove( 1 );
-        table.put( 1, 1 );
-        table.put( 1, 2 );
-        assertEquals( 2, table.count( 1 ) );
-        table.remove( 1, 1 );
-        assertEquals( 1, table.count( 1 ) );
-        assertTrue( 2 == table.get( 1 ) );
-
-        table.remove( 1, 2 );
-        assertNull( table.get( 1 ) );
-        assertEquals( 0, table.count( 1 ) );
-        assertFalse( table.has( 1 ) );
-    }
-    
-    
-    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> iterator()
-        {
-            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 )
-        {
-        }
-    }
-}
+/*
+ * 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.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.apache.directory.server.xdbm.Table;
+import org.apache.directory.server.xdbm.Tuple;
+import org.apache.directory.server.schema.SerializableComparator;
+import org.apache.directory.server.schema.registries.ComparatorRegistry;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescription;
+
+import java.io.File;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import jdbm.RecordManager;
+import jdbm.helper.IntegerSerializer;
+import jdbm.recman.BaseRecordManager;
+
+import javax.naming.NamingException;
+
+
+/**
+ * Tests JdbmTable operations with duplicates.  Does not test Cursor capabilities.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class JdbmTableWithDuplicatesTest
+{
+    private static final Logger LOG = LoggerFactory.getLogger( JdbmTableWithDuplicatesTest.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
+    {
+        destryTable();
+        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() );
+
+        table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
+                new SerializableComparator<Integer>( "" ),
+                new SerializableComparator<Integer>( "" ),
+                new IntegerSerializer(), new IntegerSerializer() );
+        LOG.debug( "Created new table and populated it with data" );
+    }
+
+
+    @After
+    public void destryTable() throws Exception
+    {
+        if ( table != null )
+        {
+            table.close();
+        }
+
+        table = null;
+
+        if ( recman != null )
+        {
+            recman.close();
+        }
+
+        recman = null;
+
+        if ( dbFile != null )
+        {
+            String fileToDelete = dbFile.getAbsolutePath();
+            new File( fileToDelete + ".db" ).delete();
+            new File( fileToDelete + ".lg" ).delete();
+
+            dbFile.delete();
+        }
+
+        dbFile = null;
+    }
+
+
+    @Test
+    public void testSerializers() throws Exception
+    {
+        assertNotNull( ( ( JdbmTable ) table ).getKeySerializer() );
+        assertNotNull( ( ( JdbmTable ) table ).getValueSerializer() );
+    }
+
+
+    @Test
+    public void testCountOneArg() throws Exception
+    {
+        assertEquals( 0, table.count( 3 ) );
+        assertEquals( 0, table.count( null ) );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void testNullKeyComparator() throws Exception
+    {
+        assertNotNull( ( ( JdbmTable ) table ).getKeyComparator() );
+        new JdbmTable<Integer,Integer>( "test", SIZE, recman,
+            null,
+            new SerializableComparator<Integer>( "" ),
+            null, new IntegerSerializer() );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void testNullValueComparator() throws Exception
+    {
+        assertNotNull( ( ( JdbmTable ) table ).getValueComparator() );
+        new JdbmTable<Integer,Integer>( "test", SIZE, recman,
+            new SerializableComparator<Integer>( "" ),
+            null,
+            null, new IntegerSerializer() );
+    }
+
+
+    @Test
+    public void testCloseReopen() throws Exception
+    {
+        table.put( 1, 2 );
+        assertTrue( 2 == table.get( 1 ) );
+        table.close();
+        table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
+                new SerializableComparator<Integer>( "" ),
+                new SerializableComparator<Integer>( "" ),
+                new IntegerSerializer(), new IntegerSerializer() );
+        assertTrue( 2 == table.get( 1 ) );
+    }
+
+    
+    @Test 
+    public void testConfigMethods() throws Exception
+    {
+        assertTrue( table.isDupsEnabled() );
+        assertEquals( "test", table.getName() );
+        assertNotNull( table.getKeyComparator() );
+    }
+
+    
+    @Test
+    public void testWhenEmpty() throws Exception
+    {
+        // Test the count methods
+        assertEquals( 0, table.count() );
+        assertEquals( 0, table.count( 1 ) );
+
+        // Test get method
+        assertNull( table.get( 0 ) );
+        assertNull( table.get( null ) );
+
+        // Test remove methods
+        table.remove( 1 );
+        assertFalse( table.has( 1 ) );
+        
+        // Test has operations
+        assertFalse( table.has( 1 ) );
+        assertFalse( table.has( 1, 0 ) );
+        assertFalse( table.hasGreaterOrEqual( 1 ) );
+        assertFalse( table.hasLessOrEqual( 1 ) );
+        assertFalse( table.hasGreaterOrEqual( 1, 0 ) );
+        assertFalse( table.hasLessOrEqual( 1, 0 ) );
+    }
+
+
+    @Test
+    public void testPut() throws Exception
+    {
+        final int SIZE = 15;
+
+        for ( int ii = 0; ii < SIZE; ii++ )
+        {
+            table.put( ii, ii );
+        }
+        assertEquals( SIZE, table.count() );
+        table.put( 0, 0 );
+        assertTrue( table.has( 0, 0 ) );
+
+        // add some duplicates
+        for ( int ii = 0; ii < SIZE*2; ii++ )
+        {
+            table.put( SIZE*2, ii );
+        }
+        assertEquals( SIZE*3, table.count() );
+        
+        table.put( 0, 0 );
+        assertTrue( table.has( 0, 0 ) );
+        
+        table.put( SIZE*2, 0 );
+        assertTrue( table.has( SIZE*2, 0 ) );
+    }
+
+
+    @Test
+    public void testHas() throws Exception
+    {
+        assertFalse( table.has( 1 ) );
+        
+        for ( int ii = 0; ii < SIZE*2; ii++ )
+        {
+            table.put( 1, ii );
+        }
+        assertEquals( SIZE*2, table.count() );
+
+        assertTrue( table.has( 1 ) );
+        assertTrue( table.has( 1, 0 ) );
+        assertFalse( table.has( 1, SIZE*2 ) );
+
+        assertTrue( table.hasGreaterOrEqual( 1, 0 ) );
+        assertTrue( table.hasLessOrEqual( 1, 0 ) );
+        assertFalse( table.hasLessOrEqual( 1, -1 ) );
+
+        assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 - 1 ) );
+        assertTrue( table.hasLessOrEqual( 1, SIZE*2 - 1 ) );
+        assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 - 1 ) );
+        assertTrue( table.hasLessOrEqual( 1, SIZE*2 ) );
+        assertFalse( table.hasGreaterOrEqual( 1, SIZE*2 ) );
+        assertFalse( table.has( 1, SIZE*2 ) );
+
+        // let's go over the this limit now and ask the same questions
+        table.put( 1, SIZE*2 );
+
+        assertTrue( table.has( 1 ) );
+        assertTrue( table.has( 1, 0 ) );
+        assertTrue( table.has( 1, SIZE*2 ) );
+        assertFalse( table.has( null, null ) );
+
+        assertTrue( table.hasGreaterOrEqual( 1, 0 ) );
+        assertTrue( table.hasLessOrEqual( 1, 0 ) );
+        assertFalse( table.hasLessOrEqual( 1, -1 ) );
+        assertFalse( table.hasGreaterOrEqual( null, null ) );
+        assertFalse( table.hasLessOrEqual( null, null ) );
+
+        assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 ) );
+        assertTrue( table.hasLessOrEqual( 1, SIZE*2 ) );
+        assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 ) );
+        assertTrue( table.hasLessOrEqual( 1, SIZE*2 + 1 ) );
+        assertFalse( table.hasGreaterOrEqual( 1, SIZE*2 + 1 ) );
+        assertFalse( table.has( 1, SIZE*2 + 1 ) );
+        
+        // now do not add duplicates and check has( key, boolean )
+        for ( int ii = 0; ii < SIZE; ii++ )
+        {
+            // note we are not adding duplicates not put( 1, ii )
+            table.put( ii, ii );
+        }
+        
+        assertFalse( table.has( -1 ) );
+        assertTrue( table.hasGreaterOrEqual( -1 ) );
+        assertFalse( table.hasLessOrEqual( -1 ) );
+        
+        assertTrue( table.has( 0 ) );
+        assertTrue( table.hasGreaterOrEqual( 0 ) );
+        assertTrue( table.hasLessOrEqual( 0 ) );
+        
+        assertTrue( table.has( SIZE - 1 ) );
+        assertTrue( table.hasGreaterOrEqual( SIZE - 1 ) );
+        assertTrue( table.hasLessOrEqual( SIZE - 1 ) );
+        
+        assertFalse( table.has( SIZE ) );
+        assertFalse( table.hasGreaterOrEqual( SIZE ) );
+        assertTrue( table.hasLessOrEqual( SIZE ) );
+
+        for ( int ii = 0; ii < SIZE; ii++ )
+        {
+            if ( ii == 1 ) // don't delete the node which had multiple values
+            {
+                continue;
+            }
+            table.remove( ii, ii );
+        }
+        
+        // delete all values of the duplicate key one by one
+        for ( int ii = 0; ii < SIZE * 2 + 1; ii++ )
+        {
+            table.remove( 1, ii );
+        }
+
+        Cursor<Tuple<Integer, Integer>> cursor = table.cursor();
+        //System.out.println( "remaining ..." );
+        cursor.beforeFirst();
+        while ( cursor.next() )
+        {
+            //System.out.println( cursor.get() );
+        }
+
+        assertFalse( table.hasLessOrEqual( 1 ) );
+        assertFalse( table.hasLessOrEqual( 1, 10 ) );
+        assertFalse( table.hasGreaterOrEqual( 1 ) );
+        assertFalse( table.hasGreaterOrEqual( 1, 0 ) );
+
+        table.put( 1, 0 );
+
+    }
+
+    
+    @Test
+    public void testRemove() throws Exception
+    {
+        assertEquals( 0, table.count() );
+
+        table.put( 1, 1 );
+        table.put( 1, 2 );
+        assertEquals( 2, table.count() );
+        table.remove( 1 );
+        assertFalse( table.has( 1 ) );
+        assertEquals( 0, table.count() );
+
+        table.put( 10, 10 );
+        assertEquals( 1, table.count() );
+        table.remove( 10, 11 );
+        assertFalse( table.has( 10, 11 ) );
+        assertEquals( 1, table.count() );
+        table.remove( 10, 10 );
+        assertFalse( table.has( 10, 10 ) );
+        assertEquals( 0, table.count() );
+
+        // add duplicates
+        for ( int ii = 0; ii < SIZE*2; ii++ )
+        {
+            table.put( 0, ii );
+        }
+
+        assertEquals( SIZE*2, table.count() );
+        table.remove( 0, 100 );
+        assertFalse( table.has( 0, 100 ) );
+        assertEquals( SIZE*2, table.count() );
+        
+        table.remove( 0 );
+        assertNull( table.get( 0 ) );
+    }
+    
+    
+    @Test
+    public void testLoadData() throws Exception
+    {
+        // add some data to it
+        for ( int ii = 0; ii < SIZE; ii++ )
+        {
+            table.put( ii, ii );
+        }
+        
+        assertEquals( 15, table.count() );
+        assertEquals( 1, table.count( 0 ) );
+        
+        /*
+         * If counts are exact then we can test for exact values.  Again this 
+         * is not a critical function but one used for optimization so worst 
+         * case guesses are allowed.
+         */
+        
+        if ( table.isCountExact() )
+        {
+            assertEquals( 5, table.lessThanCount( 5 ) );
+            assertEquals( 9, table.greaterThanCount( 5 ) );
+        }
+        else
+        {
+            assertEquals( SIZE, table.lessThanCount( 5 ) );
+            assertEquals( SIZE, table.greaterThanCount( 5 ) );
+        }
+    }
+    
+
+    @Test
+    public void testDuplicateLimit() throws Exception
+    {
+        for ( int ii = 0; ii < SIZE; ii++ )
+        {
+            table.put( 1, ii );
+        }
+        assertEquals( SIZE, table.count() );
+        assertEquals( SIZE, table.count( 1 ) );
+
+        // this switches to B+Trees from AvlTree
+        table.put( 1, SIZE );
+        assertEquals( SIZE + 1, table.count() );
+        assertEquals( SIZE + 1, table.count( 1 ) );
+
+        // go one more over still a B+Tree
+        table.put( 1, SIZE + 1 );
+        assertEquals( SIZE + 2, table.count() );
+        assertEquals( SIZE + 2, table.count( 1 ) );
+        assertEquals( 0, ( int ) table.get( 1 ) );
+        
+        // now start removing and see what happens 
+        table.remove( 1, SIZE + 1 );
+        assertFalse( table.has( 1, SIZE + 1 ) );
+        assertTrue( table.has( 1, SIZE ) );
+        assertEquals( SIZE + 1, table.count() );
+        assertEquals( SIZE + 1, table.count( 1 ) );
+
+        // this switches to AvlTree from B+Trees
+        table.remove( 1, SIZE );
+        assertFalse( table.has( 1, SIZE ) );
+        assertEquals( SIZE, table.count() );
+        assertEquals( SIZE, table.count( 1 ) );
+        assertTrue( 0 == table.get( 1 ) );
+    
+        for ( int ii = SIZE - 1; ii >= 0; ii-- )
+        {
+            table.remove( 1, ii );
+        }
+        assertEquals( 0, table.count() );
+
+        for ( int ii = 0; ii < SIZE - 1; ii++ )
+        {
+            table.put( 1, ii );
+        }
+        assertEquals( SIZE - 1, table.count() );
+        table.remove( 1 );
+        assertEquals( 0, table.count() );
+    }
+    
+    
+    /**
+     * Let's test keys with a null or lack of any values.
+     * @throws Exception on error
+     */
+    @Test
+    public void testNullOrEmptyKeyValueAfterDuplicateLimit() throws Exception
+    {
+        testDuplicateLimit();
+        assertEquals( 0, table.count() );
+        
+        try
+        {
+            table.put( 1, null );
+            fail( "should never get here due to IllegalArgumentException" );
+        }
+        catch( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+        
+        try
+        {
+            table.put( null, 1 );
+            fail( "should never get here due to IllegalArgumentException" );
+        }
+        catch( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+        
+        assertEquals( 0, table.count() );
+        assertEquals( null, table.get( 1 ) );
+        
+        // Let's add the key with two valid values and remove all values
+        table.remove( 1 );
+        table.put( 1, 1 );
+        table.put( 1, 2 );
+        assertEquals( 2, table.count( 1 ) );
+        table.remove( 1, 1 );
+        assertEquals( 1, table.count( 1 ) );
+        assertTrue( 2 == table.get( 1 ) );
+
+        table.remove( 1, 2 );
+        assertNull( table.get( 1 ) );
+        assertEquals( 0, table.count( 1 ) );
+        assertFalse( table.has( 1 ) );
+    }
+
+
+    @Test
+    public void testMiscellaneous() throws Exception
+    {
+        assertNotNull( ( ( JdbmTable ) table ).getMarshaller() );
+        ( ( JdbmTable ) table ).close();
+
+        // test value btree creation without serializer
+        table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
+                new SerializableComparator<Integer>( "" ),
+                new SerializableComparator<Integer>( "" ),
+                new IntegerSerializer(), null );
+        assertNull( ( ( JdbmTable ) table ).getValueSerializer() );
+        for ( int ii = 0; ii < SIZE + 1; ii++ )
+        {
+            table.put( 0, ii );
+        }
+        table.remove( 0 );
+        assertFalse( table.has( 0 ) );
+    }
+
+    
+    /**
+     * Let's test keys with a null or lack of any values.
+     * @throws Exception on error
+     */
+    @Test
+    public void testNullOrEmptyKeyValue() throws Exception
+    {
+        assertEquals( 0, table.count() );
+        
+        try
+        {
+            table.put( 1, null );
+            fail( "should never get here due to IllegalArgumentException" );
+        }
+        catch( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+        
+        try
+        {
+            table.put( null, 2 );
+            fail( "should never get here due to IllegalArgumentException" );
+        }
+        catch( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+        
+        assertEquals( 0, table.count() );
+        assertEquals( null, table.get( 1 ) );
+        
+        // Let's add the key with two valid values and remove all values
+        table.remove( 1 );
+        table.put( 1, 1 );
+        table.put( 1, 2 );
+        assertEquals( 2, table.count( 1 ) );
+        table.remove( 1, 1 );
+        assertEquals( 1, table.count( 1 ) );
+        assertTrue( 2 == table.get( 1 ) );
+
+        table.remove( 1, 2 );
+        assertNull( table.get( 1 ) );
+        assertEquals( 0, table.count( 1 ) );
+        assertFalse( table.has( 1 ) );
+    }
+    
+    
+    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> iterator()
+        {
+            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 )
+        {
+        }
+    }
+}

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java?rev=801340&r1=801339&r2=801340&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java Wed Aug  5 17:55:15 2009
@@ -1,308 +1,308 @@
-/*
- * 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.*;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertNull;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import jdbm.RecordManager;
-import jdbm.helper.StringComparator;
-import jdbm.helper.TupleBrowser;
-import jdbm.helper.Tuple;
-import jdbm.btree.BTree;
-import jdbm.recman.BaseRecordManager;
-
-import java.io.File;
-import java.util.Comparator;
-
-
-
-/**
- * Document me!
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class KeyBTreeCursorTest
-{
-    private static final Logger LOG = LoggerFactory.getLogger( KeyBTreeCursorTest.class.getSimpleName() );
-    private static final byte[] EMPTY_BYTES = new byte[0];
-    private static final String TEST_OUTPUT_PATH = "test.output.path";
-
-    File dbFile;
-    RecordManager recman;
-    BTree bt;
-    Comparator<String> comparator;
-
-    KeyBTreeCursor<String> cursor;
-
-
-    @SuppressWarnings({"unchecked"})
-    @Before
-    public void createCursor() throws Exception
-    {
-        File tmpDir = null;
-        if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
-        {
-            tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
-        }
-
-        dbFile = File.createTempFile( KeyBTreeCursorTest.class.getName(), "db", tmpDir );
-        recman = new BaseRecordManager( dbFile.getAbsolutePath() );
-        comparator = new StringComparator();
-        bt = BTree.createInstance( recman, comparator );
-
-        // add some data to it
-        bt.insert( "0", EMPTY_BYTES, true );
-        bt.insert( "1", EMPTY_BYTES, true );
-        bt.insert( "2", EMPTY_BYTES, true );
-        bt.insert( "3", EMPTY_BYTES, true );
-        bt.insert( "4", EMPTY_BYTES, true );
-        bt.insert( "5", EMPTY_BYTES, true );
-        bt.insert( "6", EMPTY_BYTES, true );
-        bt.insert( "7", EMPTY_BYTES, true );
-        bt.insert( "8", EMPTY_BYTES, true );
-        bt.insert( "9", EMPTY_BYTES, true );
-
-        cursor = new KeyBTreeCursor<String>( bt, comparator );
-        LOG.debug( "Created new KeyBTreeCursor and populated it's btree" );
-    }
-
-
-    @After
-    public void destryCursor() throws Exception
-    {
-        recman.close();
-        recman = null;
-        dbFile.deleteOnExit();
-
-        String fileToDelete = dbFile.getAbsolutePath();
-        new File( fileToDelete + ".db" ).delete();
-        new File( fileToDelete + ".lg" ).delete();
-
-        dbFile = null;
-    }
-
-
-    @Test
-    public void testPreviousBeforePositioning() throws Exception
-    {
-        // test initial setup, advances after, and before inside elements
-        assertInvalidCursor();
-
-        assertTrue( cursor.previous() );
-        assertEquals( "9", cursor.get() );
-    }
-
-
-    @Test
-    public void testNextBeforePositioning() throws Exception
-    {
-        // test initial setup, advances after, and before inside elements
-        assertInvalidCursor();
-
-        assertTrue( cursor.next() );
-        assertEquals( "0", cursor.get() );
-    }
-
-
-    @Test
-    public void testOperations() throws Exception
-    {
-        // test initial setup, advances after, and before inside elements
-        assertInvalidCursor();
-
-        assertTrue( cursor.next() );
-        assertEquals( "0", cursor.get() );
-
-        cursor.after( "5" );
-        assertInvalidCursor();
-        assertTrue( cursor.next() );
-        assertEquals( "6", cursor.get() );
-
-        cursor.before( "2" );
-        assertInvalidCursor();
-        assertTrue( cursor.next() );
-        assertEquals( "2", cursor.get() );
-
-        // test advances up to and past the tail end
-        cursor.after( "9" );
-        assertInvalidCursor();
-        assertFalse( cursor.next() );
-        assertTrue( cursor.previous() );
-        assertEquals( "9", cursor.get() );
-
-        cursor.after( "a" );
-        assertInvalidCursor();
-        assertFalse( cursor.next() );
-        assertTrue( cursor.previous() );
-        assertEquals( "9", cursor.get() );
-
-        cursor.before( "a" );
-        assertInvalidCursor();
-        assertFalse( cursor.next() );
-        assertTrue( cursor.previous() );
-        assertEquals( "9", cursor.get() );
-
-        // test advances up to and past the head
-        cursor.before( "0" );
-        assertInvalidCursor();
-        assertFalse( cursor.previous() );
-        assertTrue( cursor.next() );
-        assertEquals( "0", cursor.get() );
-
-        cursor.after( "*" );
-        assertInvalidCursor();
-        assertFalse( cursor.previous() );
-        assertTrue( cursor.next() );
-        assertEquals( "0", cursor.get() );
-
-        cursor.before( "*" );
-        assertInvalidCursor();
-        assertFalse( cursor.previous() );
-        assertTrue( cursor.next() );
-        assertEquals( "0", cursor.get() );
-        
-        bt.remove( "0" );
-        bt.remove( "1" );
-        bt.remove( "2" );
-        bt.remove( "3" );
-        bt.remove( "4" );
-        bt.remove( "6" );
-        bt.remove( "7" );
-        bt.remove( "8" );
-        bt.remove( "9" );
-
-        // now test with only one element: "5" remains now with others deleted
-        cursor.before( "5" );
-        assertInvalidCursor();
-        assertFalse( cursor.previous() );
-        assertTrue( cursor.next() );
-        assertEquals( "5", cursor.get() );
-        assertFalse( cursor.next() );
-
-        cursor.after( "5" );
-        assertInvalidCursor();
-        assertFalse( cursor.next() );
-        assertTrue( cursor.previous() );
-        assertEquals( "5", cursor.get() );
-        assertFalse( cursor.previous() );
-    }
-
-
-    @Test
-    public void testJdbmBrowse() throws Exception
-    {
-        bt.remove( "0" );
-        bt.remove( "5" );
-        bt.remove( "6" );
-        bt.remove( "7" );
-        bt.remove( "9" );
-
-        assertNull( bt.find( "0" ) );
-        assertNotNull( bt.find( "1" ) );
-        assertNotNull( bt.find( "2" ) );
-        assertNotNull( bt.find( "3" ) );
-        assertNotNull( bt.find( "4" ) );
-        assertNull( bt.find( "5" ) );
-        assertNull( bt.find( "6" ) );
-        assertNull( bt.find( "7" ) );
-        assertNotNull( bt.find( "8" ) );
-        assertNull( bt.find( "9" ) );
-
-        // browse will position us right after "4" and getNext() will return 8
-        // since "5", "6", and "7" do not exist
-        TupleBrowser browser = bt.browse( "5" );
-        assertNotNull( browser );
-        Tuple tuple = new Tuple();
-        browser.getNext( tuple );
-        assertEquals( "8", tuple.getKey() );
-
-        // browse will position us right after "1" and getNext() will return 2
-        // since "2" exists.
-        browser = bt.browse( "2" );
-        assertNotNull( browser );
-        tuple = new Tuple();
-        browser.getNext( tuple );
-        assertEquals( "2", tuple.getKey() );
-
-        // browse will position us right after "8" and getNext() will null
-        // since nothing else exists past 8.  We've come to the end.
-        browser = bt.browse( "9" );
-        assertNotNull( browser );
-        tuple = new Tuple();
-        browser.getNext( tuple );
-        assertNull( tuple.getKey() );
-
-        // browse will position us right before "1" and getPrevious() will
-        // null since nothing else exists before 1.  We've come to the end.
-        // getNext() will however return "1".
-        browser = bt.browse( "0" );
-        assertNotNull( browser );
-        tuple = new Tuple();
-        browser.getPrevious( tuple );
-        assertNull( tuple.getKey() );
-        browser.getNext( tuple );
-        assertEquals( "1", tuple.getKey() );
-    }
-
-    
-    @Test
-    public void testMiscelleneous() throws Exception
-    {
-        // Test available()
-        
-        assertFalse( cursor.available() );
-        cursor.beforeFirst();
-        assertFalse( cursor.available() );
-        cursor.afterLast();
-        assertFalse( cursor.available() );
-        cursor.first();
-        assertTrue( cursor.available() );
-        cursor.last();
-        assertTrue( cursor.available() );
-        
-        // Test isElementReused()
-        
-        assertFalse( cursor.isElementReused() );
-    }
-    
-
-    private void assertInvalidCursor()
-    {
-        try
-        {
-            cursor.get();
-            fail( "Invalid Cursor should not return valid value from get()" );
-        }
-        catch ( Exception e )
-        {
-            assertNotNull( e );
-        }
-    }
-}
+/*
+ * 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.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import jdbm.RecordManager;
+import jdbm.helper.StringComparator;
+import jdbm.helper.TupleBrowser;
+import jdbm.helper.Tuple;
+import jdbm.btree.BTree;
+import jdbm.recman.BaseRecordManager;
+
+import java.io.File;
+import java.util.Comparator;
+
+
+
+/**
+ * Document me!
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class KeyBTreeCursorTest
+{
+    private static final Logger LOG = LoggerFactory.getLogger( KeyBTreeCursorTest.class.getSimpleName() );
+    private static final byte[] EMPTY_BYTES = new byte[0];
+    private static final String TEST_OUTPUT_PATH = "test.output.path";
+
+    File dbFile;
+    RecordManager recman;
+    BTree bt;
+    Comparator<String> comparator;
+
+    KeyBTreeCursor<String> cursor;
+
+
+    @SuppressWarnings({"unchecked"})
+    @Before
+    public void createCursor() throws Exception
+    {
+        File tmpDir = null;
+        if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
+        {
+            tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
+        }
+
+        dbFile = File.createTempFile( KeyBTreeCursorTest.class.getName(), "db", tmpDir );
+        recman = new BaseRecordManager( dbFile.getAbsolutePath() );
+        comparator = new StringComparator();
+        bt = BTree.createInstance( recman, comparator );
+
+        // add some data to it
+        bt.insert( "0", EMPTY_BYTES, true );
+        bt.insert( "1", EMPTY_BYTES, true );
+        bt.insert( "2", EMPTY_BYTES, true );
+        bt.insert( "3", EMPTY_BYTES, true );
+        bt.insert( "4", EMPTY_BYTES, true );
+        bt.insert( "5", EMPTY_BYTES, true );
+        bt.insert( "6", EMPTY_BYTES, true );
+        bt.insert( "7", EMPTY_BYTES, true );
+        bt.insert( "8", EMPTY_BYTES, true );
+        bt.insert( "9", EMPTY_BYTES, true );
+
+        cursor = new KeyBTreeCursor<String>( bt, comparator );
+        LOG.debug( "Created new KeyBTreeCursor and populated it's btree" );
+    }
+
+
+    @After
+    public void destryCursor() throws Exception
+    {
+        recman.close();
+        recman = null;
+        dbFile.deleteOnExit();
+
+        String fileToDelete = dbFile.getAbsolutePath();
+        new File( fileToDelete + ".db" ).delete();
+        new File( fileToDelete + ".lg" ).delete();
+
+        dbFile = null;
+    }
+
+
+    @Test
+    public void testPreviousBeforePositioning() throws Exception
+    {
+        // test initial setup, advances after, and before inside elements
+        assertInvalidCursor();
+
+        assertTrue( cursor.previous() );
+        assertEquals( "9", cursor.get() );
+    }
+
+
+    @Test
+    public void testNextBeforePositioning() throws Exception
+    {
+        // test initial setup, advances after, and before inside elements
+        assertInvalidCursor();
+
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+    }
+
+
+    @Test
+    public void testOperations() throws Exception
+    {
+        // test initial setup, advances after, and before inside elements
+        assertInvalidCursor();
+
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+
+        cursor.after( "5" );
+        assertInvalidCursor();
+        assertTrue( cursor.next() );
+        assertEquals( "6", cursor.get() );
+
+        cursor.before( "2" );
+        assertInvalidCursor();
+        assertTrue( cursor.next() );
+        assertEquals( "2", cursor.get() );
+
+        // test advances up to and past the tail end
+        cursor.after( "9" );
+        assertInvalidCursor();
+        assertFalse( cursor.next() );
+        assertTrue( cursor.previous() );
+        assertEquals( "9", cursor.get() );
+
+        cursor.after( "a" );
+        assertInvalidCursor();
+        assertFalse( cursor.next() );
+        assertTrue( cursor.previous() );
+        assertEquals( "9", cursor.get() );
+
+        cursor.before( "a" );
+        assertInvalidCursor();
+        assertFalse( cursor.next() );
+        assertTrue( cursor.previous() );
+        assertEquals( "9", cursor.get() );
+
+        // test advances up to and past the head
+        cursor.before( "0" );
+        assertInvalidCursor();
+        assertFalse( cursor.previous() );
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+
+        cursor.after( "*" );
+        assertInvalidCursor();
+        assertFalse( cursor.previous() );
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+
+        cursor.before( "*" );
+        assertInvalidCursor();
+        assertFalse( cursor.previous() );
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+        
+        bt.remove( "0" );
+        bt.remove( "1" );
+        bt.remove( "2" );
+        bt.remove( "3" );
+        bt.remove( "4" );
+        bt.remove( "6" );
+        bt.remove( "7" );
+        bt.remove( "8" );
+        bt.remove( "9" );
+
+        // now test with only one element: "5" remains now with others deleted
+        cursor.before( "5" );
+        assertInvalidCursor();
+        assertFalse( cursor.previous() );
+        assertTrue( cursor.next() );
+        assertEquals( "5", cursor.get() );
+        assertFalse( cursor.next() );
+
+        cursor.after( "5" );
+        assertInvalidCursor();
+        assertFalse( cursor.next() );
+        assertTrue( cursor.previous() );
+        assertEquals( "5", cursor.get() );
+        assertFalse( cursor.previous() );
+    }
+
+
+    @Test
+    public void testJdbmBrowse() throws Exception
+    {
+        bt.remove( "0" );
+        bt.remove( "5" );
+        bt.remove( "6" );
+        bt.remove( "7" );
+        bt.remove( "9" );
+
+        assertNull( bt.find( "0" ) );
+        assertNotNull( bt.find( "1" ) );
+        assertNotNull( bt.find( "2" ) );
+        assertNotNull( bt.find( "3" ) );
+        assertNotNull( bt.find( "4" ) );
+        assertNull( bt.find( "5" ) );
+        assertNull( bt.find( "6" ) );
+        assertNull( bt.find( "7" ) );
+        assertNotNull( bt.find( "8" ) );
+        assertNull( bt.find( "9" ) );
+
+        // browse will position us right after "4" and getNext() will return 8
+        // since "5", "6", and "7" do not exist
+        TupleBrowser browser = bt.browse( "5" );
+        assertNotNull( browser );
+        Tuple tuple = new Tuple();
+        browser.getNext( tuple );
+        assertEquals( "8", tuple.getKey() );
+
+        // browse will position us right after "1" and getNext() will return 2
+        // since "2" exists.
+        browser = bt.browse( "2" );
+        assertNotNull( browser );
+        tuple = new Tuple();
+        browser.getNext( tuple );
+        assertEquals( "2", tuple.getKey() );
+
+        // browse will position us right after "8" and getNext() will null
+        // since nothing else exists past 8.  We've come to the end.
+        browser = bt.browse( "9" );
+        assertNotNull( browser );
+        tuple = new Tuple();
+        browser.getNext( tuple );
+        assertNull( tuple.getKey() );
+
+        // browse will position us right before "1" and getPrevious() will
+        // null since nothing else exists before 1.  We've come to the end.
+        // getNext() will however return "1".
+        browser = bt.browse( "0" );
+        assertNotNull( browser );
+        tuple = new Tuple();
+        browser.getPrevious( tuple );
+        assertNull( tuple.getKey() );
+        browser.getNext( tuple );
+        assertEquals( "1", tuple.getKey() );
+    }
+
+    
+    @Test
+    public void testMiscelleneous() throws Exception
+    {
+        // Test available()
+        
+        assertFalse( cursor.available() );
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+        cursor.first();
+        assertTrue( cursor.available() );
+        cursor.last();
+        assertTrue( cursor.available() );
+        
+        // Test isElementReused()
+        
+        assertFalse( cursor.isElementReused() );
+    }
+    
+
+    private void assertInvalidCursor()
+    {
+        try
+        {
+            cursor.get();
+            fail( "Invalid Cursor should not return valid value from get()" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull( e );
+        }
+    }
+}