directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r440970 - in /directory/branches/apacheds/1.0/core: ./ src/main/java/org/apache/directory/server/core/partition/impl/btree/ src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ src/test/java/org/apache/directory/server/...
Date Thu, 07 Sep 2006 04:11:41 GMT
Author: akarasulu
Date: Wed Sep  6 21:11:40 2006
New Revision: 440970

URL: http://svn.apache.org/viewvc?view=rev&rev=440970
Log:
Changes ...

 o ignoring clover generated files
 o corrected some documentation on Table interface
 o added more test cases to test listTuples() methods
 o caught and fixed bug with listTuples(Object,Object,boolean)


Modified:
    directory/branches/apacheds/1.0/core/   (props changed)
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
    directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java

Propchange: directory/branches/apacheds/1.0/core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Sep  6 21:11:40 2006
@@ -1,4 +1,5 @@
 target
+.clover
 .wtpmodules
 .settings
 .deployables

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java?view=diff&rev=440970&r1=440969&r2=440970
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
Wed Sep  6 21:11:40 2006
@@ -290,7 +290,7 @@
 
     /**
      * Sets a cursor to the first record in the Table with a key equal to
-     * the key argument whose value is greater/less than or equal to key and
+     * the key argument whose value is greater/less than or equal to val and
      * enables single next steps across all records with key equal to key.
      * Hence this cursor will only iterate over duplicate keys where values are
      * less than or greater than or equal to val.

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?view=diff&rev=440970&r1=440969&r2=440970
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
Wed Sep  6 21:11:40 2006
@@ -24,6 +24,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -956,8 +957,15 @@
 
         if ( isGreaterThan )
         {
-            Object[] objs = new Object[set.size()];
-            objs = set.tailSet( val ).toArray( objs );
+            Set tailSet = set.tailSet( val );
+            
+            if ( tailSet.isEmpty() )
+            {
+                return new EmptyEnumeration();
+            }
+            
+            Object[] objs = new Object[tailSet.size()];
+            objs = tailSet.toArray( objs );
             ArrayIterator iterator = new ArrayIterator( objs );
             return new TupleEnumeration( key, iterator );
         }
@@ -967,7 +975,7 @@
             // a list.  They will be in ascending order so we need to reverse
             // the list after adding val which is not included in headSet.
             SortedSet headset = set.headSet( val );
-            ArrayList list = new ArrayList( set.size() + 1 );
+            ArrayList list = new ArrayList( headset.size() + 1 );
             list.addAll( headset );
 
             // Add largest value (val) if it is in the set.  TreeSet.headSet

Modified: directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java?view=diff&rev=440970&r1=440969&r2=440970
==============================================================================
--- directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
(original)
+++ directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
Wed Sep  6 21:11:40 2006
@@ -24,6 +24,10 @@
 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.BigIntegerComparator;
@@ -84,6 +88,19 @@
     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" );
@@ -92,7 +109,7 @@
         // make sure the table never uses a btree for duplicates
         table = new JdbmTable( "test", true, rm, comparator );
 
-        for ( BigInteger ii = BigInteger.ZERO; ii.intValue() < 12; ii = ii.add( BigInteger.ONE
) )
+        for ( BigInteger ii = BigInteger.ZERO; ii.intValue() < 3; ii = ii.add( BigInteger.ONE
) )
         {
             table.put( BigInteger.ONE, ii );
         }
@@ -140,17 +157,299 @@
         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( "11" ), true ) ); // we do have a key greater
than or equal to 11
-        assertFalse( table.has( new BigInteger( "12" ), true ) ); // we do NOT have a key
greater than or equal to 12
-
-
+        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("11"), true ) );
-        assertFalse( table.has( BigInteger.ONE, new BigInteger("12"), 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() );
+
+    }
+    
+    
+    private void printTuples( NamingEnumeration tuples ) throws NamingException
+    {
+        while ( tuples.hasMore() )
+        {
+            Tuple tuple = ( Tuple ) tuples.next();
+            System.out.println( "(" + tuple.getKey() + ", " + tuple.getValue() + ")" );
+        }
+    }
 }
+
+    
\ No newline at end of file



Mime
View raw message