directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r366077 - in /directory/trunk: apacheds-server-unit/src/test/java/org/apache/ldap/server/ apacheds/src/main/java/org/apache/ldap/server/event/ ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/
Date Thu, 05 Jan 2006 04:18:57 GMT
Author: akarasulu
Date: Wed Jan  4 20:18:49 2006
New Revision: 366077

URL: http://svn.apache.org/viewcvs?rev=366077&view=rev
Log:
fixed some bugs in even notification and got all test cases working for initial psearch mechanism

Modified:
    directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/PersistentSearchTest.java
    directory/trunk/apacheds/src/main/java/org/apache/ldap/server/event/EventService.java
    directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/SearchHandler.java

Modified: directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/PersistentSearchTest.java
URL: http://svn.apache.org/viewcvs/directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/PersistentSearchTest.java?rev=366077&r1=366076&r2=366077&view=diff
==============================================================================
--- directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/PersistentSearchTest.java
(original)
+++ directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/PersistentSearchTest.java
Wed Jan  4 20:18:49 2006
@@ -30,6 +30,8 @@
 import javax.naming.ldap.LdapContext;
 
 import org.apache.ldap.common.message.PersistentSearchControl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -40,11 +42,11 @@
  */
 public class PersistentSearchTest extends AbstractServerTest
 {
+    public static final Logger log = LoggerFactory.getLogger( PersistentSearchTest.class
);
+    public static final String PERSON_DESCRIPTION = "an American singer-songwriter";
+    public static final String RDN = "cn=Tori Amos";
     private LdapContext ctx = null;
 
-    public static final String RDN = "cn=Tori Amos";
-
-    public static final String PERSON_DESCRIPTION = "an American singer-songwriter";
 
 
     /**
@@ -103,30 +105,127 @@
     }
 
 
-    public void testPsearchSend() throws Exception
+    public void testPsearchModify() throws Exception
     {
         PSearchListener listener = new PSearchListener();
-        Thread t = new Thread( listener );
+        Thread t = new Thread( listener, "PSearchListener" );
         t.start();
         
-        Thread.sleep( 3000 );
+        while( ! listener.isReady )
+        {
+            Thread.sleep( 100 );
+        }
+        Thread.sleep( 250 );
 
-        System.out.println( "--------------------------------------------------------------"
);
         ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, 
             new BasicAttributes( "description", PERSON_DESCRIPTION, true ) );
-        Thread.sleep( 3000 );
+        long start = System.currentTimeMillis();
+        while ( t.isAlive() )
+        {
+            Thread.sleep( 200 );
+            if ( System.currentTimeMillis() - start > 3000 )
+            {
+                System.out.println( "PSearchListener thread not dead yet" );
+                break;
+            }
+        }
         
-        // Create a person with description
-        System.out.println( "--------------------------------------------------------------"
);
-        Attributes attributes = this.getPersonAttributes( "Black", "Jack Black" );
-        attributes.put( "description", PERSON_DESCRIPTION );
-        ctx.createSubcontext( "cn=Jack Black", attributes );
-        Thread.sleep( 3000 );
+        assertNotNull( listener.result );
+    }
+
+
+    public void testPsearchModifyDn() throws Exception
+    {
+        PSearchListener listener = new PSearchListener();
+        Thread t = new Thread( listener );
+        t.start();
+        
+        while( ! listener.isReady )
+        {
+            Thread.sleep( 100 );
+        }
+        Thread.sleep( 250 );
+
+        ctx.rename( RDN, "cn=Jack Black" );
+        
+        long start = System.currentTimeMillis();
+        while ( t.isAlive() )
+        {
+            Thread.sleep( 100 );
+            if ( System.currentTimeMillis() - start > 3000 )
+            {
+                System.out.println( "PSearchListener thread not dead yet" );
+                break;
+            }
+        }
+        
+        assertNotNull( listener.result );
+    }
+
+    
+    public void testPsearchDelete() throws Exception
+    {
+        PSearchListener listener = new PSearchListener();
+        Thread t = new Thread( listener );
+        t.start();
+        
+        while( ! listener.isReady )
+        {
+            Thread.sleep( 100 );
+        }
+        Thread.sleep( 250 );
+
+        ctx.destroySubcontext( RDN );
+        
+        long start = System.currentTimeMillis();
+        while ( t.isAlive() )
+        {
+            Thread.sleep( 100 );
+            if ( System.currentTimeMillis() - start > 3000 )
+            {
+                System.out.println( "PSearchListener thread not dead yet" );
+                break;
+            }
+        }
+        
+        assertNotNull( listener.result );
     }
+
     
+    public void testPsearchAdd() throws Exception
+    {
+        PSearchListener listener = new PSearchListener();
+        Thread t = new Thread( listener );
+        t.start();
+        
+        while( ! listener.isReady )
+        {
+            Thread.sleep( 100 );
+        }
+        Thread.sleep( 250 );
+
+        ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black"
) );
+        
+        long start = System.currentTimeMillis();
+        while ( t.isAlive() )
+        {
+            Thread.sleep( 100 );
+            if ( System.currentTimeMillis() - start > 3000 )
+            {
+                System.out.println( "PSearchListener thread not dead yet" );
+                break;
+            }
+        }
+        
+        assertNotNull( listener.result );
+    }
+        
     
     class PSearchListener implements Runnable
     {
+        boolean isReady = false;
+        SearchResult result;
+        
         public void run()
         {
             PersistentSearchControl control = new PersistentSearchControl();
@@ -136,11 +235,13 @@
             try
             {
                 ctx.setRequestControls( ctxCtls );
+                isReady = true;
                 NamingEnumeration list = ctx.search( "", "objectClass=*", null );
                 while( list.hasMore() )
                 {
-                    SearchResult result = ( SearchResult ) list.next();
-                    System.out.print( "got entry: " + result );
+                    result = ( SearchResult ) list.next();
+                    System.out.println( "got notifiaction for entry: " + result.getName()
);
+                    break;
                 }
             }
             catch( Exception e ) 

Modified: directory/trunk/apacheds/src/main/java/org/apache/ldap/server/event/EventService.java
URL: http://svn.apache.org/viewcvs/directory/trunk/apacheds/src/main/java/org/apache/ldap/server/event/EventService.java?rev=366077&r1=366076&r2=366077&view=diff
==============================================================================
--- directory/trunk/apacheds/src/main/java/org/apache/ldap/server/event/EventService.java
(original)
+++ directory/trunk/apacheds/src/main/java/org/apache/ldap/server/event/EventService.java
Wed Jan  4 20:18:49 2006
@@ -162,7 +162,7 @@
                 NamespaceChangeListener nclistener = ( NamespaceChangeListener ) listener;
                 Binding binding = new Binding( upName, entry, false );
                 nclistener.objectAdded( new NamingEvent( rec.getEventContext(),
-                        NamingEvent.OBJECT_ADDED, null, binding, entry ) );
+                        NamingEvent.OBJECT_ADDED, binding, null, entry ) );
             }
         }
     }
@@ -170,8 +170,8 @@
 
     public void delete( NextInterceptor next, Name name ) throws NamingException
     {
-        super.delete( next, name );
         Attributes entry = nexus.lookup( name );
+        super.delete( next, name );
         Set selecting = getSelectingSources( name, entry );
         if ( selecting.isEmpty() )
         {
@@ -189,7 +189,7 @@
                 NamespaceChangeListener nclistener = ( NamespaceChangeListener ) listener;
                 Binding binding = new Binding( name.toString(), entry, false );
                 nclistener.objectRemoved( new NamingEvent( rec.getEventContext(),
-                        NamingEvent.OBJECT_REMOVED, binding, null, entry ) );
+                        NamingEvent.OBJECT_REMOVED, null, binding, entry ) );
             }
         }
     }

Modified: directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/SearchHandler.java
URL: http://svn.apache.org/viewcvs/directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/SearchHandler.java?rev=366077&r1=366076&r2=366077&view=diff
==============================================================================
--- directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/SearchHandler.java
(original)
+++ directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/SearchHandler.java
Wed Jan  4 20:18:49 2006
@@ -21,8 +21,6 @@
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
-import javax.naming.Binding;
-import javax.naming.Context;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
@@ -32,7 +30,6 @@
 import javax.naming.event.NamespaceChangeListener;
 import javax.naming.event.NamingEvent;
 import javax.naming.event.NamingExceptionEvent;
-import javax.naming.event.NamingListener;
 import javax.naming.event.ObjectChangeListener;
 import javax.naming.ldap.LdapContext;
 
@@ -63,7 +60,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.sun.corba.se.spi.ior.iiop.JavaCodebaseComponent;
 
 /**
  * A handler for processing search requests.
@@ -654,7 +650,7 @@
             switch ( evt.getType() )
             {
                 case( NamingEvent.OBJECT_ADDED ):
-                    respEntry.setObjectName( evt.getOldBinding().getName() );
+                    respEntry.setObjectName( evt.getNewBinding().getName() );
                     respEntry.setAttributes( ( Attributes ) evt.getChangeInfo() );
                     break;
                 case( NamingEvent.OBJECT_CHANGED ):



Mime
View raw message