directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r442055 - in /directory/trunks/apacheds: ./ 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/directory/ser...
Date Mon, 11 Sep 2006 01:11:43 GMT
Author: akarasulu
Date: Sun Sep 10 18:11:42 2006
New Revision: 442055

URL: http://svn.apache.org/viewvc?view=rev&rev=442055
Log:
add more test cases for better test coverage, updating doco

Added:
    directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDupsTest.java
      - copied unchanged from r442053, directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDupsTest.java
Modified:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
    directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
    directory/trunks/apacheds/pom.xml

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java?view=diff&rev=442055&r1=442054&r2=442055
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
Sun Sep 10 18:11:42 2006
@@ -139,6 +139,9 @@
      * depends on the fact that duplicate key values are sorted according to
      * a valid value comparator function.
      *
+     * If the table does not support duplicates then an 
+     * UnsupportedOperationException is thrown.
+     *
      * @param key the key Object
      * @param val the value Object to compare values to
      * @param isGreaterThan boolean for greater than or less then comparison
@@ -229,6 +232,7 @@
      * duplicates.
      *
      * @param key the key of the records to remove
+     * @return the first value removed
      * @throws NamingException if there is a failure to read or write to
      * the underlying Db
      */
@@ -294,6 +298,9 @@
      * 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.
+     *
+     * If the table does not support duplicates then an 
+     * UnsupportedOperationException is thrown.
      *
      * @param key the key to use to position this cursor to record with a key
      * equal to it.

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?view=diff&rev=442055&r1=442054&r2=442055
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
Sun Sep 10 18:11:42 2006
@@ -627,10 +627,14 @@
             return null;
         }
 
+        Object oldValue = getRaw( key );
+        
         // Remove the value only if it is the same as value.
-        if ( getRaw( key ).equals( value ) )
+        if ( oldValue != null && oldValue.equals( value ) )
         {
-            return removeRaw( key );
+            removeRaw( key );
+            count--;
+            return oldValue;
         }
 
         return null;
@@ -659,7 +663,7 @@
 
                 if ( values.hasMore() )
                 {
-                    throw new UnsupportedOperationException( "Attempting to put duplicate
keys into table " + name
+                    throw new UnsupportedOperationException( "Attempting to remove duplicate
keys from table " + name
                         + " which does not support duplicates" );
                 }
 
@@ -685,11 +689,18 @@
          * is in the set and remove it if it is present.  We decrement the 
          * counter while doing so.
          */
+        Object firstValue = null;
         while ( values.hasMore() )
         {
             Object val = values.next();
+            
+            // get the first value
+            if ( firstValue == null )
+            {
+                firstValue = val;
+            }
 
-            if ( !set.contains( val ) )
+            if ( set.contains( val ) )
             {
                 set.remove( val );
                 count--;
@@ -697,7 +708,8 @@
         }
 
         // Return the raw TreeSet and put the changed one back.
-        return putRaw( key, set, true );
+        putRaw( key, set, true );
+        return firstValue;
     }
 
 
@@ -925,28 +937,30 @@
 
         if ( !allowsDuplicates )
         {
-            Object rval = getRaw( key );
-
-            if ( null == rval ) // key does not exist so return nothing
-            {
-                return new EmptyEnumeration();
-            }
-            else if ( val.equals( rval ) ) // val == rval return tuple
-            {
-                return new SingletonEnumeration( new Tuple( key, val ) );
-            }
-            // val >= val and test is for greater then return tuple
-            else if ( comparator.compareValue( val, rval ) >= 1 && isGreaterThan
)
-            {
-                return new SingletonEnumeration( new Tuple( key, val ) );
-            }
-            // val <= val and test is for lesser then return tuple
-            else if ( comparator.compareValue( val, rval ) <= 1 && !isGreaterThan
)
-            {
-                return new SingletonEnumeration( new Tuple( key, val ) );
-            }
-
-            return new EmptyEnumeration();
+            throw new UnsupportedOperationException( "Cannot list tuples over duplicates
on table that " +
+                    "does not support duplicates." );
+//            Object rval = getRaw( key );
+//
+//            if ( null == rval ) // key does not exist so return nothing
+//            {
+//                return new EmptyEnumeration();
+//            }
+//            else if ( val.equals( rval ) ) // val == rval return tuple
+//            {
+//                return new SingletonEnumeration( new Tuple( key, val ) );
+//            }
+//            // val >= val and test is for greater then return tuple
+//            else if ( comparator.compareValue( val, rval ) >= 1 && isGreaterThan
)
+//            {
+//                return new SingletonEnumeration( new Tuple( key, val ) );
+//            }
+//            // val <= val and test is for lesser then return tuple
+//            else if ( comparator.compareValue( val, rval ) <= 1 && !isGreaterThan
)
+//            {
+//                return new SingletonEnumeration( new Tuple( key, val ) );
+//            }
+//
+//            return new EmptyEnumeration();
         }
 
         set = ( TreeSet ) getRaw( key );

Modified: directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java?view=diff&rev=442055&r1=442054&r2=442055
==============================================================================
--- directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
(original)
+++ directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
Sun Sep 10 18:11:42 2006
@@ -30,6 +30,7 @@
 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;
@@ -440,14 +441,212 @@
         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() + ")" );
+//        }
+//    }
     
     
-    private void printTuples( NamingEnumeration tuples ) throws NamingException
+    class ArrayNE extends ArrayEnumeration implements NamingEnumeration
     {
-        while ( tuples.hasMore() )
+        public ArrayNE( Object[] array )
+        {
+            super( array );
+        }
+
+        public void close() throws NamingException
+        {
+        }
+
+        public boolean hasMore() throws NamingException
+        {
+            return hasMoreElements();
+        }
+
+        public Object next() throws NamingException
         {
-            Tuple tuple = ( Tuple ) tuples.next();
-            System.out.println( "(" + tuple.getKey() + ", " + tuple.getValue() + ")" );
+            return nextElement();
         }
     }
 }

Modified: directory/trunks/apacheds/pom.xml
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/pom.xml?view=diff&rev=442055&r1=442054&r2=442055
==============================================================================
--- directory/trunks/apacheds/pom.xml (original)
+++ directory/trunks/apacheds/pom.xml Sun Sep 10 18:11:42 2006
@@ -5,7 +5,7 @@
   <parent>
     <groupId>org.apache.directory</groupId>
     <artifactId>build</artifactId>
-    <version>1.0.5-SNAPSHOT</version>
+    <version>1.0.5</version>
   </parent>
 
   <groupId>org.apache.directory.server</groupId>



Mime
View raw message