directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r442107 - in /directory/branches/apacheds/optimization2: core/src/main/java/org/apache/directory/server/core/partition/impl/btree/ core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ core/src/test/java/org/apache/...
Date Mon, 11 Sep 2006 05:41:40 GMT
Author: akarasulu
Date: Sun Sep 10 22:41:39 2006
New Revision: 442107

URL: http://svn.apache.org/viewvc?view=rev&rev=442107
Log:
changes ...

 o added more test for greater coverage with btree based duplicates
 o fixed bug in optimizer due to integer overflow
 o fixed bug in enumeration for duplcates where table was null
 o fixd bug in jdbm table dealing with removal operations in btrees for dups
 o fixed DumpCommand to now use new Index constructor overload 
 o fixed MANIFEST.MF to use new 1.0-SNAPSHOT jars instead of RC4 in tools prj


Added:
    directory/branches/apacheds/optimization2/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsBTreeTest.java
Modified:
    directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultOptimizer.java
    directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsEnumeration.java
    directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
    directory/branches/apacheds/optimization2/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java
    directory/branches/apacheds/optimization2/server-tools/src/main/manifest/MANIFEST.MF

Modified: directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultOptimizer.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultOptimizer.java?view=diff&rev=442107&r1=442106&r2=442107
==============================================================================
--- directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultOptimizer.java
(original)
+++ directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultOptimizer.java
Sun Sep 10 22:41:39 2006
@@ -178,7 +178,7 @@
      */
     private BigInteger getConjunctionScan( BranchNode node ) throws NamingException
     {
-        BigInteger count = BigInteger.valueOf( Integer.MAX_VALUE );
+        BigInteger count = MAX;
         ArrayList children = node.getChildren();
 
         for ( int ii = 0; ii < children.size(); ii++ )
@@ -243,6 +243,12 @@
             ExprNode child = ( ExprNode ) children.get( ii );
             annotate( child );
             total = total.add( ( BigInteger ) child.get( "count" ) );
+        }
+        
+        // we don't want values bigger than Integer.MAX_VALUE
+        if ( total.compareTo( MAX ) > 0 )
+        {
+            total = MAX;
         }
 
         return total;

Modified: directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsEnumeration.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsEnumeration.java?view=diff&rev=442107&r1=442106&r2=442107
==============================================================================
--- directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsEnumeration.java
(original)
+++ directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsEnumeration.java
Sun Sep 10 22:41:39 2006
@@ -86,6 +86,7 @@
      */
     public DupsEnumeration( JdbmTable table, NoDupsEnumeration list ) throws NamingException
     {
+        this.table = table;
         underlying = list;
 
         // Protect against closed cursors

Modified: directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?view=diff&rev=442107&r1=442106&r2=442107
==============================================================================
--- directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
(original)
+++ directory/branches/apacheds/optimization2/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
Sun Sep 10 22:41:39 2006
@@ -897,7 +897,7 @@
         if ( storedValues instanceof BTreeRedirect )
         {
             BTree tree = getBTree( ( BTreeRedirect ) storedValues );
-            
+            Object first = null;
             while ( values.hasMore() )
             {
                 Object val = values.next();
@@ -905,10 +905,15 @@
                 if ( removeDupFromBTree( tree, val ) )
                 {
                     count--;
+                    
+                    if ( first == null )
+                    {
+                        first = val;
+                    }
                 }
             }
             
-            return storedValues;
+            return first;
         }
         
         throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );
@@ -944,7 +949,7 @@
         {
             BTree tree = getBTree( ( BTreeRedirect ) returned );
             this.count -= tree.size();
-            removeAll( tree );
+            return removeAll( tree );
         }
         
         throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );
@@ -1506,6 +1511,22 @@
                 }
                 else
                 {
+                    /*
+                     * Calls to getPrevious() will return a lower key even
+                     * if there exists a key equal to the one searched
+                     * for.  Since isGreaterThan when false really means
+                     * 'less than or equal to' we must check to see if 
+                     * the key in front is equal to the key argument provided.
+                     */
+                    success = browser.getNext( tuple );
+                    if ( success )
+                    {
+                        Object biggerKey = tuple.getKey();
+                        if ( comparator.compareValue( key, biggerKey ) == 0 )
+                        {
+                            return true;
+                        }
+                    }
                     return false;
                 }
             }
@@ -1530,12 +1551,13 @@
             boolean success = browser.getNext( tuple );
             if ( success )
             {
-                return true;
-            }
-            else
-            {
-                return false;
+                if ( comparator.compareValue( key, tuple.getKey() ) == 0 )
+                {
+                    return true;
+                }
             }
+
+            return false;
         }
         catch ( IOException e )
         {
@@ -1568,7 +1590,11 @@
     {
         try
         {
-            Object removed = tree.remove( value );
+            Object removed = null;
+            if ( tree.find( value ) != null )
+            {
+                removed = tree.remove( value );
+            }
             return null != removed;
         }
         catch ( IOException e )
@@ -1603,8 +1629,9 @@
     }
     
     
-    private void removeAll( BTree tree ) throws NamingException
+    private Object removeAll( BTree tree ) throws NamingException
     {
+        Object first = null;
         jdbm.helper.Tuple jdbmTuple = new jdbm.helper.Tuple();
         TupleBrowser browser;
         try
@@ -1613,6 +1640,10 @@
             while( browser.getNext( jdbmTuple ) )
             {
                 tree.remove( jdbmTuple.getKey() );
+                if ( first == null )
+                {
+                    first = jdbmTuple.getKey();
+                }
             }
         }
         catch ( IOException e )
@@ -1622,6 +1653,8 @@
             lne.setRootCause( e );
             throw lne;
         }
+        
+        return first;
     }
 }
 

Added: directory/branches/apacheds/optimization2/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsBTreeTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization2/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsBTreeTest.java?view=auto&rev=442107
==============================================================================
--- directory/branches/apacheds/optimization2/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsBTreeTest.java
(added)
+++ directory/branches/apacheds/optimization2/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsBTreeTest.java
Sun Sep 10 22:41:39 2006
@@ -0,0 +1,654 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
+
+
+import java.io.File;
+import java.io.Serializable;
+import java.math.BigInteger;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+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.schema.SerializableComparator;
+import org.apache.directory.shared.ldap.util.ArrayEnumeration;
+import org.apache.directory.shared.ldap.util.BigIntegerComparator;
+
+import jdbm.RecordManager;
+import jdbm.recman.BaseRecordManager;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for JdbmTable.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JdbmTableDupsBTreeTest extends TestCase implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+    private transient File tempFile = null;
+    private transient RecordManager rm = null;
+    private final BigIntegerComparator biComparator = new BigIntegerComparator();
+    private final SerializableComparator serializableComparator = new SerializableComparator(
"integerMatchingRule" )
+    {
+        private static final long serialVersionUID = 1L;
+
+        public int compare( Object o1, Object o2 )
+        {
+            return biComparator.compare( o1, o2 );
+        }
+    };
+    private TupleComparator comparator = new TupleComparator()
+    {
+        private static final long serialVersionUID = 1L;
+
+        public int compareKey( Object key1, Object key2 )
+        {
+            return biComparator.compare( key1, key2 );
+        }
+
+        public int compareValue( Object value1, Object value2 )
+        {
+            return biComparator.compare( value1, value2 );
+        }
+
+        public SerializableComparator getKeyComparator()
+        {
+            return serializableComparator;
+        }
+
+        public SerializableComparator getValueComparator()
+        {
+            return serializableComparator;
+        }
+    };
+
+
+    transient JdbmTable table;
+
+
+    /**
+     * Here's what the table looks like:
+     * <pre>
+     * .-.-.
+     * |1|0|
+     * |1|1|
+     * |1|2|
+     * |2|1|
+     * |4|1|
+     * |5|1|
+     * .-.-. 
+     * </pre>
+     */
+    public void setUp() throws Exception
+    {
+        tempFile = File.createTempFile( "jdbm", "test" );
+        rm = new BaseRecordManager( tempFile.getAbsolutePath() );
+
+        // make sure the table never uses a btree for duplicates
+        table = new JdbmTable( "test", true, 1, rm, comparator );
+
+        for ( BigInteger ii = BigInteger.ZERO; ii.intValue() < 3; ii = ii.add( BigInteger.ONE
) )
+        {
+            table.put( BigInteger.ONE, ii );
+        }
+
+        table.put( new BigInteger( "2" ), BigInteger.ONE );
+        table.put( new BigInteger( "4" ), BigInteger.ONE );
+        table.put( new BigInteger( "5" ), BigInteger.ONE );
+    }
+
+
+    /**
+     * Tests the has() methods for correct behavoir:
+     * <ul>
+     *   <li>has(Object)</li>
+     *   <li>has(Object, boolean)</li>
+     *   <li>has(Object, Object)</li>
+     *   <li>has(Object, Object, boolean)</li>
+     * </ul>
+     *
+     * @throws NamingException
+     */
+    public void testHas() throws Exception
+    {
+        // test the has( Object ) method
+        assertTrue( table.has( BigInteger.ONE ) );
+        assertTrue( table.has( new BigInteger("2") ) );
+        assertTrue( table.has( new BigInteger("4") ) );
+        assertTrue( table.has( new BigInteger("5") ) );
+        assertFalse( table.has( new BigInteger("3") ) );
+        assertFalse( table.has( BigInteger.ZERO ) );
+        assertFalse( table.has( new BigInteger( "999" ) ) );
+
+        // test the has( Object, Object ) method
+        assertTrue( table.has( BigInteger.ONE, BigInteger.ONE ) );
+        assertTrue( table.has( new BigInteger("2"), BigInteger.ONE ) );
+        assertTrue( table.has( new BigInteger("4"), BigInteger.ONE ) );
+        assertTrue( table.has( new BigInteger("5"), BigInteger.ONE ) );
+        assertFalse( table.has( new BigInteger("5"), BigInteger.ZERO ) );
+        assertFalse( table.has( new BigInteger("3"), BigInteger.ONE ) );
+        assertFalse( table.has( BigInteger.ONE, new BigInteger("999") ) );
+        assertFalse( table.has( new BigInteger( "999" ), BigInteger.ONE ) );
+
+        // test the has( Object, boolean ) method
+        assertFalse( table.has( BigInteger.ZERO, false ) ); // we do not have a key less
than or equal to 0
+        assertTrue( table.has( BigInteger.ONE, false ) ); // we do have a key less than or
equal to 1
+        assertTrue( table.has( BigInteger.ZERO, true ) ); // we do have a key greater than
or equal to 0
+        assertTrue( table.has( BigInteger.ONE, true ) ); // we do have a key greater than
or equal to 1
+        assertTrue( table.has( new BigInteger( "5" ), true ) ); // we do have a key greater
than or equal to 5
+        assertFalse( table.has( new BigInteger( "6" ), true ) ); // we do NOT have a key
greater than or equal to 11
+        assertFalse( table.has( new BigInteger( "999" ), true ) ); // we do NOT have a key
greater than or equal to 12
+
+        // test the has( Object, Object, boolean ) method
+        assertTrue( table.has( BigInteger.ONE, BigInteger.ZERO, true ) );
+        assertTrue( table.has( BigInteger.ONE, BigInteger.ONE, true ) );
+        assertTrue( table.has( BigInteger.ONE, new BigInteger("2"), true ) );
+        assertFalse( table.has( BigInteger.ONE, new BigInteger("3"), true ) );
+        assertTrue( table.has( BigInteger.ONE, BigInteger.ZERO, false ) );
+        assertFalse( table.has( BigInteger.ONE, new BigInteger("-1"), false ) );
+    }
+    
+    
+    /**
+     * Tests the count() methods for correct behavoir:
+     * <ul>
+     *   <li>count()</li>
+     *   <li>count(Object)</li>
+     *   <li>count(Object, boolean)</li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    public void testCount() throws Exception
+    {
+        // test the count() method
+        assertEquals( 6, table.count() );
+        
+        // test the count(Object) method
+        assertEquals( 3, table.count( BigInteger.ONE ) );
+        assertEquals( 0, table.count( BigInteger.ZERO ) );
+        assertEquals( 1, table.count( new BigInteger( "2" ) ) );
+        
+        // test the count( Object, boolean ) method 
+        // note for speed this count method returns the same as count()
+        assertEquals( table.count(), table.count( BigInteger.ONE, true ) );
+    }
+    
+    
+    /**
+     * Tests the get() method for correct behavoir.
+     * 
+     * @throws Exception
+     */
+    public void testGet() throws Exception
+    {
+        assertEquals( BigInteger.ZERO, table.get( BigInteger.ONE ) );
+        assertEquals( BigInteger.ONE, table.get( new BigInteger( "2" ) ) );
+        assertEquals( null, table.get( new BigInteger( "3" ) ) );
+        assertEquals( BigInteger.ONE, table.get( new BigInteger( "4" ) ) );
+        assertEquals( BigInteger.ONE, table.get( new BigInteger( "5" ) ) );
+    }
+    
+    
+    /**
+     * Tests the listTuples() methods for correct behavoir:
+     * <ul>
+     *   <li>listTuples()</li>
+     *   <li>listTuples(Object)</li>
+     *   <li>listTuples(Object,boolean)</li>
+     *   <li>listTuples(Object,Object,boolean)</li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    public void testListTuples() throws Exception
+    {
+        Tuple tuple;
+
+        // -------------------------------------------------------------------
+        // test the listTuples() method
+        // -------------------------------------------------------------------
+
+        NamingEnumeration tuples = table.listTuples();
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ZERO, tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( new BigInteger( "2" ), tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "2" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "4" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "5" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        
+        assertFalse( tuples.hasMore() );
+
+        // -------------------------------------------------------------------
+        // test the listTuples(Object) method
+        // -------------------------------------------------------------------
+
+        tuples = table.listTuples( BigInteger.ZERO );
+        assertFalse( tuples.hasMore() );
+
+        tuples = table.listTuples( new BigInteger( "2" ) );
+        assertTrue( tuples.hasMore() );
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "2" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        assertFalse( tuples.hasMore() );
+        
+        tuples = table.listTuples( BigInteger.ONE );
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ZERO, tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( new BigInteger( "2" ), tuple.getValue() );
+        
+        assertFalse( tuples.hasMore() );
+        
+        // -------------------------------------------------------------------
+        // test the listTuples(Object, boolean) method
+        // -------------------------------------------------------------------
+
+        tuples = table.listTuples( BigInteger.ZERO, false );
+        assertFalse( tuples.hasMore() );
+
+
+        tuples = table.listTuples( BigInteger.ONE, false );
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( new BigInteger( "2" ), tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ZERO, tuple.getValue() );
+        assertFalse( tuples.hasMore() );
+
+
+        tuples = table.listTuples( new BigInteger( "2" ), false );
+
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "2" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( new BigInteger( "2" ), tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ZERO, tuple.getValue() );
+        assertFalse( tuples.hasMore() );
+
+        
+        tuples = table.listTuples( new BigInteger( "6" ), true );
+        assertFalse( tuples.hasMore() );
+
+        
+        tuples = table.listTuples( new BigInteger( "5" ), true );
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "5" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        assertFalse( tuples.hasMore() );
+
+        
+        tuples = table.listTuples( new BigInteger( "4" ), true );
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "4" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "5" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        assertFalse( tuples.hasMore() );
+
+        // -------------------------------------------------------------------
+        // test the listTuples(Object,Object,boolean) method
+        // -------------------------------------------------------------------
+        
+        tuples = table.listTuples( BigInteger.ZERO, BigInteger.ZERO, true );
+        assertFalse( tuples.hasMore() );
+
+        tuples = table.listTuples( BigInteger.ZERO, BigInteger.ZERO, false );
+        assertFalse( tuples.hasMore() );
+        
+        tuples = table.listTuples( new BigInteger( "2" ), BigInteger.ZERO, false );
+        assertFalse( tuples.hasMore() );
+        
+        tuples = table.listTuples( new BigInteger( "2" ), new BigInteger( "99" ), true );
+        assertFalse( tuples.hasMore() );
+        
+        tuples = table.listTuples( new BigInteger( "2" ), BigInteger.ONE, false );
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "2" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        assertFalse( tuples.hasMore() );
+
+        tuples = table.listTuples( new BigInteger( "2" ), new BigInteger( "99" ), false );
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( new BigInteger( "2" ), tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+        assertFalse( tuples.hasMore() );
+
+        
+        tuples = table.listTuples( BigInteger.ONE, new BigInteger( "3" ), true );
+        assertFalse( tuples.hasMore() );
+
+
+        tuples = table.listTuples( BigInteger.ONE, new BigInteger( "-1" ), false );
+        assertFalse( tuples.hasMore() );
+
+
+        tuples = table.listTuples( BigInteger.ONE, new BigInteger( "1" ), true );
+
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( new BigInteger( "2" ), tuple.getValue() );
+
+        assertFalse( tuples.hasMore() );
+
+        
+        tuples = table.listTuples( BigInteger.ONE, new BigInteger( "1" ), false );
+
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ONE, tuple.getValue() );
+
+        assertTrue( tuples.hasMore() ) ;
+        tuple = ( Tuple ) tuples.next();
+        assertEquals( BigInteger.ONE, tuple.getKey() );
+        assertEquals( BigInteger.ZERO, tuple.getValue() );
+
+        assertFalse( tuples.hasMore() );
+
+    }
+
+    
+    /**
+     * Tests the listValues() method for correct behavoir.
+     */
+    public void testListValues() throws Exception
+    {
+        // -------------------------------------------------------------------
+        // test the listValues(Object) method
+        // -------------------------------------------------------------------
+
+        NamingEnumeration values = table.listValues( BigInteger.ZERO );
+        assertFalse( values.hasMore() );
+
+        values = table.listValues( new BigInteger( "2" ) );
+        assertTrue( values.hasMore() );
+        Object value = values.next();
+        assertEquals( BigInteger.ONE, value );
+        assertFalse( values.hasMore() );
+        
+        values = table.listValues( BigInteger.ONE );
+        assertTrue( values.hasMore() ) ;
+        value = values.next();
+        assertEquals( BigInteger.ZERO, value );
+        
+        assertTrue( values.hasMore() ) ;
+        value = values.next();
+        assertEquals( BigInteger.ONE, value );
+        
+        assertTrue( values.hasMore() ) ;
+        value = values.next();
+        assertEquals( new BigInteger( "2" ), value );
+        
+        assertFalse( values.hasMore() );
+    }
+    
+    
+    /**
+     * Tests the put() methods for correct behavior:
+     * <ul>
+     *   <li>put(Object, Object)</li>
+     *   <li>put(Object, NamingEnumeration)</li>
+     * </ul>
+     */
+    public void testPut() throws Exception
+    {
+        // put(Object,Object) already tested in setUp() tests the 
+        // this instead tests the NamingEnumeration overload
+        
+        NamingEnumeration values = new ArrayNE( new Object[] {
+            new BigInteger( "3" ),
+            new BigInteger( "4" ),
+            new BigInteger( "5" ),
+            new BigInteger( "6" ),
+        } );
+        
+        table.put( BigInteger.ONE, values );
+        assertFalse( values.hasMore() );
+        
+        values = table.listValues( BigInteger.ONE );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( BigInteger.ZERO, values.next() );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( BigInteger.ONE, values.next() );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( new BigInteger( "2" ), values.next() );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( new BigInteger( "3" ), values.next() );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( new BigInteger( "4" ), values.next() );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( new BigInteger( "5" ), values.next() );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( new BigInteger( "6" ), values.next() );
+        assertFalse( values.hasMore() );
+
+    
+        values = new ArrayNE( new Object[] {
+            new BigInteger( "3" ),
+            new BigInteger( "4" ),
+            new BigInteger( "5" ),
+            new BigInteger( "6" ),
+        } );
+        
+        table.put( BigInteger.ZERO, values );
+        assertFalse( values.hasMore() );
+        
+        values = table.listValues( BigInteger.ZERO );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( new BigInteger( "3" ), values.next() );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( new BigInteger( "4" ), values.next() );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( new BigInteger( "5" ), values.next() );
+        
+        assertTrue( values.hasMore() );
+        assertEquals( new BigInteger( "6" ), values.next() );
+        assertFalse( values.hasMore() );
+    }
+    
+    
+    /**
+     * Tests the remove(Object) for correct behavoir:
+     */
+    public void testRemoveObject() throws Exception
+    {
+        // -------------------------------------------------------------------
+        // tests the remove(Object) method
+        // -------------------------------------------------------------------
+
+        try
+        {
+            table.remove( BigInteger.ZERO );
+            fail( "should not get here trying to remove non-existent key" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+        }
+        
+        Object value = table.remove( new BigInteger( "2" ) );
+        assertEquals( BigInteger.ONE, value );
+        assertEquals( 5, table.count() );
+        
+        value = table.remove( BigInteger.ONE );
+        assertEquals( BigInteger.ZERO, value ); // return first value of dups
+        assertEquals( 2, table.count() );
+    }
+    
+    
+    /**
+     * Tests the remove(Object,Object) for correct behavoir:
+     */
+    public void testRemoveObjectObject() throws Exception
+    {
+        // -------------------------------------------------------------------
+        // tests the remove(Object) method
+        // -------------------------------------------------------------------
+
+        Object value = table.remove( BigInteger.ZERO, BigInteger.ZERO );
+        assertNull( value );
+        
+        value = table.remove( new BigInteger( "2" ), BigInteger.ONE );
+        assertEquals( BigInteger.ONE, value );
+        assertEquals( 5, table.count() );
+        
+        value = table.remove( BigInteger.ONE, new BigInteger( "2" ) );
+        assertEquals( new BigInteger( "2" ), value ); 
+        assertEquals( 4, table.count() );
+    }
+    
+    
+    /**
+     * Tests the remove(Object,NamingEnumeration) for correct behavoir:
+     */
+    public void testRemoveObjectNamingEnumeration() throws Exception
+    {
+        NamingEnumeration values = new ArrayNE( new Object[] {
+            new BigInteger( "1" ),
+            new BigInteger( "2" )
+        } );
+        
+        Object value = table.remove( BigInteger.ONE, values );
+        assertEquals( BigInteger.ONE, value );
+        assertEquals( 4, table.count() );
+    }
+    
+    
+//    private void printTuples( NamingEnumeration tuples ) throws NamingException
+//    {
+//        while ( tuples.hasMore() )
+//        {
+//            Tuple tuple = ( Tuple ) tuples.next();
+//            System.out.println( "(" + tuple.getKey() + ", " + tuple.getValue() + ")" );
+//        }
+//    }
+    
+    
+    class ArrayNE extends ArrayEnumeration implements NamingEnumeration
+    {
+        public ArrayNE( Object[] array )
+        {
+            super( array );
+        }
+
+        public void close() throws NamingException
+        {
+        }
+
+        public boolean hasMore() throws NamingException
+        {
+            return hasMoreElements();
+        }
+
+        public Object next() throws NamingException
+        {
+            return nextElement();
+        }
+    }
+}
+
+    
\ No newline at end of file

Modified: directory/branches/apacheds/optimization2/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization2/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java?view=diff&rev=442107&r1=442106&r2=442107
==============================================================================
--- directory/branches/apacheds/optimization2/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java
(original)
+++ directory/branches/apacheds/optimization2/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java
Sun Sep 10 22:41:39 2006
@@ -132,7 +132,7 @@
 
         JdbmMasterTable master = new JdbmMasterTable( recMan );
         AttributeType attributeType = bootstrapRegistries.getAttributeTypeRegistry().lookup(
"apacheUpdn" );
-        JdbmIndex idIndex = new JdbmIndex( attributeType, partitionDirectory, 1000 );
+        JdbmIndex idIndex = new JdbmIndex( attributeType, partitionDirectory, 1000, 1000
);
 
         out.println( "#---------------------" );
         NamingEnumeration list = master.listTuples();

Modified: directory/branches/apacheds/optimization2/server-tools/src/main/manifest/MANIFEST.MF
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization2/server-tools/src/main/manifest/MANIFEST.MF?view=diff&rev=442107&r1=442106&r2=442107
==============================================================================
--- directory/branches/apacheds/optimization2/server-tools/src/main/manifest/MANIFEST.MF (original)
+++ directory/branches/apacheds/optimization2/server-tools/src/main/manifest/MANIFEST.MF Sun
Sep 10 22:41:39 2006
@@ -2,16 +2,16 @@
 Main-Class: org.apache.directory.server.tools.ApachedsTools
 Class-Path: logger.jar daemon.jar bootstrapper.jar 
  ../lib/antlr-2.7.2.jar 
- ../lib/apacheds-kerberos-shared-1.0-RC4.jar 
- ../lib/apacheds-protocol-changepw-1.0-RC4.jar 
- ../lib/apacheds-protocol-shared-1.0-RC4.jar 
- ../lib/apacheds-protocol-kerberos-1.0-RC4.jar 
- ../lib/apacheds-protocol-ldap-1.0-RC4.jar 
- ../lib/apacheds-protocol-ntp-1.0-RC4.jar 
- ../lib/apacheds-core-1.0-RC4.jar 
- ../lib/apacheds-core-shared-1.0-RC4.jar 
- ../lib/apacheds-server-jndi-1.0-RC4.jar 
- ../lib/apacheds-server-main-1.0-RC4.jar 
+ ../lib/apacheds-kerberos-shared-1.0-SNAPSHOT.jar 
+ ../lib/apacheds-protocol-changepw-1.0-SNAPSHOT.jar 
+ ../lib/apacheds-protocol-shared-1.0-SNAPSHOT.jar 
+ ../lib/apacheds-protocol-kerberos-1.0-SNAPSHOT.jar 
+ ../lib/apacheds-protocol-ldap-1.0-SNAPSHOT.jar 
+ ../lib/apacheds-protocol-ntp-1.0-SNAPSHOT.jar 
+ ../lib/apacheds-core-1.0-SNAPSHOT.jar 
+ ../lib/apacheds-core-shared-1.0-SNAPSHOT.jar 
+ ../lib/apacheds-server-jndi-1.0-SNAPSHOT.jar 
+ ../lib/apacheds-server-main-1.0-SNAPSHOT.jar 
  ../lib/commons-collections-3.0.jar 
  ../lib/commons-lang-2.0.jar 
  ../lib/commons-logging-1.0.4.jar 



Mime
View raw message