directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r473660 - /directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceIntegrationTest.java
Date Sat, 11 Nov 2006 07:38:12 GMT
Author: trustin
Date: Fri Nov 10 23:38:11 2006
New Revision: 473660

URL: http://svn.apache.org/viewvc?view=rev&rev=473660
Log:
DIRSERVER-780: Create an integration test that tests various conflict resolution scenarios.

http://issues.apache.org/jira/browse/DIRSERVER-780
* Added ReplicationServiceIntegrationTest with setUp and tearDown implementation

Added:
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceIntegrationTest.java
  (contents, props changed)
      - copied, changed from r473640, directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceTest.java

Copied: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceIntegrationTest.java
(from r473640, directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceTest.java)
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceIntegrationTest.java?view=diff&rev=473660&p1=directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceTest.java&r1=473640&p2=directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceIntegrationTest.java&r2=473660
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceTest.java
(original)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceIntegrationTest.java
Fri Nov 10 23:38:11 2006
@@ -19,23 +19,175 @@
  */
 package org.apache.directory.mitosis.service;
 
+import java.io.File;
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
 import junit.framework.TestCase;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.mitosis.common.Replica;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.configuration.MutableInterceptorConfiguration;
+import org.apache.directory.server.core.configuration.MutableStartupConfiguration;
+import org.apache.directory.server.core.configuration.ShutdownConfiguration;
+import org.apache.directory.server.core.jndi.CoreContextFactory;
+import org.apache.mina.util.AvailablePortFinder;
+
 /**
- * A test case for {@link ReplicationServiceTest}
+ * A test case for {@link ReplicationServiceIntegrationTest}
  * 
  * @author The Apache Directory Project Team (dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class ReplicationServiceTest extends TestCase
+public class ReplicationServiceIntegrationTest extends TestCase
 {
+	private Map contexts = new HashMap();
 
 	protected void setUp() throws Exception
 	{
+		createReplicas( new String[] { "A", "B", "C" } );
 	}
 
 	protected void tearDown() throws Exception
 	{
+		destroyAllReplicas();
 	}
+	
+	public void testModify() throws Exception
+	{
+	}
+	
+	private void createReplicas(String[] names) throws Exception
+	{
+		int lastAvailablePort = 1024;
+		
+		Replica[] replicas = new Replica[ names.length ];
+		for( int i = 0; i < names.length; i ++ )
+		{
+			int replicationPort = AvailablePortFinder.getNextAvailable( lastAvailablePort );
+			lastAvailablePort = replicationPort + 1;
+			
+			replicas[ i ] = new Replica(
+					new ReplicaId( names[ i ] ),
+					new InetSocketAddress( "127.0.0.1", replicationPort ));
+		}
+		
+		Random random = new Random();
+		String homeDirectory =
+			System.getProperty( "java.io.tmpdir" ) + File.separator +
+			"mitosis-" + Long.toHexString( random.nextLong() );
+		
+		for( int i = 0; i < replicas.length; i ++ )
+		{
+			Replica replica = replicas[ i ];
+		    String replicaId = replicas[ i ].getId().getId();
+			MutableStartupConfiguration ldapCfg =
+		    	new MutableStartupConfiguration( replicaId );
+		    
+		    File workDir = new File( homeDirectory + File.separator + ldapCfg.getInstanceId() );
+		    
+			ldapCfg.setShutdownHookEnabled( false );
+			ldapCfg.setWorkingDirectory( workDir );
+			
+			List interceptorCfgs = ldapCfg.getInterceptorConfigurations();
+			
+			ReplicationConfiguration replicationCfg = new ReplicationConfiguration();
+			replicationCfg.setReplicaId( replica.getId() );
+			replicationCfg.setServerPort( replica.getAddress().getPort() );
+			for( int j = 0; j < replicas.length; j ++ )
+			{
+				if( replicas[ j ] != replica )
+				{
+					replicationCfg.addPeerReplica( replicas[ j ] );
+				}
+			}
+			
+			ReplicationService replicationService = new ReplicationService();
+			replicationService.setConfiguration( replicationCfg );
+			
+			MutableInterceptorConfiguration interceptorCfg = new MutableInterceptorConfiguration();
+			interceptorCfg.setName( "mitosis" );
+			interceptorCfg.setInterceptor( replicationService );
+					
+			interceptorCfgs.add( interceptorCfg );
+			
+			ldapCfg.setInterceptorConfigurations( interceptorCfgs );
 
+			if( workDir.exists() )
+			{
+				FileUtils.deleteDirectory( workDir );
+			}
+			
+	        Hashtable env = new Hashtable( ldapCfg.toJndiEnvironment() );
+	        env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+	        env.put( Context.SECURITY_CREDENTIALS, "secret" );
+	        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+	        env.put( Context.PROVIDER_URL, "" );
+	        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+	        
+	        // Initialize the server instance.
+	        LdapContext context = new InitialLdapContext( env, null );
+	        contexts.put( replicaId, context );
+		}
+	}
+	
+	private LdapContext getReplicaContext( String name ) throws Exception
+	{
+		LdapContext context = ( LdapContext ) contexts.get( name );
+		if( context == null )
+		{
+			throw new IllegalArgumentException( "No such replica: " + name );
+		}
+		
+		return context;
+	}
+	
+	private void destroyAllReplicas() throws Exception
+	{
+		for( Iterator i = contexts.keySet().iterator(); i.hasNext(); )
+		{
+			String replicaId = ( String ) i.next();
+			File workDir = DirectoryService.getInstance( replicaId ).getConfiguration().getStartupConfiguration().getWorkingDirectory();
+
+	        Hashtable env = new Hashtable();
+	        env.put( Context.PROVIDER_URL, "ou=system" );
+	        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+	        env.putAll( new ShutdownConfiguration( replicaId ).toJndiEnvironment() );
+	        env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+	        env.put( Context.SECURITY_CREDENTIALS, "secret" );
+	        try
+	        {
+	            new InitialContext( env );
+	        }
+	        catch( Exception e )
+	        {
+	        }
+	        
+	        try
+	        {
+	        	FileUtils.deleteDirectory( workDir );
+	        }
+	        catch( Exception e )
+	        {
+	        	e.printStackTrace();
+	        }
+	        
+	        workDir.getParentFile().delete();
+
+	        i.remove();
+		}
+	}
 }

Propchange: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/ReplicationServiceIntegrationTest.java
------------------------------------------------------------------------------
    svn:keywords = LastChangedDate LastChangedRevision LastChangedBy HeadURL Id



Mime
View raw message