directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r613292 - in /directory/sandbox/akarasulu/bigbang/apacheds: btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ jdbm-store/src/...
Date Fri, 18 Jan 2008 21:53:18 GMT
Author: akarasulu
Date: Fri Jan 18 13:53:16 2008
New Revision: 613292

URL: http://svn.apache.org/viewvc?rev=613292&view=rev
Log:
more unit tests and some bug fixes

Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java?rev=613292&r1=613291&r2=613292&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
Fri Jan 18 13:53:16 2008
@@ -180,7 +180,8 @@
 
 
     /**
-     * Puts a record into this Table.
+     * Puts a record into this Table.  Null is not allowed for keys or values
+     * and should result in an IllegalArgumentException.
      *
      * @param key the key of the record
      * @param value the value of the record.
@@ -188,6 +189,7 @@
      * exist before.
      * @throws IOException if there is a failure to read or write to
      * the underlying Db
+     * @throws IllegalArgumentException if a null key or value is used
      */
     V put( K key, V value ) throws IOException;
 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?rev=613292&r1=613291&r2=613292&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
Fri Jan 18 13:53:16 2008
@@ -267,12 +267,7 @@
         // Handle the use of a BTree for storing duplicates
         // -------------------------------------------------------------------
 
-        if ( values instanceof BTreeRedirect )
-        {
-            return getBTree( ( BTreeRedirect ) values ).size();
-        }
-        
-        throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );
+        return getBTree( ( BTreeRedirect ) values ).size();
     }
 
 
@@ -308,32 +303,20 @@
         {
             //noinspection unchecked
             TreeSet<V> set = ( TreeSet<V> ) values;
-            
-            if ( set.size() == 0 )
-            {
-                return null;
-            }
-            else
-            {
-                return set.first();
-            }
+            return set.first();
         }
 
-        if ( values instanceof BTreeRedirect )
+        // Handle values if they are stored in another BTree
+        BTree tree = getBTree( ( BTreeRedirect ) values );
+        
+        if ( tree.size() == 0 )
         {
-            BTree tree = getBTree( ( BTreeRedirect ) values );
-            
-            if ( tree.size() == 0 )
-            {
-                return null;
-            }
-            else
-            {
-                return firstKey( tree );
-            }
+            return null;
+        }
+        else
+        {
+            return firstKey( tree );
         }
-        
-        throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );
     }
 
     
@@ -358,18 +341,34 @@
             {
                 return true;
             }
-            // val >= val and test is for greater then return true
-            else if ( comparator.compareValue( ( V ) rval, val ) >= 1 && isGreaterThan
)
-            {
-                return true;
-            }
-            // val <= val and test is for lesser then return true
-            else if ( comparator.compareValue( ( V ) rval, val ) <= 1 && !isGreaterThan
)
-            {
-                return true;
-            }
-
-            return false;
+            
+            /*
+             * Any comparisons below here would require use to use a value 
+             * comparator to determine ordering.  However since this Table
+             * has duplicate keys disabled (multiple values), there is no
+             * way to set a value comparator.  Perhaps this can change but 
+             * for now this will throw an unsupported operation exception.
+             * 
+             * If a value comparator is available then the following code 
+             * below will allow us to return the correct values.
+             */
+            
+            throw new UnsupportedOperationException( "Unfortunately this Table without duplicates
enabled " +
+            		"does not contain a value comparator which is needed to answer your ordering
question." );
+            
+//            // val >= val and test is for greater then return true
+//            else if ( comparator.compareValue( ( V ) rval, val ) >= 1 && isGreaterThan
)
+//            {
+//                return true;
+//            }
+//            // val <= val and test is for lesser then return true
+//            else if ( comparator.compareValue( ( V ) rval, val ) <= 1 && !isGreaterThan
)
+//            {
+//                return true;
+//            }
+//
+//            return false;
+            
         }
 
         Object values = getRaw( key );
@@ -384,11 +383,6 @@
             TreeSet set = ( TreeSet ) values;
             SortedSet subset;
     
-            if ( set.size() == 0 )
-            {
-                return false;
-            }
-    
             if ( isGreaterThan )
             {
                 subset = set.tailSet( val );
@@ -401,13 +395,9 @@
             return subset.size() > 0 || set.contains( val );
         }
         
-        if ( values instanceof BTreeRedirect )
-        {
-            BTree tree = getBTree( ( BTreeRedirect ) values );
-            return tree.size() != 0 && btreeHas( tree, val, isGreaterThan );
-        }
-        
-        throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );
+        // last option is to try a btree with BTreeRedirects
+        BTree tree = getBTree( ( BTreeRedirect ) values );
+        return tree.size() != 0 && btreeHas( tree, val, isGreaterThan );
     }
     
 
@@ -520,12 +510,7 @@
             return ( ( TreeSet ) values ).contains( value );
         }
         
-        if ( values instanceof BTreeRedirect )
-        {
-            return btreeHas( getBTree( ( BTreeRedirect ) values ), value );
-        }
-        
-        throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );
+        return btreeHas( getBTree( ( BTreeRedirect ) values ), value );
     }
     
 
@@ -545,6 +530,11 @@
     @SuppressWarnings("unchecked")
     public V put( K key, V value ) throws IOException
     {
+        if ( value == null || key == null )
+        {
+            throw new IllegalArgumentException( "null for key or value is not valid" );
+        }
+        
         V replaced;
 
         if ( ! allowsDuplicates )
@@ -596,18 +586,13 @@
             return null;
         }
         
-        if ( values instanceof BTreeRedirect )
+        BTree tree = getBTree( ( BTreeRedirect ) values );
+        
+        if ( insertDupIntoBTree( tree, value ) )
         {
-            BTree tree = getBTree( ( BTreeRedirect ) values );
-            
-            if ( value != null insertDupIntoBTree( tree, value ) )
-            {
-                count++;
-            }
-            return null;
+            count++;
         }
-        
-        throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );
+        return null;
     }
     
 
@@ -624,6 +609,7 @@
             // Remove the value only if it is the same as value.
             if ( oldValue != null && oldValue.equals( value ) )
             {
+                bt.remove( key );
                 count--;
                 return oldValue;
             }
@@ -645,7 +631,14 @@
             // If removal succeeds then remove if set is empty else replace it
             if ( set.remove( value ) )
             {
-                bt.insert( key, set, true );
+                if ( set.isEmpty() )
+                {
+                    bt.remove( key );
+                }
+                else
+                {
+                    bt.insert( key, set, true );
+                }
                 count--;
                 return value;
             }
@@ -655,24 +648,18 @@
 
         // TODO might be nice to add code here that reverts to a TreeSet
         // if the number of duplicates falls below the numDupLimit value
-        if ( values instanceof BTreeRedirect )
+        BTree tree = getBTree( ( BTreeRedirect ) values );
+        if ( removeDupFromBTree( tree, value ) )
         {
-            BTree tree = getBTree( ( BTreeRedirect ) values );
-            
-            if ( removeDupFromBTree( tree, value ) )
+            if ( tree.size() == 0 )
             {
-                if ( tree.size() == 0 )
-                {
-                }
-                
-                count--;
-                return value;
             }
             
-            return null;
+            count--;
+            return value;
         }
         
-        throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );
+        return null;
     }
 
 
@@ -703,14 +690,9 @@
             return set.first();
         }
         
-        if ( returned instanceof BTreeRedirect )
-        {
-            BTree tree = getBTree( ( BTreeRedirect ) returned );
-            this.count -= tree.size();
-            return removeAll( tree );
-        }
-        
-        throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );
+        BTree tree = getBTree( ( BTreeRedirect ) returned );
+        this.count -= tree.size();
+        return removeAll( tree );
     }
 
 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java?rev=613292&r1=613291&r2=613292&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
Fri Jan 18 13:53:16 2008
@@ -54,7 +54,7 @@
     private static final Logger LOG = LoggerFactory.getLogger( KeyCursorTest.class.getSimpleName()
);
     private static final String TEST_OUTPUT_PATH = "test.output.path";
 
-    transient Table<String,String> table;
+    transient Table<Integer,Integer> table;
     transient File dbFile;
     transient RecordManager recman;
 
@@ -73,7 +73,7 @@
 
         // gosh this is a terrible use of a global static variable
         SerializableComparator.setRegistry( new MockComparatorRegistry() );
-        table = new JdbmTable<String,String>( "test", recman, new SerializableComparator<String>(
"" ), null, null );
+        table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>(
"" ), null, null );
         LOG.debug( "Created new table and populated it with data" );
     }
 
@@ -93,10 +93,10 @@
     @Test
     public void testCloseReopen() throws Exception
     {
-        table.put( "key", "value" );
+        table.put( 1, 2 );
         table.close();
-        table = new JdbmTable<String,String>( "test", recman, new SerializableComparator<String>(
"" ), null, null );
-        assertEquals( "value", table.get( "key" ) );
+        table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>(
"" ), null, null );
+        assertTrue( 2 == table.get( 1 ) );
     }
 
     
@@ -128,21 +128,21 @@
     {
         // Test the count methods
         assertEquals( 0, table.count() );
-        assertEquals( 0, table.count( "1" ) );
+        assertEquals( 0, table.count( 1 ) );
 
         // Test get method
-        assertNull( table.get( "0" ) );
+        assertNull( table.get( 0 ) );
         
         // Test remove methods
-        assertNull( table.remove( "1" ) );
+        assertNull( table.remove( 1 ) );
         
         // Test has operations
-        assertFalse( table.has( "1" ) );
-        assertFalse( table.has( "1", "0" ) );
-        assertFalse( table.has( "1", true ) );
-        assertFalse( table.has( "1", false ) );
-        assertFalse( table.has( "1", "0", true ) );
-        assertFalse( table.has( "1", "0", false ) );
+        assertFalse( table.has( 1 ) );
+        assertFalse( table.has( 1, 0 ) );
+        assertFalse( table.has( 1, true ) );
+        assertFalse( table.has( 1, false ) );
+        assertFalse( table.has( 1, 0, true ) );
+        assertFalse( table.has( 1, 0, false ) );
     }
 
     
@@ -150,19 +150,13 @@
     public void testLoadData() throws Exception
     {
         // add some data to it
-        table.put( "0", "zero" );
-        table.put( "1", "one" );
-        table.put( "2", "two" );
-        table.put( "3", "three" );
-        table.put( "4", "four" );
-        table.put( "5", "five" );
-        table.put( "6", "six" );
-        table.put( "7", "seven" );
-        table.put( "8", "eight" );
-        table.put( "9", "nine" );
+        for ( int ii = 0; ii < 10; ii++ )
+        {
+            table.put( ii, ii );
+        }
         
         assertEquals( 10, table.count() );
-        assertEquals( 1, table.count( "0" ) );
+        assertEquals( 1, table.count( 0 ) );
         
         /*
          * If counts are exact then we can test for exact values.  Again this 
@@ -172,20 +166,115 @@
         
         if ( table.isCountExact() )
         {
-            assertEquals( 5, table.lessThanCount( "5" ) );
-            assertEquals( 4, table.greaterThanCount( "5" ) );
+            assertEquals( 5, table.lessThanCount( 5 ) );
+            assertEquals( 4, table.greaterThanCount( 5 ) );
         }
         else
         {
-            assertEquals( 10, table.lessThanCount( "5" ) );
-            assertEquals( 10, table.greaterThanCount( "5" ) );
+            assertEquals( 10, table.lessThanCount( 5 ) );
+            assertEquals( 10, table.greaterThanCount( 5 ) );
+        }
+    }
+    
+    
+    /**
+     * Let's test keys with a null or lack of any values.
+     */
+    @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 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.has( -1 , true ) );
+        assertFalse( table.has( -1 , false ) );
+        
+        assertTrue( table.has( 0 ) );
+        assertTrue( table.has( 0 , true ) );
+        assertTrue( table.has( 0 , false ) );
+        
+        assertTrue( table.has( SIZE-1 ) );
+        assertTrue( table.has( SIZE-1, true ) );
+        assertTrue( table.has( SIZE-1, false ) );
+        
+        assertFalse( table.has( SIZE ) );
+        assertFalse( table.has( SIZE, true ) );
+        assertTrue( table.has( SIZE, false ) );
+        
+        assertTrue( table.has( 1, 1, true ) );
+        assertTrue( table.has( 1, 1, false ) );
+        
+        try
+        {
+            assertTrue( table.has( 1, 2, false ) );
+            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 StringComparator comparator = new StringComparator();
+        private Comparator comparator = new Comparator<Integer>()
+        {
+            public int compare( Integer i1, Integer i2 )
+            {
+                return i1.compareTo( i2 );
+            }
+        };
+        
 
         public String getSchemaName( String oid ) throws NamingException
         {

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java?rev=613292&r1=613291&r2=613292&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
Fri Jan 18 13:53:16 2008
@@ -55,11 +55,10 @@
 public class JdbmTableWithDuplicatesTest
 {
     private static final Logger LOG = LoggerFactory.getLogger( KeyCursorTest.class.getSimpleName()
);
-    private static final String EMPTY_STRING = "";
     private static final String TEST_OUTPUT_PATH = "test.output.path";
-    private static final int DUP_LIMIT = 15; // point at which the JDBM table starts using
btrees
+    private static final int SIZE = 15;
     
-    transient Table<String,String> table;
+    transient Table<Integer,Integer> table;
     transient File dbFile;
     transient RecordManager recman;
 
@@ -78,11 +77,11 @@
         // gosh this is a terrible use of a global static variable
         SerializableComparator.setRegistry( new MockComparatorRegistry() );
 
-        TupleComparator<String,String> comparator = 
-                new DefaultTupleComparator<String,String>(
-                        new SerializableComparator<String>( "" ),
-                        new SerializableComparator<String>( "" ) );
-        table = new JdbmTable<String,String>( "test", true, DUP_LIMIT, recman, comparator,
null, null );
+        TupleComparator<Integer,Integer> comparator = 
+                new DefaultTupleComparator<Integer,Integer>(
+                        new SerializableComparator<Integer>( "" ),
+                        new SerializableComparator<Integer>( "" ) );
+        table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator,
null, null );
         LOG.debug( "Created new table and populated it with data" );
     }
 
@@ -102,15 +101,14 @@
     @Test
     public void testCloseReopen() throws Exception
     {
-        table.put( "key", "value" );
+        table.put( 1, 2 );
         table.close();
-        TupleComparator<String,String> comparator = 
-            new DefaultTupleComparator<String,String>(
-                    new SerializableComparator<String>( "" ),
-                    new SerializableComparator<String>( "" ) );
-        table = new JdbmTable<String,String>( "test", true, DUP_LIMIT, recman, comparator,
null, null );
-        Object storedValue = table.get( "key" );
-        assertEquals( "value", storedValue );
+        TupleComparator<Integer,Integer> comparator = 
+            new DefaultTupleComparator<Integer,Integer>(
+                    new SerializableComparator<Integer>( "" ),
+                    new SerializableComparator<Integer>( "" ) );
+        table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator,
null, null );
+        assertTrue( 2 == table.get( 1 ) );
     }
 
     
@@ -142,41 +140,117 @@
     {
         // Test the count methods
         assertEquals( 0, table.count() );
-        assertEquals( 0, table.count( "1" ) );
+        assertEquals( 0, table.count( 1 ) );
 
         // Test get method
-        assertNull( table.get( "0" ) );
+        assertNull( table.get( 0 ) );
         
         // Test remove methods
-        assertNull( table.remove( "1" ) );
+        assertNull( table.remove( 1 ) );
         
         // Test has operations
-        assertFalse( table.has( "1" ) );
-        assertFalse( table.has( "1", "0" ) );
-        assertFalse( table.has( "1", true ) );
-        assertFalse( table.has( "1", false ) );
-        assertFalse( table.has( "1", "0", true ) );
-        assertFalse( table.has( "1", "0", false ) );
+        assertFalse( table.has( 1 ) );
+        assertFalse( table.has( 1, 0 ) );
+        assertFalse( table.has( 1, true ) );
+        assertFalse( table.has( 1, false ) );
+        assertFalse( table.has( 1, 0, true ) );
+        assertFalse( table.has( 1, 0, false ) );
+    }
+    
+    
+    @Test
+    public void testHas() throws Exception
+    {
+        assertFalse( table.has( 1 ) );
+        
+        for ( int ii = 0; ii < SIZE; ii++ )
+        {
+            table.put( 1, ii );
+        }
+        assertEquals( SIZE, table.count() );
+
+        assertTrue( table.has( 1 ) );
+        assertTrue( table.has( 1, 0 ) );
+        assertFalse( table.has( 1, SIZE ) );
+
+        assertTrue( table.has( 1, 0, true ) );
+        assertTrue( table.has( 1, 0, false ) );
+        assertFalse( table.has( 1, -1, false ) );
+
+        assertTrue( table.has( 1, SIZE-1, true ) );
+        assertTrue( table.has( 1, SIZE-1, false ) );
+        assertTrue( table.has( 1, SIZE-1, true ) );
+        assertTrue( table.has( 1, SIZE, false ) );
+        assertFalse( table.has( 1, SIZE, true ) );
+        assertFalse( table.has( 1, SIZE ) );
+
+        // let's go over the this limit now and ask the same questions
+        table.put( 1, SIZE );
+
+        assertTrue( table.has( 1 ) );
+        assertTrue( table.has( 1, 0 ) );
+        assertTrue( table.has( 1, SIZE ) );
+
+        assertTrue( table.has( 1, 0, true ) );
+        assertTrue( table.has( 1, 0, false ) );
+        assertFalse( table.has( 1, -1, false ) );
+
+        assertTrue( table.has( 1, SIZE, true ) );
+        assertTrue( table.has( 1, SIZE, false ) );
+        assertTrue( table.has( 1, SIZE, true ) );
+        assertTrue( table.has( 1, SIZE+1, false ) );
+        assertFalse( table.has( 1, SIZE+1, true ) );
+        assertFalse( table.has( 1, SIZE+1 ) );
+        
+        table.remove( 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.has( -1 , true ) );
+        assertFalse( table.has( -1 , false ) );
+        
+        assertTrue( table.has( 0 ) );
+        assertTrue( table.has( 0 , true ) );
+        assertTrue( table.has( 0 , false ) );
+        
+        assertTrue( table.has( SIZE-1 ) );
+        assertTrue( table.has( SIZE-1, true ) );
+        assertTrue( table.has( SIZE-1, false ) );
+        
+        assertFalse( table.has( SIZE ) );
+        assertFalse( table.has( SIZE, true ) );
+        assertTrue( table.has( SIZE, false ) );
     }
 
     
     @Test
+    public void testRemove() throws Exception
+    {
+        table.put( 1, 1 );
+        table.put( 1, 2 );
+        table.remove( 1 );
+    }
+    
+    
+    @Test
     public void testLoadData() throws Exception
     {
         // add some data to it
-        table.put( "0", "zero" );
-        table.put( "1", "one" );
-        table.put( "2", "two" );
-        table.put( "3", "three" );
-        table.put( "4", "four" );
-        table.put( "5", "five" );
-        table.put( "6", "six" );
-        table.put( "7", "seven" );
-        table.put( "8", "eight" );
-        table.put( "9", "nine" );
-
-        assertEquals( 10, table.count() );
-        assertEquals( 1, table.count( "0" ) );
+        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 
@@ -186,13 +260,13 @@
         
         if ( table.isCountExact() )
         {
-            assertEquals( 5, table.lessThanCount( "5" ) );
-            assertEquals( 4, table.greaterThanCount( "5" ) );
+            assertEquals( 5, table.lessThanCount( 5 ) );
+            assertEquals( 9, table.greaterThanCount( 5 ) );
         }
         else
         {
-            assertEquals( 10, table.lessThanCount( "5" ) );
-            assertEquals( 10, table.greaterThanCount( "5" ) );
+            assertEquals( SIZE, table.lessThanCount( 5 ) );
+            assertEquals( SIZE, table.greaterThanCount( 5 ) );
         }
     }
     
@@ -200,38 +274,48 @@
     @Test
     public void testDuplicateLimit() throws Exception
     {
-        for ( int ii = 0; ii < DUP_LIMIT-1; ii++ )
+        for ( int ii = 0; ii < SIZE-1; ii++ )
         {
-            table.put( "key", String.valueOf( ii ) );
+            table.put( 1, ii );
         }
-        assertEquals( DUP_LIMIT-1, table.count() );
+        assertEquals( SIZE-1, table.count() );
         
-        table.put( "key", String.valueOf( DUP_LIMIT-1 ) );
-        assertEquals( DUP_LIMIT, table.count() );
+        table.put( 1, SIZE-1 );
+        assertEquals( SIZE, table.count() );
         
         // this switches to B+Trees in JDBM implementations
-        table.put( "key", String.valueOf( DUP_LIMIT ) );
-        assertEquals( DUP_LIMIT+1, table.count() );
+        table.put( 1, SIZE );
+        assertEquals( SIZE+1, table.count() );
         
-        table.put( "key", String.valueOf( DUP_LIMIT+1 ) );
-        assertEquals( DUP_LIMIT+2, table.count() );
+        table.put( 1, SIZE+1 );
+        assertEquals( SIZE+2, table.count() );
         
         
         // now start removing and see what happens 
 
-        table.remove( "key", String.valueOf( DUP_LIMIT+1 ) );
-        assertFalse( table.has( "key", String.valueOf( DUP_LIMIT+1 ) ) );
-        assertEquals( DUP_LIMIT+1, table.count() );
-    
-        table.remove( "key", String.valueOf( DUP_LIMIT ) );
-        assertFalse( table.has( "key", String.valueOf( DUP_LIMIT ) ) );
-        assertEquals( DUP_LIMIT, table.count() );
+        table.remove( 1, SIZE+1 );
+        assertFalse( table.has( 1, SIZE+1 ) );
+        assertEquals( SIZE+1, table.count() );
+    
+        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 = DUP_LIMIT-1; ii >= 0; ii-- )
+        for ( int ii = SIZE-1; ii >= 0; ii-- )
         {
-            table.remove( "key", String.valueOf( 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() );
     }
     
     
@@ -239,35 +323,47 @@
      * Let's test keys with a null or lack of any values.
      */
     @Test
-    public void testNullOrEmptyValueAfterDuplicateLimit() throws Exception
+    public void testNullOrEmptyKeyValueAfterDuplicateLimit() throws Exception
     {
         testDuplicateLimit();
         assertEquals( 0, table.count() );
-        table.put( "key", null );
-        assertEquals( 1, table.count() );
-        assertEquals( null, table.get( "key" ) );
+        
+        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( "key" );
-        table.put( "key", "1" );
-        table.put( "key", "2" );
-        assertEquals( 2, table.count( "key" ) );
-        table.remove( "key", "1" );
-        assertEquals( 1, table.count( "key" ) );
-        assertEquals( "2", table.get( "key" ) );
-
-        
-        table.remove( "key", "2" );
-        String remainingValue = table.get( "key" );
-        assertNull( remainingValue );
-        assertEquals( 0, table.count( "key" ) );
-        assertTrue( table.has( "key" ) );
-        
-        table.remove( "key", "1" );
-        remainingValue = table.get( "key" );
-        assertNull( remainingValue );
-        assertEquals( 0, table.count( "key" ) );
-        assertTrue( table.has( "key" ) );
+        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 ) );
     }
     
     
@@ -275,40 +371,58 @@
      * Let's test keys with a null or lack of any values.
      */
     @Test
-    public void testNullOrEmptyValue() throws Exception
+    public void testNullOrEmptyKeyValue() throws Exception
     {
         assertEquals( 0, table.count() );
-        table.put( "key", null );
-        assertEquals( 1, table.count() );
-        assertEquals( null, table.get( "key" ) );
+        
+        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( "key" );
-        table.put( "key", "1" );
-        table.put( "key", "2" );
-        assertEquals( 2, table.count( "key" ) );
-        table.remove( "key", "1" );
-        assertEquals( 1, table.count( "key" ) );
-        assertEquals( "2", table.get( "key" ) );
-
-        
-        table.remove( "key", "2" );
-        String remainingValue = table.get( "key" );
-        assertNull( remainingValue );
-        assertEquals( 0, table.count( "key" ) );
-        assertTrue( table.has( "key" ) );
-        
-        table.remove( "key", "1" );
-        remainingValue = table.get( "key" );
-        assertNull( remainingValue );
-        assertEquals( 0, table.count( "key" ) );
-        assertTrue( table.has( "key" ) );
+        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 StringComparator comparator = new StringComparator();
+        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
         {



Mime
View raw message