Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 95158 invoked from network); 1 Sep 2008 14:54:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Sep 2008 14:54:14 -0000 Received: (qmail 67166 invoked by uid 500); 1 Sep 2008 14:54:12 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 67133 invoked by uid 500); 1 Sep 2008 14:54:12 -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 67124 invoked by uid 99); 1 Sep 2008 14:54:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Sep 2008 07:54:12 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED 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; Mon, 01 Sep 2008 14:53:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2307E2388989; Mon, 1 Sep 2008 07:53:53 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r690985 [2/2] - in /directory/apacheds/trunk: core/src/main/java/org/apache/directory/server/core/schema/ mitosis/src/main/java/org/apache/directory/mitosis/operation/ mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/code... Date: Mon, 01 Sep 2008 14:53:51 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080901145353.2307E2388989@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java?rev=690985&r1=690984&r2=690985&view=diff ============================================================================== --- directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java (original) +++ directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java Mon Sep 1 07:53:50 2008 @@ -20,18 +20,30 @@ package org.apache.directory.mitosis.service.protocol.codec; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; import junit.framework.Assert; import org.apache.directory.mitosis.service.protocol.message.BaseMessage; +import org.apache.directory.server.core.DefaultDirectoryService; import org.apache.mina.common.ByteBuffer; +import org.apache.mina.common.IoFilterChain; +import org.apache.mina.common.IoHandler; +import org.apache.mina.common.IoService; +import org.apache.mina.common.IoServiceConfig; +import org.apache.mina.common.IoSession; +import org.apache.mina.common.IoSessionConfig; +import org.apache.mina.common.TransportType; import org.apache.mina.common.WriteFuture; +import org.apache.mina.common.support.BaseIoSession; import org.apache.mina.filter.codec.ProtocolDecoderOutput; import org.apache.mina.filter.codec.demux.MessageDecoder; import org.apache.mina.filter.codec.demux.MessageEncoder; import org.apache.mina.filter.codec.support.SimpleProtocolEncoderOutput; +import org.junit.BeforeClass; import org.junit.Test; @@ -42,6 +54,15 @@ private final MessageDecoder decoder; + private static DefaultDirectoryService service; + + @BeforeClass + public static void setUp() + { + service = new DefaultDirectoryService(); + } + + protected AbstractMessageCodecTest( BaseMessage message, MessageEncoder encoder, MessageDecoder decoder ) { if ( message == null ) @@ -63,7 +84,8 @@ } - @Test public void testMessageCodec() throws Exception + @Test + public void testMessageCodec() throws Exception { SimpleProtocolEncoderOutput encoderOut = new SimpleProtocolEncoderOutput() { @@ -73,7 +95,11 @@ } }; - encoder.encode( null, message, encoderOut ); + + IoSession session = new DummySession(); + + session.setAttribute( "registries", service.getRegistries() ); + encoder.encode( session, message, encoderOut ); ByteBuffer buf = encoderOut.getBufferQueue().poll(); buf.mark(); @@ -81,7 +107,7 @@ buf.reset(); ProtocolDecoderOutputImpl decoderOut = new ProtocolDecoderOutputImpl(); - decoder.decode( null, buf, decoderOut ); + decoder.decode( session, buf, decoderOut ); Assert.assertTrue( compare( message, ( BaseMessage ) decoderOut.messages.poll() ) ); } @@ -107,4 +133,97 @@ messages.add( message ); } } + + + protected static class DummySession extends BaseIoSession + { + Object message; + + + @Override + public WriteFuture write( Object message ) + { + this.message = message; + + return super.write( message ); + } + + + protected Object getMessage() + { + return message; + } + + + protected void updateTrafficMask() + { + // Do nothing. + } + + + public IoService getService() + { + return null; + } + + + public IoHandler getHandler() + { + return null; + } + + + public IoFilterChain getFilterChain() + { + return null; + } + + + public TransportType getTransportType() + { + return null; + } + + + public SocketAddress getRemoteAddress() + { + return new InetSocketAddress( 10088 ); + } + + + public SocketAddress getLocalAddress() + { + return null; + } + + + public IoSessionConfig getConfig() + { + return null; + } + + + public int getScheduledWriteRequests() + { + return 0; + } + + + public SocketAddress getServiceAddress() + { + return null; + } + + + public IoServiceConfig getServiceConfig() + { + return null; + } + + + public int getScheduledWriteBytes() + { + return 0; + } + } } Modified: directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java?rev=690985&r1=690984&r2=690985&view=diff ============================================================================== --- directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java (original) +++ directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java Mon Sep 1 07:53:50 2008 @@ -57,17 +57,11 @@ public LogEntryMessageCodecTest() throws InvalidNameException, NamingException { - // Initialize OIDs maps for normalization - /*Map oids = new HashMap(); - - oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) ); - oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) ); - oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) ); - */ super( new LogEntryMessage( 1234, new AddAttributeOperation( + service.getRegistries(), new DefaultCSN( System.currentTimeMillis(), "testReplica0", 1234 ), new LdapDN( "ou=system" ).normalize( oids ), Modified: directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java?rev=690985&r1=690984&r2=690985&view=diff ============================================================================== --- directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java (original) +++ directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java Mon Sep 1 07:53:50 2008 @@ -27,7 +27,6 @@ public class LoginAckMessageCodecTest extends AbstractMessageCodecTest { - public LoginAckMessageCodecTest() { super( new LoginAckMessage( 1234, 5678, "ReplicaABCD" ), new LoginAckMessageEncoder(), Modified: directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java?rev=690985&r1=690984&r2=690985&view=diff ============================================================================== --- directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java (original) +++ directory/apacheds/trunk/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java Mon Sep 1 07:53:50 2008 @@ -42,7 +42,9 @@ import org.apache.directory.server.core.entry.DefaultServerAttribute; import org.apache.directory.server.core.entry.DefaultServerEntry; import org.apache.directory.server.schema.registries.AttributeTypeRegistry; +import org.apache.directory.shared.ldap.entry.EntryAttribute; import org.apache.directory.shared.ldap.name.LdapDN; +import org.apache.directory.shared.ldap.schema.AttributeType; import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer; import org.apache.directory.shared.ldap.schema.OidNormalizer; import org.apache.directory.mitosis.common.CSN; @@ -192,35 +194,35 @@ AttributeTypeRegistry atRegistry = service.getRegistries().getAttributeTypeRegistry(); CSN csn = csnFactory.newInstance( REPLICA_ID ); - CompositeOperation op1 = new CompositeOperation( csn ); + CompositeOperation op1 = new CompositeOperation( service.getRegistries(), csn ); LdapDN ouA = new LdapDN( "ou=a" ).normalize( oids ); - op1.add( new AddEntryOperation( csn, + op1.add( new AddEntryOperation( service.getRegistries(), csn, new DefaultServerEntry( service.getRegistries(), ouA ) ) ); - op1.add( new AddAttributeOperation( csn, ouA, + op1.add( new AddAttributeOperation( service.getRegistries(), csn, ouA, new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) ); - op1.add( new ReplaceAttributeOperation( csn, ouA, + op1.add( new ReplaceAttributeOperation( service.getRegistries(), csn, ouA, new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) ); - op1.add( new DeleteAttributeOperation( csn, ouA, + op1.add( new DeleteAttributeOperation( service.getRegistries(), csn, ouA, new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) ); store.putLog( op1 ); testGetLogs( csn, op1 ); csn = csnFactory.newInstance( OTHER_REPLICA_ID ); - CompositeOperation op2 = new CompositeOperation( csn ); - op2.add( new AddEntryOperation( csn, + CompositeOperation op2 = new CompositeOperation( service.getRegistries(), csn ); + op2.add( new AddEntryOperation( service.getRegistries(), csn, new DefaultServerEntry( service.getRegistries(), ouA ) ) ); - op2.add( new AddAttributeOperation( csn, ouA, + op2.add( new AddAttributeOperation( service.getRegistries(), csn, ouA, new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) ); - op2.add( new ReplaceAttributeOperation( csn, ouA, + op2.add( new ReplaceAttributeOperation( service.getRegistries(), csn, ouA, new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) ); - op2.add( new DeleteAttributeOperation( csn, ouA, + op2.add( new DeleteAttributeOperation( service.getRegistries(), csn, ouA, new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) ); store.putLog( op2 ); @@ -281,7 +283,7 @@ it = store.getLogs( new DefaultCSN( 0, REPLICA_ID, 0 ), false ); it.next(); - csn = it.getOperation().getCSN(); + csn = it.getOperation( service.getRegistries() ).getCSN(); it.close(); Assert.assertEquals( 0, store.removeLogs( csn, false ) ); @@ -290,7 +292,7 @@ it = store.getLogs( new DefaultCSN( 0, OTHER_REPLICA_ID, 0 ), false ); Assert.assertTrue( it.next() ); - csn = it.getOperation().getCSN(); + csn = it.getOperation( service.getRegistries() ).getCSN(); it.close(); Assert.assertEquals( 0, store.removeLogs( csn, false ) ); @@ -307,10 +309,12 @@ CSN csnB = new DefaultCSN( 1, REPLICA_ID, 0 ); CSN csnC = new DefaultCSN( 0, OTHER_REPLICA_ID_2, 0 ); CSN csnD = new DefaultCSN( 0, OTHER_REPLICA_ID_2, 1 ); - store.putLog( new Operation( csnA ) ); - store.putLog( new Operation( csnB ) ); - store.putLog( new Operation( csnC ) ); - store.putLog( new Operation( csnD ) ); + AttributeType at = service.getRegistries().getAttributeTypeRegistry().lookup( "ou" ); + EntryAttribute attribute = new DefaultServerAttribute( at, "test" ); + store.putLog( new AddAttributeOperation( service.getRegistries(), csnA, LdapDN.EMPTY_LDAPDN, attribute ) ); + store.putLog( new AddAttributeOperation( service.getRegistries(), csnB, LdapDN.EMPTY_LDAPDN, attribute ) ); + store.putLog( new AddAttributeOperation( service.getRegistries(), csnC, LdapDN.EMPTY_LDAPDN, attribute ) ); + store.putLog( new AddAttributeOperation( service.getRegistries(), csnD, LdapDN.EMPTY_LDAPDN, attribute ) ); Set expectedKnownReplicaIds = new HashSet(); expectedKnownReplicaIds.add( REPLICA_ID ); @@ -368,7 +372,7 @@ Operation expected = expectedIt.next(); Assert.assertTrue( actualIt.next() ); - Operation actual = actualIt.getOperation(); + Operation actual = actualIt.getOperation( service.getRegistries() ); Assert.assertEquals( expected.getCSN(), actual.getCSN() ); assertEquals( expected, actual ); }