directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r891735 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/test/java/org/apache/directory/server/schema/ ldap/src/main/java/org/apache/directory/shared/ldap/schema/ ldap/src/main/java/org/apache/directory/shared/ldap/sche...
Date Thu, 17 Dec 2009 14:48:01 GMT
Author: elecharny
Date: Thu Dec 17 14:47:52 2009
New Revision: 891735

URL: http://svn.apache.org/viewvc?rev=891735&view=rev
Log:
o Fixed some missing action when deleting MR : the back references to C/N/S weren't deleted,
causing the MR tests to fail.
o Cleaned up the AT comments
o Adding a test for MR deletion

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java?rev=891735&r1=891734&r2=891735&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
Thu Dec 17 14:47:52 2009
@@ -129,6 +129,44 @@
     }
 
 
+    private boolean isMRPresent( SchemaManager schemaManager, String oid )
+    {
+        try
+        {
+            MatchingRule matchingRule = schemaManager.lookupMatchingRuleRegistry( oid );
+
+            return matchingRule != null;
+        }
+        catch ( NoSuchAttributeException nsae )
+        {
+            return false;
+        }
+        catch ( NamingException ne )
+        {
+            return false;
+        }
+    }
+
+    
+    private boolean isCPresent( SchemaManager schemaManager, String oid )
+    {
+        try
+        {
+            LdapComparator<?> comparator = schemaManager.lookupComparatorRegistry(
oid );
+
+            return comparator != null;
+        }
+        catch ( NoSuchAttributeException nsae )
+        {
+            return false;
+        }
+        catch ( NamingException ne )
+        {
+            return false;
+        }
+    }
+
+
     //=========================================================================
     // For each test, we will check many different things.
     // If the test is successful, we want to know if the SchemaObject
@@ -334,6 +372,52 @@
         assertEquals( ctrSize, schemaManager.getComparatorRegistry().size() );
         assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
     }
+
+
+    /**
+     * Check that a Comparator which has been used by a deleted MatchingRule
+     * can be removed
+     */
+    @Test
+    public void testDeleteExistingComaparatorUsedByRemovedMatchingRule() throws Exception
+    {
+        SchemaManager schemaManager = loadSchema( "system" );
+        int ctrSize = schemaManager.getComparatorRegistry().size();
+        int mrrSize = schemaManager.getMatchingRuleRegistry().size();
+        int goidSize = schemaManager.getGlobalOidRegistry().size();
+        
+        String OID = "2.5.13.33";
+
+        // Check that the MR and C are present
+        assertTrue( isMRPresent( schemaManager, OID ) );
+        assertTrue( isCPresent( schemaManager, OID ) );
+
+        // Now try to remove the C
+        LdapComparator<?> lc = schemaManager.lookupComparatorRegistry( OID );
+        
+        // shouldn't be deleted cause there is a MR associated with it
+        assertFalse( schemaManager.delete( lc ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertFalse( errors.isEmpty() );
+        assertTrue( errors.get( 0 ) instanceof LdapSchemaViolationException );
+
+        // Now delete the using MR : it should be OK
+        MatchingRule mr = new MatchingRule( OID );
+        assertTrue( schemaManager.delete( mr ) );
+
+        assertEquals( mrrSize - 1, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
+
+        assertFalse( isMRPresent( schemaManager, OID ) );
+        
+        // and try to delete the Comparator again
+        assertTrue( schemaManager.delete( lc ) );
+
+        assertFalse( isCPresent( schemaManager, OID ) );
+        assertEquals( ctrSize - 1, schemaManager.getComparatorRegistry().size() );
+        assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
+    }
     
 
     //=========================================================================

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java?rev=891735&r1=891734&r2=891735&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java
Thu Dec 17 14:47:52 2009
@@ -696,11 +696,11 @@
             // Remove the attributeType from the oid/normalizer map
             attributeTypeRegistry.removeMappingFor( this );
 
-            // Register this AttributeType into the Descendant map
+            // Unregister this AttributeType into the Descendant map
             attributeTypeRegistry.unregisterDescendants( this, superior );
 
             /**
-             * Add the AT references (using and usedBy) : 
+             * Remove the AT references (using and usedBy) : 
              * AT -> MR (for EQUALITY, ORDERING and SUBSTR)
              * AT -> S
              * AT -> AT

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java?rev=891735&r1=891734&r2=891735&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
Thu Dec 17 14:47:52 2009
@@ -28,6 +28,7 @@
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.comparators.ComparableComparator;
 import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
+import org.apache.directory.shared.ldap.schema.registries.MatchingRuleRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
 
 
@@ -184,6 +185,46 @@
 
 
     /**
+     * Remove the MatchingRule from the registries, updating the references to
+     * other SchemaObject.
+     * 
+     * If one of the referenced SchemaObject does not exist (), 
+     * an exception is thrown.
+     *
+     * @param registries The Registries
+     * @exception If the MatchingRule is not valid 
+     */
+    public void removeFromRegistries( List<Throwable> errors, Registries registries
) throws NamingException
+    {
+        if ( registries != null )
+        {
+            MatchingRuleRegistry matchingRuleRegistry = registries.getMatchingRuleRegistry();
+
+            /**
+             * Remove the MR references (using and usedBy) : 
+             * MR -> C
+             * MR -> N
+             * MR -> S
+             */
+            if ( ldapComparator != null )
+            {
+                registries.delReference( this, ldapComparator );
+            }
+
+            if ( ldapSyntax != null )
+            {
+                registries.delReference( this, ldapSyntax );
+            }
+
+            if ( normalizer != null )
+            {
+                registries.delReference( this, normalizer );
+            }
+        }
+    }
+
+
+    /**
      * Gets the LdapSyntax used by this MatchingRule.
      * 
      * @return the LdapSyntax of this MatchingRule

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java?rev=891735&r1=891734&r2=891735&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
Thu Dec 17 14:47:52 2009
@@ -2596,12 +2596,22 @@
 
                 try
                 {
-                    SchemaObject copy = clone.globalOidRegistry.getSchemaObject( original.getOid()
);
-                    SchemaObjectWrapper newWrapper = new SchemaObjectWrapper( copy );
-                    objects.add( newWrapper );
+                    if ( ! ( original instanceof LoadableSchemaObject ) )
+                    {
+                        SchemaObject copy = clone.globalOidRegistry.getSchemaObject( original.getOid()
);
+                        SchemaObjectWrapper newWrapper = new SchemaObjectWrapper( copy );
+                        objects.add( newWrapper );
+                    }
+                    else
+                    {
+                        SchemaObjectWrapper newWrapper = new SchemaObjectWrapper( original
);
+                        objects.add(  newWrapper );
+                    }
                 }
                 catch ( NamingException ne )
                 {
+                    int i = 0;
+                    i++;
                     // Nothing to do
                 }
             }



Mime
View raw message