directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r894420 - in /directory/apacheds/branches/apacheds-schema: server-annotations/src/main/java/org/apache/directory/server/annotations/ server-unit/src/main/java/org/apache/directory/server/unit/ test-framework/src/main/java/org/apache/directo...
Date Tue, 29 Dec 2009 15:17:57 GMT
Author: elecharny
Date: Tue Dec 29 15:17:56 2009
New Revision: 894420

URL: http://svn.apache.org/viewvc?rev=894420&view=rev
Log:
o Added a CreateTransport @
o Modified the LdapServerBuilder to accept Transports
o Refactored the FrameworkSuite to launch a LdapServer

Added:
    directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/CreateTransport.java
      - copied, changed from r894343, directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/Transport.java
Modified:
    directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/LdapServerBuilder.java
    directory/apacheds/branches/apacheds-schema/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
    directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
    directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkSuite.java

Copied: directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/CreateTransport.java
(from r894343, directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/Transport.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/CreateTransport.java?p2=directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/CreateTransport.java&p1=directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/Transport.java&r1=894343&r2=894420&rev=894420&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/Transport.java
(original)
+++ directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/CreateTransport.java
Tue Dec 29 15:17:56 2009
@@ -38,7 +38,7 @@
 @Inherited
 @Retention ( RetentionPolicy.RUNTIME )
 @Target ( { ElementType.METHOD, ElementType.TYPE } )
-public @interface Transport
+public @interface CreateTransport
 {
     /** The name for this protocol*/
     String protocol();

Modified: directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/LdapServerBuilder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/LdapServerBuilder.java?rev=894420&r1=894419&r2=894420&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/LdapServerBuilder.java
(original)
+++ directory/apacheds/branches/apacheds-schema/server-annotations/src/main/java/org/apache/directory/server/annotations/LdapServerBuilder.java
Tue Dec 29 15:17:56 2009
@@ -51,6 +51,9 @@
     /** The instance name */
     String name();
     
+    /** The transports to use, default to LDAP */
+    CreateTransport[] transports() default {};
+    
     /** The LdapServer factory */
     Class<?> factory() default DefaultLdapServerFactory.class;
     

Modified: directory/apacheds/branches/apacheds-schema/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java?rev=894420&r1=894419&r2=894420&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
(original)
+++ directory/apacheds/branches/apacheds-schema/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
Tue Dec 29 15:17:56 2009
@@ -39,7 +39,7 @@
 
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.annotations.LdapServerBuilder;
-import org.apache.directory.server.annotations.Transport;
+import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.core.DefaultDirectoryService;
@@ -81,7 +81,7 @@
  * @version $Rev$
  */
 @LdapServerBuilder( name="test" )
-@Transport( protocol="LDAP")
+@CreateTransport( protocol="LDAP")
 @DSBuilder( factory = DefaultDirectoryServiceFactory.class, name="DSTest" )
 public abstract class AbstractServerTest
 {

Modified: directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java?rev=894420&r1=894419&r2=894420&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
(original)
+++ directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
Tue Dec 29 15:17:56 2009
@@ -158,6 +158,7 @@
                 }
             }
 
+            // Now run the class
             super.run( notifier );
             
             // cleanup classService if it is not the same as suite service or

Modified: directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkSuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkSuite.java?rev=894420&r1=894419&r2=894420&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkSuite.java
(original)
+++ directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkSuite.java
Tue Dec 29 15:17:56 2009
@@ -21,9 +21,14 @@
 
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.annotations.LdapServerBuilder;
+import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.factory.DSBuilderAnnotationProcessor;
 import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.server.protocol.shared.transport.TcpTransport;
+import org.apache.directory.server.protocol.shared.transport.Transport;
+import org.apache.mina.util.AvailablePortFinder;
+import org.junit.runner.Description;
 import org.junit.runner.Runner;
 import org.junit.runner.notification.RunNotifier;
 import org.junit.runners.Suite;
@@ -49,10 +54,10 @@
     private DirectoryService directoryService;
     
     /** The LdapServerBuilder for this class, if any */
-    private LdapServerBuilder suiteLdapServerBuilder;
+    private LdapServerBuilder ldapServerBuilder;
 
     /** The LdapServer for this class, if any */
-    private LdapServer suiteLdapServer;
+    private LdapServer ldapServer;
 
     /**
      * Creates a new instance of FrameworkSuite.
@@ -63,19 +68,20 @@
     }
     
     
-    private void startSuiteDS()
+    /**
+     * Start and initialize the DS
+     */
+    private void startDS( Description description )
     {
-        suiteLdapServerBuilder = getDescription().getAnnotation( LdapServerBuilder.class
);
-
         // Initialize and start the DS before running any test, if we have a DS annotation
-        directoryService = DSBuilderAnnotationProcessor.getDirectoryService( getDescription()
);
+        directoryService = DSBuilderAnnotationProcessor.getDirectoryService( description
);
         
         // and inject LDIFs if needed
         if ( directoryService != null )
         {
             try
             {
-                DSBuilderAnnotationProcessor.applyLdifs( getDescription(), directoryService
);
+                DSBuilderAnnotationProcessor.applyLdifs( description, directoryService );
             }
             catch ( Exception e )
             {
@@ -85,7 +91,10 @@
     }
     
     
-    private void stopSuiteDS()
+    /**
+     * Stop and clean the DS
+     */
+    private void stopDS()
     {
         if ( directoryService != null )
         {
@@ -101,7 +110,93 @@
             }
         }
     }
+    
+    
+    private void createTransports( LdapServer ldapServer, CreateTransport[] transportBuilders
)
+    {
+        if ( transportBuilders.length != 0 )
+        {
+            int createdPort = 1024;
+            
+            for ( CreateTransport transportBuilder : transportBuilders )
+            {
+                String protocol = transportBuilder.protocol();
+                int port = transportBuilder.port();
+                int nbThreads = transportBuilder.nbThreads();
+                int backlog = transportBuilder.backlog();
+                String address = transportBuilder.address();
+                
+                if ( port == -1 )
+                {
+                    port = AvailablePortFinder.getNextAvailable( createdPort );
+                    createdPort = port + 1;
+                }
+                
+                if ( protocol.equalsIgnoreCase( "LDAP" ) )
+                {
+                    Transport ldap = new TcpTransport( address, port, nbThreads, backlog
);
+                    ldapServer.addTransports( ldap );
+                }
+                else if ( protocol.equalsIgnoreCase( "LDAPS" ) )
+                {
+                    Transport ldaps = new TcpTransport( address, port, nbThreads, backlog
);
+                    ldaps.setEnableSSL( true );
+                    ldapServer.addTransports( ldaps );
+                }
+            }
+        }
+        else
+        {
+            // Create default LDAP and LDAPS transports
+            int port = AvailablePortFinder.getNextAvailable( 1024 );
+            Transport ldap = new TcpTransport( port );
+            ldapServer.addTransports( ldap );
+            
+            port = AvailablePortFinder.getNextAvailable( port );
+            Transport ldaps = new TcpTransport( port );
+            ldaps.setEnableSSL( true );
+            ldapServer.addTransports( ldaps );
+        }
+    }
+    
+    
+    private void startLdapServer( Description description )
+    {
+        ldapServerBuilder = description.getAnnotation( LdapServerBuilder.class );
 
+        if ( ldapServerBuilder != null )
+        {
+            LdapServer ldapServer = new LdapServer();
+            
+            ldapServer.setServiceName( ldapServerBuilder.name() );
+            
+            // Read the transports
+            createTransports( ldapServer, ldapServerBuilder.transports() );
+            
+            // Associate the DS to this LdapServer
+            ldapServer.setDirectoryService( directoryService );
+            
+            // Launch the server
+            try
+            {
+                ldapServer.start();
+            }
+            catch ( Exception e )
+            {
+                e.printStackTrace();
+            }
+        }
+    }
+    
+    
+    private void stopLdapServer()
+    {
+        if ( ( ldapServer != null ) && ( ldapServer.isStarted() ) )
+        {
+            ldapServer.stop();
+        }
+    }
+    
     
     /**
      * {@inheritDoc}
@@ -110,13 +205,19 @@
     public void run( final RunNotifier notifier )
     {
         // Create and initialize the Suite DS
-        startSuiteDS();
+        startDS( getDescription() );
+        
+        // create and initialize the suite LdapServer
+        startLdapServer( getDescription() );
         
         // Run the suite
         super.run( notifier );
         
+        // Stop the LdapServer
+        stopLdapServer();
+        
         // last, stop the DS if we have one
-        stopSuiteDS();
+        stopDS();
     }
 
     /**
@@ -164,7 +265,7 @@
      */
     public LdapServerBuilder getSuiteLdapServerBuilder()
     {
-        return suiteLdapServerBuilder;
+        return ldapServerBuilder;
     }
 
 
@@ -173,6 +274,6 @@
      */
     public LdapServer getSuiteLdapServer()
     {
-        return suiteLdapServer;
+        return ldapServer;
     }
 }



Mime
View raw message