directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1152169 - in /directory/apacheds/trunk: core-api/src/test/java/org/apache/directory/server/core/ server-integ/src/test/java/org/apache/directory/server/replication/
Date Fri, 29 Jul 2011 11:22:16 GMT
Author: elecharny
Date: Fri Jul 29 11:22:14 2011
New Revision: 1152169

URL: http://svn.apache.org/viewvc?rev=1152169&view=rev
Log:
o Stored the SchemaManager into the MockDirectoryService
o Improved the CLientInitialRequest test by isolating the consumer creation
o Make the MockSyncReplConsumer inherit from ReplicationConsumer

Modified:
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockDirectoryService.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockDirectoryService.java?rev=1152169&r1=1152168&r2=1152169&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockDirectoryService.java
(original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/MockDirectoryService.java
Fri Jul 29 11:22:14 2011
@@ -50,10 +50,18 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.util.tree.DnNode;
 
 
+/**
+ * A mock DirectoryService used for tests
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
 public class MockDirectoryService implements DirectoryService
 {
     int count;
     
+    /** The schemaManager */
+    SchemaManager schemaManager;
+    
     
     public MockDirectoryService()
     {
@@ -113,7 +121,7 @@ public class MockDirectoryService implem
 
     public SchemaManager getSchemaManager()
     {
-        return null;
+        return schemaManager;
     }
 
 
@@ -130,6 +138,7 @@ public class MockDirectoryService implem
 
     public void setSchemaManager( SchemaManager schemaManager )
     {
+        this.schemaManager = schemaManager;
     }
 
 

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java?rev=1152169&r1=1152168&r2=1152169&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java
Fri Jul 29 11:22:14 2011
@@ -30,6 +30,7 @@ import org.apache.directory.server.annot
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.MockDirectoryService;
 import org.apache.directory.server.core.annotations.ContextEntry;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.annotations.CreateIndex;
@@ -38,6 +39,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.server.factory.ServerAnnotationProcessor;
 import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.server.ldap.replication.ReplicationConsumer;
 import org.apache.directory.server.ldap.replication.SyncReplRequestHandler;
 import org.apache.directory.server.ldap.replication.SyncreplConfiguration;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
@@ -191,10 +193,46 @@ public class ClientInitialRefreshIT
     }
     
     
-    @Test
-    public void testInitialRefresh() throws Exception
+    
+    
+    /**
+     * Wait for the expected number of entries to be added into the client
+     */
+    private boolean waitForSyncReplClient( ReplicationConsumer consumer, int expected ) throws
Exception
     {
-        final MockSyncReplConsumer syncreplClient = new MockSyncReplConsumer();
+        System.out.println( "NbAdded every 100ms : " );
+        boolean isFirst = true;
+        
+        for ( int i = 0; i < 50; i++ )
+        {
+            Thread.sleep( 100 );
+            
+            int nbAdded = ((MockSyncReplConsumer)consumer).getNbAdded();
+            
+            if ( isFirst )
+            {
+                isFirst = false;
+            }
+            else
+            {
+                System.out.print( ", " );
+            }
+            
+            System.out.print( nbAdded );
+            
+            if ( nbAdded == expected )
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
+
+    private ReplicationConsumer createConsumer() throws Exception
+    {
+        final ReplicationConsumer syncreplClient = new MockSyncReplConsumer();
         final SyncreplConfiguration config = new SyncreplConfiguration();
         config.setRemoteHost( "localhost" );
         config.setRemotePort( 16000 );
@@ -229,7 +267,9 @@ public class ClientInitialRefreshIT
 
                     searchRequest.addAttributes( config.getAttributes() );
 
-                    syncreplClient.init( schemaManager );
+                    DirectoryService directoryService = new MockDirectoryService();
+                    directoryService.setSchemaManager( schemaManager );
+                    ((MockSyncReplConsumer)syncreplClient).init( directoryService );
                     syncreplClient.start();
                 }
                 catch ( Exception e )
@@ -243,42 +283,19 @@ public class ClientInitialRefreshIT
         consumerThread.setDaemon( true );
         consumerThread.start();
         
-        // We should have 1000 entries plus the base entry = 1001
-        assertTrue( waitForSyncReplClient( syncreplClient, 1001 ) ); 
+        return syncreplClient;
     }
     
-    
+
     /**
-     * Wait for the expected number of entries to be added into the client
+     * First test : create a consumer, and see if it gets the 1000 entries
      */
-    private boolean waitForSyncReplClient( MockSyncReplConsumer consumer, int expected )
throws Exception
+    @Test
+    public void testInitialRefresh() throws Exception
     {
-        System.out.println( "NbAdded every 100ms : " );
-        boolean isFirst = true;
+        ReplicationConsumer syncreplClient = createConsumer();
         
-        for ( int i = 0; i < 50; i++ )
-        {
-            Thread.sleep( 100 );
-            
-            int nbAdded = consumer.getNbAdded();
-            
-            if ( isFirst )
-            {
-                isFirst = false;
-            }
-            else
-            {
-                System.out.print( ", " );
-            }
-            
-            System.out.print( nbAdded );
-            
-            if ( nbAdded == expected )
-            {
-                return true;
-            }
-        }
-        
-        return false;
+        // We should have 1000 entries plus the base entry = 1001
+        assertTrue( waitForSyncReplClient( syncreplClient, 1001 ) ); 
     }
 }

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java?rev=1152169&r1=1152168&r2=1152169&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/MockSyncReplConsumer.java
Fri Jul 29 11:22:14 2011
@@ -35,7 +35,9 @@ import java.util.concurrent.atomic.Atomi
 import org.apache.directory.ldap.client.api.ConnectionClosedEventListener;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.ldap.client.api.future.SearchFuture;
+import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
+import org.apache.directory.server.ldap.replication.ReplicationConsumer;
 import org.apache.directory.server.ldap.replication.ReplicationConsumerConfig;
 import org.apache.directory.server.ldap.replication.SyncreplConfiguration;
 import org.apache.directory.shared.ldap.codec.api.LdapApiService;
@@ -87,8 +89,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class MockSyncReplConsumer implements ConnectionClosedEventListener
-//, ReplicationConsumer
+public class MockSyncReplConsumer implements ConnectionClosedEventListener, ReplicationConsumer
 {
     /** the logger */
     private static final Logger LOG = LoggerFactory.getLogger( MockSyncReplConsumer.class
);
@@ -164,9 +165,9 @@ public class MockSyncReplConsumer implem
      * Init the replication service
      * @param directoryservice The directory service
      */
-    public void init( SchemaManager schemaManager ) throws Exception
+    public void init( DirectoryService directoryService ) throws Exception
     {
-        this.schemaManager = schemaManager;
+        this.schemaManager = directoryService.getSchemaManager();
         ENTRY_UUID_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ENTRY_UUID_AT
);
         COOKIE_AT_TYPE = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ADS_REPL_COOKIE
);
 



Mime
View raw message