You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/10/27 22:34:17 UTC

svn commit: rev 55732 - in incubator/directory/eve/trunk/backend/core: . src/java/org/apache/eve src/java/org/apache/eve/jndi src/java/org/apache/eve/jndi/ibs src/test/org/apache/eve/jndi src/test/org/apache/eve/jndi/ibs

Author: akarasulu
Date: Wed Oct 27 13:34:16 2004
New Revision: 55732

Added:
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/OperationalAttributesTest.java
Modified:
   incubator/directory/eve/trunk/backend/core/project.properties
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/AbstractContextPartition.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/BackingStore.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/EveBackendSubsystem.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/RootNexus.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveJndiProvider.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/CreateContextTest.java
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/EveContextFactoryTest.java
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ModifyContextTest.java
Log:
Changes ...

 o added sync() and close() operations that tunnel down to database ops
 o added EveBackendSystem interface methods to sync and shutdown
 o added new JNDI properties to environment to sync and shutdown Eve
 o added code to shutdown and cleanup Eve after all test cases
 o cleaned up bugs in OperationalAttributeService which is working very well now 
 o cleaned up test cases a little bit

Note ...

 o found a major bug in Comparator serialization code that is a blocker



Modified: incubator/directory/eve/trunk/backend/core/project.properties
==============================================================================
--- incubator/directory/eve/trunk/backend/core/project.properties	(original)
+++ incubator/directory/eve/trunk/backend/core/project.properties	Wed Oct 27 13:34:16 2004
@@ -1,4 +1,4 @@
-maven.junit.fork=no
+maven.junit.fork=yes
 
 maven.javadoc.private=true
 maven.javadoc.overview=src/java/org/apache/eve/schema/overview.html

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/AbstractContextPartition.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/AbstractContextPartition.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/AbstractContextPartition.java	Wed Oct 27 13:34:16 2004
@@ -365,4 +365,16 @@
     {
         db.move( oldChildDn, newParentDn, newRdn, deleteOldRdn );
     }
+
+
+    public void sync() throws NamingException
+    {
+        db.sync();
+    }
+
+
+    public void close() throws NamingException
+    {
+        db.close();
+    }
 }

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/BackingStore.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/BackingStore.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/BackingStore.java	Wed Oct 27 13:34:16 2004
@@ -215,6 +215,10 @@
      */
     void move( Name oriChildName, Name newParentName, String newRn,
                boolean deleteOldRn ) throws NamingException;
+    
+    void sync() throws NamingException;
+
+    void close() throws NamingException;
 }
 
 

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/EveBackendSubsystem.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/EveBackendSubsystem.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/EveBackendSubsystem.java	Wed Oct 27 13:34:16 2004
@@ -21,4 +21,8 @@
      * @throws NamingException if something goes wrong
      */
     LdapContext getLdapContext( Hashtable env ) throws NamingException;
+
+    void sync() throws NamingException;
+
+    void shutdown() throws NamingException;
 }

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/RootNexus.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/RootNexus.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/RootNexus.java	Wed Oct 27 13:34:16 2004
@@ -288,16 +288,47 @@
         ContextPartition backend = getBackend( oldChildDn );
         backend.move( oldChildDn, newParentDn, newRdn, deleteOldRdn );
     }
-    
+
+
+    /**
+     * @see BackingStore#sync()
+     */
+    public void sync() throws NamingException
+    {
+        Iterator list = this.backends.values().iterator();
+        while ( list.hasNext() )
+        {
+            BackingStore store = ( BackingStore ) list.next();
+            store.sync();
+        }
+    }
+
+
+    /**
+     * @see BackingStore#close()
+     */
+    public void close() throws NamingException
+    {
+        Iterator list = this.backends.values().iterator();
+        while ( list.hasNext() )
+        {
+            BackingStore store = ( BackingStore ) list.next();
+            store.sync();
+            store.close();
+        }
+
+        s_singleton = null;
+    }
+
 
     // ------------------------------------------------------------------------
     // Private Methods
     // ------------------------------------------------------------------------
-    
-    
+
+
     /**
      * Gets the backend partition associated with a dn.
-     * 
+     *
      * @param dn the name to resolve to a backend
      * @return the backend partition associated with the dn
      * @throws NamingException if the name cannot be resolved to a backend

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java	Wed Oct 27 13:34:16 2004
@@ -39,6 +39,8 @@
  */
 public class EveContextFactory implements InitialContextFactory
 {
+    public static final String SHUTDOWN_OP_ENV = "eve.operation.shutdown";
+    public static final String SYNC_OP_ENV = "eve.operation.sync";
     /** key base for a set of user indices provided as comma sep list of attribute names or oids */
     public static final String USER_INDICES_ENV_BASE = "eve.user.db.indices";
     /** the path to eve's working directory - relative or absolute */
@@ -95,6 +97,20 @@
      */
     public Context getInitialContext( Hashtable env ) throws NamingException
     {
+        if ( env.containsKey( SHUTDOWN_OP_ENV ) )
+        {
+            provider.shutdown();
+            provider = null;
+            initialEnv = null;
+            return null;
+        }
+
+        if ( env.containsKey( SYNC_OP_ENV ) )
+        {
+            provider.sync();
+            return null;
+        }
+
         // fire up the backend subsystem if we need to
         if ( null == provider )
         {

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveJndiProvider.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveJndiProvider.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveJndiProvider.java	Wed Oct 27 13:34:16 2004
@@ -55,6 +55,9 @@
     /** PartitionNexus proxy wrapping nexus to inject services */
     private PartitionNexus proxy = null;
 
+    /** whether or not this instance has been shutdown */
+    private boolean isShutdown = false;
+
 
     // ------------------------------------------------------------------------
     // Constructor
@@ -112,7 +115,42 @@
      */
     public LdapContext getLdapContext( Hashtable aenv ) throws NamingException
     {
+        if ( this.isShutdown )
+        {
+            throw new IllegalStateException( "Eve has been shutdown!" );
+        }
+
         return new EveLdapContext( proxy, aenv );
+    }
+
+
+    public void sync() throws NamingException
+    {
+        if ( this.isShutdown )
+        {
+            throw new IllegalStateException( "Eve has been shutdown!" );
+        }
+
+        this.nexus.sync();
+    }
+
+
+    public void shutdown() throws NamingException
+    {
+        if ( this.isShutdown )
+        {
+            throw new IllegalStateException( "Eve has been shutdown!" );
+        }
+
+        this.nexus.sync();
+        this.nexus.close();
+        this.nexus = null;
+        this.proxy = null;
+        this.before = null;
+        this.after = null;
+        this.afterFailure = null;
+        this.isShutdown = true;
+        s_singleton = null;
     }
 
 

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java	Wed Oct 27 13:34:16 2004
@@ -201,7 +201,10 @@
 
         if ( invocation.getState() == InvocationStateEnum.POSTINVOCATION )
         {
-            filter( ( Attributes ) invocation.getReturnValue() );
+            Attributes attributes = ( Attributes ) invocation.getReturnValue();
+            Attributes retval = ( Attributes ) attributes.clone();
+            filter( retval );
+            invocation.setReturnValue( retval );
         }
     }
 
@@ -214,6 +217,11 @@
 
         if ( invocation.getState() == InvocationStateEnum.POSTINVOCATION )
         {
+            if ( searchControls.getReturningAttributes() != null )
+            {
+                return;
+            }
+
             SearchResultEnumeration enum ;
             ResultFilteringEnumeration retval;
             enum = ( SearchResultEnumeration ) invocation.getReturnValue();

Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java	Wed Oct 27 13:34:16 2004
@@ -66,6 +66,20 @@
     protected void tearDown() throws Exception
     {
         super.tearDown();
+        Hashtable env = new Hashtable();
+        env.put( Context.PROVIDER_URL, "ou=system" );
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.eve.jndi.EveContextFactory" );
+        env.put( EveContextFactory.SHUTDOWN_OP_ENV, "" );
+
+        try
+        {
+            InitialContext initialContext = new InitialContext( env );
+        }
+        catch( Exception e )
+        {
+
+        }
+
         sysRoot = null;
         File file = new File( "target/eve" );
         FileUtils.deleteDirectory( file );

Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/CreateContextTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/CreateContextTest.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/CreateContextTest.java	Wed Oct 27 13:34:16 2004
@@ -140,18 +140,43 @@
         DirContext ctx = null;
 
         /*
-         * fail on ou=testing01,ou=system
+         * create ou=testing00,ou=system
          */
         attributes = new BasicAttributes();
         attribute = new BasicAttribute( "objectClass" );
         attribute.add( "top" );
         attribute.add( "organizationalUnit" );
         attributes.put( attribute );
-        attributes.put( "ou", "testing01" );
+        attributes.put( "ou", "testing00" );
+        ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
+        assertNotNull( ctx );
 
+        ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
+        assertNotNull( ctx );
+
+        attributes = ctx.getAttributes( "" );
+        assertNotNull( attributes );
+        assertEquals( "testing00", attributes.get( "ou" ).get() );
+        attribute = attributes.get( "objectClass" );
+        assertNotNull( attribute );
+        assertTrue( attribute.contains( "top" ) );
+        assertTrue( attribute.contains( "organizationalUnit" ) );
+
+
+        /*
+         * fail on recreate attempt for ou=testing00,ou=system
+         */
+        attributes = new BasicAttributes();
+        attribute = new BasicAttribute( "objectClass" );
+        attribute.add( "top" );
+        attribute.add( "organizationalUnit" );
+        attributes.put( attribute );
+        attributes.put( "ou", "testing00" );
+
+        ctx = null;
         try
         {
-            ctx = sysRoot.createSubcontext( "ou=testing01", attributes );
+            ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
             fail( "Attept to create exiting context should fail!" );
         }
         catch ( NamingException e )

Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/EveContextFactoryTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/EveContextFactoryTest.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/EveContextFactoryTest.java	Wed Oct 27 13:34:16 2004
@@ -50,4 +50,18 @@
         assertTrue( attribute.contains( "top" ) );
         assertTrue( attribute.contains( "organizationalUnit" ) );
     }
+
+
+    public void testSetupTeardown() throws NamingException
+    {
+        assertNotNull( sysRoot );
+
+        Attributes attributes = sysRoot.getAttributes( "" );
+        assertNotNull( attributes );
+        assertEquals( "system", attributes.get( "ou" ).get() );
+        Attribute attribute = attributes.get( "objectClass" );
+        assertNotNull( attribute );
+        assertTrue( attribute.contains( "top" ) );
+        assertTrue( attribute.contains( "organizationalUnit" ) );
+    }
 }

Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ModifyContextTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ModifyContextTest.java	(original)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ModifyContextTest.java	Wed Oct 27 13:34:16 2004
@@ -17,10 +17,7 @@
 package org.apache.eve.jndi;
 
 
-import javax.naming.directory.DirContext;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.Attribute;
+import javax.naming.directory.*;
 import javax.naming.NamingException;
 
 
@@ -37,9 +34,105 @@
     {
         super.setUp();
 
-        CreateContextTest createContextTest = new CreateContextTest();
-        createContextTest.setUp();
-        createContextTest.testCreateContexts();
+        try
+        {
+            /*
+             * create ou=testing00,ou=system
+             */
+            Attributes attributes = new BasicAttributes();
+            Attribute attribute = new BasicAttribute( "objectClass" );
+            attribute.add( "top" );
+            attribute.add( "organizationalUnit" );
+            attributes.put( attribute );
+            attributes.put( "ou", "testing00" );
+            DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
+            assertNotNull( ctx );
+
+            ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
+            assertNotNull( ctx );
+
+            attributes = ctx.getAttributes( "" );
+            assertNotNull( attributes );
+            assertEquals( "testing00", attributes.get( "ou" ).get() );
+            attribute = attributes.get( "objectClass" );
+            assertNotNull( attribute );
+            assertTrue( attribute.contains( "top" ) );
+            assertTrue( attribute.contains( "organizationalUnit" ) );
+
+            /*
+             * create ou=testing01,ou=system
+             */
+            attributes = new BasicAttributes();
+            attribute = new BasicAttribute( "objectClass" );
+            attribute.add( "top" );
+            attribute.add( "organizationalUnit" );
+            attributes.put( attribute );
+            attributes.put( "ou", "testing01" );
+            ctx = sysRoot.createSubcontext( "ou=testing01", attributes );
+            assertNotNull( ctx );
+
+            ctx = ( DirContext ) sysRoot.lookup( "ou=testing01" );
+            assertNotNull( ctx );
+
+            attributes = ctx.getAttributes( "" );
+            assertNotNull( attributes );
+            assertEquals( "testing01", attributes.get( "ou" ).get() );
+            attribute = attributes.get( "objectClass" );
+            assertNotNull( attribute );
+            assertTrue( attribute.contains( "top" ) );
+            assertTrue( attribute.contains( "organizationalUnit" ) );
+
+            /*
+             * create ou=testing02,ou=system
+             */
+            attributes = new BasicAttributes();
+            attribute = new BasicAttribute( "objectClass" );
+            attribute.add( "top" );
+            attribute.add( "organizationalUnit" );
+            attributes.put( attribute );
+            attributes.put( "ou", "testing02" );
+            ctx = sysRoot.createSubcontext( "ou=testing02", attributes );
+            assertNotNull( ctx );
+
+            ctx = ( DirContext ) sysRoot.lookup( "ou=testing02" );
+            assertNotNull( ctx );
+
+            attributes = ctx.getAttributes( "" );
+            assertNotNull( attributes );
+            assertEquals( "testing02", attributes.get( "ou" ).get() );
+            attribute = attributes.get( "objectClass" );
+            assertNotNull( attribute );
+            assertTrue( attribute.contains( "top" ) );
+            assertTrue( attribute.contains( "organizationalUnit" ) );
+
+            /*
+             * create ou=subtest,ou=testing01,ou=system
+             */
+            ctx = ( DirContext ) sysRoot.lookup( "ou=testing01" );
+
+            attributes = new BasicAttributes();
+            attribute = new BasicAttribute( "objectClass" );
+            attribute.add( "top" );
+            attribute.add( "organizationalUnit" );
+            attributes.put( attribute );
+            attributes.put( "ou", "subtest" );
+            ctx = ctx.createSubcontext( "ou=subtest", attributes );
+            assertNotNull( ctx );
+
+            ctx = ( DirContext ) sysRoot.lookup( "ou=subtest,ou=testing01" );
+            assertNotNull( ctx );
+
+            attributes = ctx.getAttributes( "" );
+            assertNotNull( attributes );
+            assertEquals( "subtest", attributes.get( "ou" ).get() );
+            attribute = attributes.get( "objectClass" );
+            assertNotNull( attribute );
+            assertTrue( attribute.contains( "top" ) );
+            assertTrue( attribute.contains( "organizationalUnit" ) );
+        }
+        catch( NamingException e )
+        {
+        }
     }
 
 
@@ -54,18 +147,16 @@
         attributes = ctx.getAttributes( "" );
         assertTrue( attributes.get( "ou" ).contains( "testCases" ) );
 
-        Attribute attribute;
-
-        attribute = attributes.get( "creatorsName" );
-        assertNotNull( attribute );
+        Attribute attribute = attributes.get( "creatorsName" );
+        assertNull( attribute );
 
         attribute = attributes.get( "createTimestamp" );
-        assertNotNull( attribute );
+        assertNull( attribute );
 
         attribute = attributes.get( "modifiersName" );
-        assertNotNull( attribute );
+        assertNull( attribute );
 
         attributes.get( "modifyTimestamp" );
-        assertNotNull( attribute );
+        assertNull( attribute );
     }
 }

Added: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/OperationalAttributesTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/OperationalAttributesTest.java	Wed Oct 27 13:34:16 2004
@@ -0,0 +1,85 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.eve.jndi.ibs;
+
+
+import javax.naming.directory.*;
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+
+import org.apache.ldap.common.message.DerefAliasesEnum;
+import org.apache.eve.jndi.AbstractJndiTest;
+
+
+/**
+ * Tests the methods on JNDI contexts that are analogous to entry modify
+ * operations in LDAP.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class OperationalAttributesTest extends AbstractJndiTest
+{
+    private static final String CREATORS_NAME = "creatorsName";
+    private static final String CREATE_TIMESTAMP = "createTimestamp";
+
+
+    public void testModifyOperationalOpAttrs() throws NamingException
+    {
+        /*
+         * create ou=testing00,ou=system
+         */
+        Attributes attributes = new BasicAttributes();
+        Attribute attribute = new BasicAttribute( "objectClass" );
+        attribute.add( "top" );
+        attribute.add( "organizationalUnit" );
+        attributes.put( attribute );
+        attributes.put( "ou", "testing00" );
+        DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
+        assertNotNull( ctx );
+
+        ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
+        assertNotNull( ctx );
+
+        attributes = ctx.getAttributes( "" );
+        assertNotNull( attributes );
+        assertEquals( "testing00", attributes.get( "ou" ).get() );
+        attribute = attributes.get( "objectClass" );
+        assertNotNull( attribute );
+        assertTrue( attribute.contains( "top" ) );
+        assertTrue( attribute.contains( "organizationalUnit" ) );
+        assertNull( attributes.get( CREATE_TIMESTAMP ) );
+        assertNull( attributes.get( CREATORS_NAME ) );
+
+        SearchControls ctls = new SearchControls();
+        ctls.setReturningAttributes( new String[]
+            { "ou", "createTimestamp", "creatorsName" } );
+
+        sysRoot.addToEnvironment( DerefAliasesEnum.JNDI_PROP,
+                DerefAliasesEnum.NEVERDEREFALIASES_NAME );
+        NamingEnumeration list;
+        list = ( NamingEnumeration ) sysRoot.search( "", "(ou=testing00)", ctls );
+        SearchResult result = ( SearchResult ) list.next();
+        list.close();
+
+        System.out.println( result );
+
+        assertNotNull( result.getAttributes().get( "ou" ) );
+        assertNotNull( result.getAttributes().get( CREATORS_NAME ) );
+        assertNotNull( result.getAttributes().get( CREATE_TIMESTAMP ) );
+    }
+}