directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r440944 - in /directory/branches/apacheds/1.0: core-unit/src/test/java/org/apache/directory/server/core/ core/src/main/java/org/apache/directory/server/core/partition/impl/btree/ core/src/test/java/org/apache/directory/server/core/partition...
Date Thu, 07 Sep 2006 02:08:15 GMT
Author: akarasulu
Date: Wed Sep  6 19:08:14 2006
New Revision: 440944

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

 o Adding additional test cases for greaterThan/lessThan tests
 o Found and fixed severe bug where greaterThan/lessThan was reversed when 
   indices were not used on the integerMatch based attribute being searched on
 o Added additional test case to test duplicate key based behavoir of JdbmTable


Added:
    directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
Modified:
    directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java

Modified: directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java?view=diff&rev=440944&r1=440943&r2=440944
==============================================================================
--- directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java
(original)
+++ directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java
Wed Sep  6 19:08:14 2006
@@ -70,20 +70,23 @@
         // Alter the partition configuration to index gidNumber
         // -------------------------------------------------------------------
 
-        MutablePartitionConfiguration sysConf = new MutablePartitionConfiguration();
-        sysConf.setName( "system" );
-        Attributes attrs = new BasicAttributes( "objectClass", "top", true );
-        attrs.get( "objectClass" ).add( "organizationalUnit" );
-        attrs.put( "ou", "system" );
-        sysConf.setContextEntry( attrs );
-        sysConf.setSuffix( "ou=system" );
-        Set indices = new HashSet();
-        indices.addAll( sysConf.getIndexedAttributes() );
-        MutableIndexConfiguration idxConfig = new MutableIndexConfiguration();
-        idxConfig.setAttributeId( "gidNumber" );
-        indices.add( idxConfig );
-        sysConf.setIndexedAttributes( indices );
-        configuration.setSystemPartitionConfiguration( sysConf );
+        if ( getName().indexOf( "WithIndices" ) != -1 )
+        {
+            MutablePartitionConfiguration sysConf = new MutablePartitionConfiguration();
+            sysConf.setName( "system" );
+            Attributes attrs = new BasicAttributes( "objectClass", "top", true );
+            attrs.get( "objectClass" ).add( "organizationalUnit" );
+            attrs.put( "ou", "system" );
+            sysConf.setContextEntry( attrs );
+            sysConf.setSuffix( "ou=system" );
+            Set indices = new HashSet();
+            indices.addAll( sysConf.getIndexedAttributes() );
+            MutableIndexConfiguration idxConfig = new MutableIndexConfiguration();
+            idxConfig.setAttributeId( "gidNumber" );
+            indices.add( idxConfig );
+            sysConf.setIndexedAttributes( indices );
+            configuration.setSystemPartitionConfiguration( sysConf );
+        }
         
         super.setUp();
         
@@ -173,6 +176,86 @@
 
     
     public void testGreaterThanSearch() throws Exception
+    {
+        Set results = searchGroups( "(gidNumber>=0)" );
+        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+        results = searchGroups( "(gidNumber>=1)" );
+        assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+        results = searchGroups( "(gidNumber>=3)" );
+        assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+        results = searchGroups( "(gidNumber>=6)" );
+        assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+    }
+
+    
+    public void testLessThanSearchWithIndices() throws Exception
+    {
+        Set results = searchGroups( "(gidNumber<=5)" );
+        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+        results = searchGroups( "(gidNumber<=4)" );
+        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+        results = searchGroups( "(gidNumber<=3)" );
+        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+        results = searchGroups( "(gidNumber<=0)" );
+        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+        results = searchGroups( "(gidNumber<=-1)" );
+        assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+    }
+
+    
+    public void testGreaterThanSearchWithIndices() throws Exception
     {
         Set results = searchGroups( "(gidNumber>=0)" );
         assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java?view=diff&rev=440944&r1=440943&r2=440944
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
Wed Sep  6 19:08:14 2006
@@ -200,7 +200,7 @@
                 Object value = normalizer.normalize( list.next() );
 
                 // Found a value that is greater than or equal to the ava value
-                if ( 0 >= comparator.compare( value, filterValue ) )
+                if ( 0 >= comparator.compare( filterValue, value ) )
                 {
                     return true;
                 }
@@ -213,7 +213,7 @@
                 Object value = normalizer.normalize( list.next() );
 
                 // Found a value that is less than or equal to the ava value
-                if ( 0 <= comparator.compare( value, filterValue ) )
+                if ( 0 <= comparator.compare( filterValue, value ) )
                 {
                     return true;
                 }

Added: 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=auto&rev=440944
==============================================================================
--- directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
(added)
+++ directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java
Wed Sep  6 19:08:14 2006
@@ -0,0 +1,156 @@
+/*
+ *  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 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;
+
+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 JdbmTableDupsTreeSetTest 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;
+
+
+    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, rm, comparator );
+
+        for ( BigInteger ii = BigInteger.ZERO; ii.intValue() < 12; 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( "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
+
+
+
+        // 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, BigInteger.ZERO, false ) );
+        assertFalse( table.has( BigInteger.ONE, new BigInteger("-1"), false ) );
+    }
+}



Mime
View raw message