directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r797871 - in /directory: apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/
Date Sun, 26 Jul 2009 07:36:30 GMT
Author: kayyagari
Date: Sun Jul 26 07:36:30 2009
New Revision: 797871

URL: http://svn.apache.org/viewvc?rev=797871&view=rev
Log:
o added async support for recursive delete operation
o added a test case to test this new async behaviour
o removed @Ignore tag

Modified:
    directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java
    directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java

Modified: directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java?rev=797871&r1=797870&r2=797871&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java
(original)
+++ directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java
Sun Jul 26 07:36:30 2009
@@ -29,6 +29,7 @@
 import java.lang.reflect.Method;
 import java.util.Map;
 import java.util.concurrent.Semaphore;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.core.integ.Level;
@@ -145,7 +146,6 @@
     }
     
 
-    @Ignore( "enable this test when the TreeDelete control gets created" )
     @Test
     public void testDeleteWithCascadeControl() throws Exception
     {
@@ -179,16 +179,55 @@
         
         assertTrue( session.exists( dn ) );
 
-        Method deleteChildrenMethod = connection.getClass().getDeclaredMethod( "deleteRecursive",
LdapDN.class, Map.class );
+        Method deleteChildrenMethod = connection.getClass().getDeclaredMethod( "deleteRecursive",
LdapDN.class, Map.class, DeleteListener.class );
         deleteChildrenMethod.setAccessible( true );
         
-        DeleteResponse response = ( DeleteResponse ) deleteChildrenMethod.invoke( connection,
dn, null );
+        DeleteResponse response = ( DeleteResponse ) deleteChildrenMethod.invoke( connection,
dn, null, null );
         assertNotNull( response );
         assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() );
         
         assertFalse( session.exists( dn ) );
     }
+
+    
+    /**
+     * @see #testDeleteWithoutCascadeControl()
+     */
+    @Test
+    public void testDeleteAsyncWithoutCascadeControl() throws Exception
+    {
+        LdapDN dn = new LdapDN( "cn=parent,ou=system" );
+        
+        assertTrue( session.exists( dn ) );
+
+        Method deleteChildrenMethod = connection.getClass().getDeclaredMethod( "deleteRecursive",
LdapDN.class, Map.class, DeleteListener.class );
+        deleteChildrenMethod.setAccessible( true );
     
+        final AtomicInteger count = new AtomicInteger();
+        
+        DeleteListener listener = new DeleteListener()
+        {
+            public void entryDeleted( LdapConnection connection, DeleteResponse response
) throws LdapException
+            {
+                assertNotNull( response );
+                assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode()
);
+                count.incrementAndGet();
+            }
+        };
+        
+        DeleteResponse response = ( DeleteResponse ) deleteChildrenMethod.invoke( connection,
dn, null, listener );
+        
+        assertNull( response );
+        
+        int numDNs = 5; // total number of entries expected to be deleted
+        while( count.get() != numDNs )
+        {
+            Thread.sleep( 1000 );
+        }
+
+        assertFalse( session.exists( dn ) );
+    }
+
     
     @Test
     public void testDeleteAsync() throws Exception

Modified: directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java?rev=797871&r1=797870&r2=797871&view=diff
==============================================================================
--- directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
(original)
+++ directory/shared/trunk/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
Sun Jul 26 07:36:30 2009
@@ -2003,7 +2003,7 @@
             }
             else
             {
-                return deleteRecursive( dn, new HashMap() );
+                return deleteRecursive( dn, new HashMap(), listener );
             }
         }
         else
@@ -2050,13 +2050,17 @@
      *               
      *           The below method works better in the case where the tree depth is >1

      *          
+     *   In the case of passing a non-null DeleteListener, the return value will always be
null, cause the
+     *   operation is treated as asynchronous and response result will be sent using the
listener callback
+     *   
      *  //FIXME provide another method for optimizing delete operation for a tree with depth
<=1
      *          
      * @param dn the DN which will be removed after removing its children
-     * @param map a map to hold the Cursor related to a DN 
+     * @param map a map to hold the Cursor related to a DN
+     * @param listener  the delete operation response listener 
      * @throws LdapException
      */
-    private DeleteResponse deleteRecursive( LdapDN dn, Map<LdapDN, Cursor<SearchResponse>>
cursorMap ) throws LdapException
+    private DeleteResponse deleteRecursive( LdapDN dn, Map<LdapDN, Cursor<SearchResponse>>
cursorMap, DeleteListener listener ) throws LdapException
     {
         LOG.debug( "searching for {}", dn.getUpName() );
         DeleteResponse delResponse = null;
@@ -2081,7 +2085,7 @@
                 LOG.debug( "deleting {}", dn.getUpName() );
                 cursorMap.remove( dn );
                 cursor.close();
-                delResponse = delete( new DeleteRequest( dn ), null );
+                delResponse = delete( new DeleteRequest( dn ), listener );
             }
             else
             {
@@ -2091,7 +2095,7 @@
                     if( searchResp instanceof SearchResultEntry )
                     {
                         SearchResultEntry searchResult = ( SearchResultEntry ) searchResp;
-                        deleteRecursive( searchResult.getEntry().getDn(), cursorMap );
+                        deleteRecursive( searchResult.getEntry().getDn(), cursorMap, listener
);
                     }
                 }
                 while( cursor.next() );
@@ -2099,7 +2103,7 @@
                 cursorMap.remove( dn );
                 cursor.close();
                 LOG.debug( "deleting {}", dn.getUpName() );
-                delResponse = delete( new DeleteRequest( dn ), null );
+                delResponse = delete( new DeleteRequest( dn ), listener );
             }
         }
         catch( Exception e )



Mime
View raw message