Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F19166B73 for ; Thu, 26 May 2011 11:38:20 +0000 (UTC) Received: (qmail 33813 invoked by uid 500); 26 May 2011 11:38:20 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 33774 invoked by uid 500); 26 May 2011 11:38:20 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 33767 invoked by uid 99); 26 May 2011 11:38:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 May 2011 11:38:20 +0000 X-ASF-Spam-Status: No, hits=-1996.4 required=5.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 May 2011 11:38:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E14DF23889D5; Thu, 26 May 2011 11:37:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1127877 - in /directory/apacheds/trunk/server-integ: pom.xml src/test/java/org/apache/directory/server/replication/ src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java Date: Thu, 26 May 2011 11:37:58 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110526113758.E14DF23889D5@eris.apache.org> Author: kayyagari Date: Thu May 26 11:37:58 2011 New Revision: 1127877 URL: http://svn.apache.org/viewvc?rev=1127877&view=rev Log: o added a test class for testing replication with one test (more tests will be added) o updated integration profile in pom Added: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java Modified: directory/apacheds/trunk/server-integ/pom.xml Modified: directory/apacheds/trunk/server-integ/pom.xml URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/pom.xml?rev=1127877&r1=1127876&r2=1127877&view=diff ============================================================================== --- directory/apacheds/trunk/server-integ/pom.xml (original) +++ directory/apacheds/trunk/server-integ/pom.xml Thu May 26 11:37:58 2011 @@ -236,6 +236,9 @@ 900 **/*ISuite.java + + **/ClientServerReplicationIT.java **/*PerfIT.java Added: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java?rev=1127877&view=auto ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java (added) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java Thu May 26 11:37:58 2011 @@ -0,0 +1,231 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.server.replication; + + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import org.apache.directory.server.annotations.CreateLdapServer; +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.annotations.CreateDS; +import org.apache.directory.server.core.annotations.CreateIndex; +import org.apache.directory.server.core.annotations.CreatePartition; +import org.apache.directory.server.core.factory.DSAnnotationProcessor; +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.SyncReplConsumer; +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; +import org.apache.directory.shared.ldap.model.entry.Entry; +import org.apache.directory.shared.ldap.model.schema.SchemaManager; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests for replication subsystem in client-server mode. + * + * @author Apache Directory Project + */ +public class ClientServerReplicationIT +{ + private static LdapServer providerServer; + + private static LdapServer consumerServer; + + private SchemaManager schemaManager; + + private CoreSession providerSession; + + private CoreSession consumerSession; + + @BeforeClass + public static void setUp() throws Exception + { + Class justLoadToSetControlProperties = Class.forName( FrameworkRunner.class.getName() ); + + startProvider(); + startConsumer(); + } + + + @AfterClass + public static void tearDown() + { + consumerServer.stop(); + providerServer.stop(); + } + + + @Before + public void accessFields() + { + schemaManager = providerServer.getDirectoryService().getSchemaManager(); + providerSession = providerServer.getDirectoryService().getAdminSession(); + consumerSession = consumerServer.getDirectoryService().getAdminSession(); + } + + + @Test + public void testInjectContextEntry() throws Exception + { + String dn = "dc=example,dc=com"; + + DefaultEntry entry = new DefaultEntry( schemaManager, dn ); + entry.add( "objectClass", "domain" ); + entry.add( "dc", "example" ); + + assertFalse( consumerSession.exists( dn ) ); + + providerSession.add( entry ); + + // sleep for 2 sec (twice the refresh interval), just to let the first refresh request succeed + Thread.sleep( 2000 ); + + assertTrue( consumerSession.exists( dn ) ); + + Entry providerEntry = providerSession.lookup( entry.getDn(), "*", "+" ); + + Entry consumerEntry = consumerSession.lookup( entry.getDn(), "*", "+" ); + assertEquals( providerEntry, consumerEntry ); + } + + + @CreateDS(allowAnonAccess = true, name = "provider-replication", partitions = + { + @CreatePartition( + name = "example", + suffix = "dc=example,dc=com", + indexes = + { + @CreateIndex(attribute = "objectClass"), + @CreateIndex(attribute = "dc"), + @CreateIndex(attribute = "ou") + }) + }) + @CreateLdapServer(transports = + { @CreateTransport( port=16000, protocol = "LDAP") }) + private static void startProvider() throws Exception + { + Method createProviderMethod = ClientServerReplicationIT.class.getDeclaredMethod( "startProvider" ); + CreateDS dsAnnotation = createProviderMethod.getAnnotation( CreateDS.class ); + DirectoryService provDirService = DSAnnotationProcessor.createDS( dsAnnotation ); + + CreateLdapServer serverAnnotation = createProviderMethod.getAnnotation( CreateLdapServer.class ); + + providerServer = ServerAnnotationProcessor.instantiateLdapServer( serverAnnotation, provDirService, 0 ); + + providerServer.setReplicationReqHandler( new SyncReplRequestHandler() ); + + Runnable r = new Runnable() + { + + public void run() + { + try + { + providerServer.start(); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + }; + + Thread t = new Thread( r ); + t.setDaemon( true ); + t.start(); + } + + + @CreateDS(allowAnonAccess = true, name = "consumer-replication", partitions = + { + @CreatePartition( + name = "example", + suffix = "dc=example,dc=com", + indexes = + { + @CreateIndex(attribute = "objectClass"), + @CreateIndex(attribute = "dc"), + @CreateIndex(attribute = "ou") + }) + }) + @CreateLdapServer(transports = + { @CreateTransport( port=17000, protocol = "LDAP") }) + private static void startConsumer() throws Exception + { + Method createProviderMethod = ClientServerReplicationIT.class.getDeclaredMethod( "startConsumer" ); + CreateDS dsAnnotation = createProviderMethod.getAnnotation( CreateDS.class ); + DirectoryService provDirService = DSAnnotationProcessor.createDS( dsAnnotation ); + + CreateLdapServer serverAnnotation = createProviderMethod.getAnnotation( CreateLdapServer.class ); + + consumerServer = ServerAnnotationProcessor.instantiateLdapServer( serverAnnotation, provDirService, 0 ); + + SyncReplConsumer syncreplClient = new SyncReplConsumer(); + SyncreplConfiguration config = new SyncreplConfiguration(); + config.setProviderHost( "localhost" ); + config.setPort( 16000 ); + config.setReplUserDn( "uid=admin,ou=system" ); + config.setReplUserPassword( "secret".getBytes() ); + config.setUseTls( false ); + config.setBaseDn( "dc=example,dc=com" ); + config.setRefreshInterval( 1000 ); + + syncreplClient.setConfig( config ); + + List replConsumers = new ArrayList(); + replConsumers.add( syncreplClient ); + + consumerServer.setReplConsumers( replConsumers ); + + Runnable r = new Runnable() + { + + public void run() + { + try + { + consumerServer.start(); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + }; + + Thread t = new Thread( r ); + t.setDaemon( true ); + t.start(); + } +}