directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r463366 [5/5] - in /directory/trunks/apacheds/mitosis/src: ./ main/ main/java/ main/java/org/ main/java/org/apache/ main/java/org/apache/directory/ main/java/org/apache/directory/mitosis/ main/java/org/apache/directory/mitosis/common/ main/...
Date Thu, 12 Oct 2006 18:33:19 GMT
Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,53 @@
+/*
+ *  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.mitosis.service.protocol.codec;
+
+import org.apache.directory.mitosis.common.CSNVector;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.common.SimpleCSN;
+import org.apache.directory.mitosis.service.protocol.Constants;
+import org.apache.directory.mitosis.service.protocol.codec.BeginLogEntriesAckMessageDecoder;
+import org.apache.directory.mitosis.service.protocol.codec.BeginLogEntriesAckMessageEncoder;
+import org.apache.directory.mitosis.service.protocol.message.BeginLogEntriesAckMessage;
+
+public class BeginLogEntriesAckMessageCodecTest extends AbstractMessageCodecTest {
+
+    private static final CSNVector PURGE_VECTOR = new CSNVector();
+    private static final CSNVector UPDATE_VECTOR = new CSNVector();
+    
+    static
+    {
+        PURGE_VECTOR.setCSN( new SimpleCSN( System.currentTimeMillis() - 400, new ReplicaId(
"replica0" ), 3456 ) );
+        PURGE_VECTOR.setCSN( new SimpleCSN( System.currentTimeMillis() - 300, new ReplicaId(
"replica1" ), 9012 ) );
+        PURGE_VECTOR.setCSN( new SimpleCSN( System.currentTimeMillis() - 200, new ReplicaId(
"replica2" ), 5678 ) );
+        PURGE_VECTOR.setCSN( new SimpleCSN( System.currentTimeMillis() - 100, new ReplicaId(
"replica3" ), 1234 ) );
+
+        UPDATE_VECTOR.setCSN( new SimpleCSN( System.currentTimeMillis() + 000, new ReplicaId(
"replica0" ), 1234 ) );
+        UPDATE_VECTOR.setCSN( new SimpleCSN( System.currentTimeMillis() + 100, new ReplicaId(
"replica1" ), 5678 ) );
+        UPDATE_VECTOR.setCSN( new SimpleCSN( System.currentTimeMillis() + 200, new ReplicaId(
"replica2" ), 9012 ) );
+        UPDATE_VECTOR.setCSN( new SimpleCSN( System.currentTimeMillis() + 300, new ReplicaId(
"replica3" ), 3456 ) );
+    }
+    
+    public BeginLogEntriesAckMessageCodecTest() {
+        super( new BeginLogEntriesAckMessage( 1234, Constants.OK, PURGE_VECTOR, UPDATE_VECTOR
),
+               new BeginLogEntriesAckMessageEncoder(),
+               new BeginLogEntriesAckMessageDecoder() );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest2.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest2.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest2.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest2.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,34 @@
+/*
+ *  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.mitosis.service.protocol.codec;
+
+import org.apache.directory.mitosis.service.protocol.Constants;
+import org.apache.directory.mitosis.service.protocol.codec.BeginLogEntriesAckMessageDecoder;
+import org.apache.directory.mitosis.service.protocol.codec.BeginLogEntriesAckMessageEncoder;
+import org.apache.directory.mitosis.service.protocol.message.BeginLogEntriesAckMessage;
+
+public class BeginLogEntriesAckMessageCodecTest2 extends AbstractMessageCodecTest {
+    
+    public BeginLogEntriesAckMessageCodecTest2() {
+        super( new BeginLogEntriesAckMessage( 1234, Constants.NOT_OK, null, null ),
+               new BeginLogEntriesAckMessageEncoder(),
+               new BeginLogEntriesAckMessageDecoder() );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageCodecTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageCodecTest.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageCodecTest.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,33 @@
+/*
+ *  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.mitosis.service.protocol.codec;
+
+import org.apache.directory.mitosis.service.protocol.codec.BeginLogEntriesMessageDecoder;
+import org.apache.directory.mitosis.service.protocol.codec.BeginLogEntriesMessageEncoder;
+import org.apache.directory.mitosis.service.protocol.message.BeginLogEntriesMessage;
+
+public class BeginLogEntriesMessageCodecTest extends AbstractMessageCodecTest {
+
+    public BeginLogEntriesMessageCodecTest() {
+        super( new BeginLogEntriesMessage( 1234 ),
+               new BeginLogEntriesMessageEncoder(),
+               new BeginLogEntriesMessageDecoder() );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesAckMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesAckMessageCodecTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesAckMessageCodecTest.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesAckMessageCodecTest.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,33 @@
+/*
+ *  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.mitosis.service.protocol.codec;
+
+import org.apache.directory.mitosis.service.protocol.codec.EndLogEntriesAckMessageDecoder;
+import org.apache.directory.mitosis.service.protocol.codec.EndLogEntriesAckMessageEncoder;
+import org.apache.directory.mitosis.service.protocol.message.EndLogEntriesAckMessage;
+
+public class EndLogEntriesAckMessageCodecTest extends AbstractMessageCodecTest {
+
+    public EndLogEntriesAckMessageCodecTest() {
+        super( new EndLogEntriesAckMessage( 1234, 5678 ),
+               new EndLogEntriesAckMessageEncoder(),
+               new EndLogEntriesAckMessageDecoder() );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesMessageCodecTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesMessageCodecTest.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesMessageCodecTest.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,33 @@
+/*
+ *  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.mitosis.service.protocol.codec;
+
+import org.apache.directory.mitosis.service.protocol.codec.EndLogEntriesMessageDecoder;
+import org.apache.directory.mitosis.service.protocol.codec.EndLogEntriesMessageEncoder;
+import org.apache.directory.mitosis.service.protocol.message.EndLogEntriesMessage;
+
+public class EndLogEntriesMessageCodecTest extends AbstractMessageCodecTest {
+
+    public EndLogEntriesMessageCodecTest() {
+        super( new EndLogEntriesMessage( 1234 ),
+               new EndLogEntriesMessageEncoder(),
+               new EndLogEntriesMessageDecoder() );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryAckMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryAckMessageCodecTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryAckMessageCodecTest.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryAckMessageCodecTest.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,33 @@
+/*
+ *  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.mitosis.service.protocol.codec;
+
+import org.apache.directory.mitosis.service.protocol.codec.LogEntryAckMessageDecoder;
+import org.apache.directory.mitosis.service.protocol.codec.LogEntryAckMessageEncoder;
+import org.apache.directory.mitosis.service.protocol.message.LogEntryAckMessage;
+
+public class LogEntryAckMessageCodecTest extends AbstractMessageCodecTest {
+
+    public LogEntryAckMessageCodecTest() {
+        super( new LogEntryAckMessage( 1234, 5678 ),
+               new LogEntryAckMessageEncoder(),
+               new LogEntryAckMessageDecoder() );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,57 @@
+/*
+ *  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.mitosis.service.protocol.codec;
+
+import javax.naming.InvalidNameException;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.ldap.LdapName;
+
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.common.SimpleCSN;
+import org.apache.directory.mitosis.operation.AddAttributeOperation;
+import org.apache.directory.mitosis.service.protocol.codec.LogEntryMessageDecoder;
+import org.apache.directory.mitosis.service.protocol.codec.LogEntryMessageEncoder;
+import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
+import org.apache.directory.mitosis.service.protocol.message.LogEntryMessage;
+
+public class LogEntryMessageCodecTest extends AbstractMessageCodecTest {
+
+    public LogEntryMessageCodecTest() throws InvalidNameException {
+        super( new LogEntryMessage( 1234,
+                                    new AddAttributeOperation(
+                                            new SimpleCSN( System.currentTimeMillis(), new
ReplicaId( "testReplica0" ), 1234 ),
+                                            new LdapName( "ou=system" ),
+                                            new BasicAttribute( "Hello", "Test" ) ) ),
+               new LogEntryMessageEncoder(),
+               new LogEntryMessageDecoder() );
+    }
+
+    protected boolean compare( BaseMessage expected0, BaseMessage actual0 ) {
+        LogEntryMessage expected = ( LogEntryMessage ) expected0;
+        LogEntryMessage actual = ( LogEntryMessage ) actual0;
+        
+        // We don't compare operation here because it is {@link OperationCodec}'s
+        // duty to serialize and deserialize Invocations.
+        return expected.getType() == actual.getType() &&
+               expected.getSequence() == actual.getSequence() &&
+               expected.getOperation().getCSN().equals( actual.getOperation().getCSN() )
&&
+               expected.getOperation().getClass() == actual.getOperation().getClass();
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,34 @@
+/*
+ *  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.mitosis.service.protocol.codec;
+
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.service.protocol.codec.LoginAckMessageDecoder;
+import org.apache.directory.mitosis.service.protocol.codec.LoginAckMessageEncoder;
+import org.apache.directory.mitosis.service.protocol.message.LoginAckMessage;
+
+public class LoginAckMessageCodecTest extends AbstractMessageCodecTest {
+
+    public LoginAckMessageCodecTest() {
+        super( new LoginAckMessage( 1234, 5678, new ReplicaId( "ReplicaABCD" ) ),
+               new LoginAckMessageEncoder(),
+               new LoginAckMessageDecoder() );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginMessageCodecTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginMessageCodecTest.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginMessageCodecTest.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,34 @@
+/*
+ *  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.mitosis.service.protocol.codec;
+
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.service.protocol.codec.LoginMessageDecoder;
+import org.apache.directory.mitosis.service.protocol.codec.LoginMessageEncoder;
+import org.apache.directory.mitosis.service.protocol.message.LoginMessage;
+
+public class LoginMessageCodecTest extends AbstractMessageCodecTest {
+
+    public LoginMessageCodecTest() {
+        super( new LoginMessage( 1234, new ReplicaId( "myReplica0" ) ),
+               new LoginMessageEncoder(),
+               new LoginMessageDecoder() );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java
(added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java
Thu Oct 12 11:33:14 2006
@@ -0,0 +1,409 @@
+/*
+ *  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.mitosis.store.derby;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.Name;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.ldap.LdapName;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.DirectoryServiceConfiguration;
+import org.apache.directory.server.core.DirectoryServiceListener;
+import org.apache.directory.server.core.configuration.MutableStartupConfiguration;
+import org.apache.directory.server.core.configuration.StartupConfiguration;
+import org.apache.directory.server.core.interceptor.InterceptorChain;
+import org.apache.directory.server.core.partition.PartitionNexus;
+import org.apache.directory.server.core.schema.global.GlobalRegistries;
+import org.apache.directory.mitosis.common.CSN;
+import org.apache.directory.mitosis.common.CSNFactory;
+import org.apache.directory.mitosis.common.CSNVector;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.common.SimpleCSN;
+import org.apache.directory.mitosis.common.SimpleCSNFactory;
+import org.apache.directory.mitosis.common.SimpleUUIDFactory;
+import org.apache.directory.mitosis.common.UUID;
+import org.apache.directory.mitosis.common.UUIDFactory;
+import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
+import org.apache.directory.mitosis.operation.AddAttributeOperation;
+import org.apache.directory.mitosis.operation.AddEntryOperation;
+import org.apache.directory.mitosis.operation.CompositeOperation;
+import org.apache.directory.mitosis.operation.DeleteAttributeOperation;
+import org.apache.directory.mitosis.operation.Operation;
+import org.apache.directory.mitosis.operation.ReplaceAttributeOperation;
+import org.apache.directory.mitosis.store.ReplicationLogIterator;
+import org.apache.directory.mitosis.store.ReplicationStoreException;
+import org.apache.directory.mitosis.store.derby.DerbyReplicationStore;
+
+public class DerbyReplicationStoreTest extends TestCase
+{
+    private static final ReplicaId REPLICA_ID = new ReplicaId( "TEST_REPLICA" );
+    private static final ReplicaId OTHER_REPLICA_ID = new ReplicaId( "OTHER_REPLICA" );
+    private static final ReplicaId OTHER_REPLICA_ID_2 = new ReplicaId( "OTHER_REPLICA_2"
);
+    private static final File DB_PATH = new File( "target/testDB" );
+
+    private final UUIDFactory uuidFactory = new SimpleUUIDFactory();
+    private final CSNFactory csnFactory = new SimpleCSNFactory();
+    private DerbyReplicationStore store;
+    private int testCount;
+    private long startTime;
+
+    public void setUp() throws Exception
+    {
+        dropDatabase();
+        startupDatabase( REPLICA_ID );
+        initStopWatch();
+    }
+
+    private void startupDatabase( ReplicaId replicaId ) throws Exception
+    {
+        // Prepare configuration
+        ReplicationConfiguration cfg = new ReplicationConfiguration();
+        cfg.setReplicaId( replicaId );
+        
+        // Open store
+        store = new DerbyReplicationStore();
+        store.setTablePrefix( "TEST_" );
+        store.open( new DirectoryServiceConfigurationImpl(), cfg );
+    }
+    
+    public void tearDown() throws Exception
+    {
+        store.close();
+        dropDatabase();
+    }
+
+    private void dropDatabase() throws IOException {
+        FileUtils.deleteDirectory( DB_PATH );
+        File logFile = new File( "derby.log" );
+        if( !logFile.delete() )
+        {
+            logFile.deleteOnExit();
+        }
+    }
+
+    public void testOperations() throws Exception
+    {
+        subTestReopen();
+        printElapsedTime( "Reopen" );
+        subTestUUID();
+        printElapsedTime( "UUID" );
+        subTestEmptyLog();
+        printElapsedTime( "EmptyLog" );
+        subTestWriteLog();
+        printElapsedTime( "WriteLog" );
+        subTestRemoveLogs();
+        printElapsedTime( "RemoveLogs" );
+        subTestVectors();
+        printElapsedTime( "Vectors" );
+    }
+    
+    private void subTestReopen() throws Exception
+    {
+        store.close();
+        try
+        {
+            startupDatabase( OTHER_REPLICA_ID );
+            Assert.fail( "Store cannot start up with wrong replica ID." );
+        }
+        catch( ReplicationStoreException e )
+        {
+        }
+        startupDatabase( REPLICA_ID );
+    }
+    
+    private void subTestUUID() throws Exception
+    {
+        UUID uuid = uuidFactory.newInstance();
+        Name name = new LdapName( "ou=a, ou=b" );
+        Assert.assertTrue( store.putUUID( uuid, name ) );
+        Assert.assertEquals( name, store.getDN( uuid ) );
+        Assert.assertTrue( store.removeUUID( uuid ) );
+        Assert.assertFalse( store.removeUUID( uuid ) );
+        Assert.assertNull( store.getDN( uuid ) );
+    }
+    
+    private void subTestEmptyLog() throws Exception
+    {
+        ReplicationLogIterator it;
+        
+        it = store.getLogs( csnFactory.newInstance( REPLICA_ID ), true );
+        Assert.assertFalse( it.next() );
+        it.close();
+        it = store.getLogs( csnFactory.newInstance( REPLICA_ID ), false );
+        Assert.assertFalse( it.next() );
+        it.close();
+        it = store.getLogs( csnFactory.newInstance( OTHER_REPLICA_ID ), true );
+        Assert.assertFalse( it.next() );
+        it.close();
+        it = store.getLogs( csnFactory.newInstance( OTHER_REPLICA_ID ), false );
+        Assert.assertFalse( it.next() );
+        it.close();
+        
+        Assert.assertEquals( 0, store.getLogSize() );
+    }
+
+    private void subTestWriteLog() throws Exception
+    {
+        CSN csn = csnFactory.newInstance( REPLICA_ID );
+        CompositeOperation op1 = new CompositeOperation( csn );
+        op1.add( new AddEntryOperation( csn, new LdapName( "ou=a" ), "ou=a", new BasicAttributes()
) );
+        op1.add( new AddAttributeOperation( csn, new LdapName( "ou=a" ), new BasicAttribute(
"id", "valie" ) ) );
+        op1.add( new ReplaceAttributeOperation( csn, new LdapName( "ou=a" ), new BasicAttribute(
"id", "valie" ) ) );
+        op1.add( new DeleteAttributeOperation( csn, new LdapName( "ou=a" ), new BasicAttribute(
"id", "valie" ) ) );
+        
+        store.putLog( op1 );
+        testGetLogs( csn, op1 );
+
+        csn = csnFactory.newInstance( OTHER_REPLICA_ID );
+        CompositeOperation op2 = new CompositeOperation( csn );
+        op2.add( new AddEntryOperation( csn, new LdapName( "ou=a" ), "ou=a", new BasicAttributes()
) );
+        op2.add( new AddAttributeOperation( csn, new LdapName( "ou=a" ), new BasicAttribute(
"id", "valie" ) ) );
+        op2.add( new ReplaceAttributeOperation( csn, new LdapName( "ou=a" ), new BasicAttribute(
"id", "valie" ) ) );
+        op2.add( new DeleteAttributeOperation( csn, new LdapName( "ou=a" ), new BasicAttribute(
"id", "valie" ) ) );
+        
+        store.putLog( op2 );
+        testGetLogs( csn, op2 );
+        
+        Assert.assertEquals( 2, store.getLogSize() );
+        Assert.assertEquals( 1, store.getLogSize( REPLICA_ID ) );
+        Assert.assertEquals( 1, store.getLogSize( OTHER_REPLICA_ID ) );
+        
+        // Test getLogs(CSNVector, true)
+        List expected = new ArrayList();
+        expected.add( op1 );
+        expected.add( op2 );
+        CSNVector updateVector = new CSNVector();
+        testGetLogs( updateVector, true, expected );
+        updateVector = new CSNVector();
+        updateVector.setCSN( op1.getCSN() );
+        testGetLogs( updateVector, true, expected );
+        updateVector = new CSNVector();
+        updateVector.setCSN( op2.getCSN() );
+        testGetLogs( updateVector, true, expected );
+        updateVector = new CSNVector();
+        updateVector.setCSN( op1.getCSN() );
+        updateVector.setCSN( op2.getCSN() );
+        testGetLogs( updateVector, true, expected );
+
+        // Test getLogs(CSNVector, false)
+        expected = new ArrayList();
+        expected.add( op1 );
+        expected.add( op2 );
+        updateVector = new CSNVector();
+        testGetLogs( updateVector, false, expected );
+        expected = new ArrayList();
+        expected.add( op2 );
+        updateVector = new CSNVector();
+        updateVector.setCSN( op1.getCSN() );
+        testGetLogs( updateVector, false, expected );
+        expected = new ArrayList();
+        expected.add( op1 );
+        updateVector = new CSNVector();
+        updateVector.setCSN( op2.getCSN() );
+        testGetLogs( updateVector, false, expected );
+        expected = new ArrayList();
+        updateVector = new CSNVector();
+        updateVector.setCSN( op1.getCSN() );
+        updateVector.setCSN( op2.getCSN() );
+        testGetLogs( updateVector, false, expected );
+    }
+    
+    private void subTestRemoveLogs()
+    {
+        CSN csn;
+        ReplicationLogIterator it;
+        
+        it = store.getLogs( new SimpleCSN( 0, REPLICA_ID, 0 ), false );
+        it.next();
+        csn = it.getOperation().getCSN();
+        it.close();
+        
+        Assert.assertEquals( 0, store.removeLogs( csn, false ) );
+        Assert.assertEquals( 1, store.removeLogs( csn, true ) );
+        Assert.assertEquals( 0, store.getLogSize( REPLICA_ID ) );
+
+        it = store.getLogs( new SimpleCSN( 0, OTHER_REPLICA_ID, 0 ), false );
+        Assert.assertTrue( it.next() );
+        csn = it.getOperation().getCSN();
+        it.close();
+        
+        Assert.assertEquals( 0, store.removeLogs( csn, false ) );
+        Assert.assertEquals( 1, store.removeLogs( csn, true ) );
+        Assert.assertEquals( 0, store.getLogSize( OTHER_REPLICA_ID ) );
+        
+        Assert.assertEquals( 0, store.getLogSize() );
+    }
+    
+    private void subTestVectors() throws Exception
+    {
+        CSN csnA = new SimpleCSN( 0, REPLICA_ID, 0 );
+        CSN csnB = new SimpleCSN( 1, REPLICA_ID, 0 );
+        CSN csnC = new SimpleCSN( 0, OTHER_REPLICA_ID_2, 0 );
+        CSN csnD = new SimpleCSN( 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 ) );
+        
+        Set expectedKnownReplicaIds = new HashSet();
+        expectedKnownReplicaIds.add( REPLICA_ID );
+        expectedKnownReplicaIds.add( OTHER_REPLICA_ID );
+        expectedKnownReplicaIds.add( OTHER_REPLICA_ID_2 );
+        
+        Assert.assertEquals( expectedKnownReplicaIds, store.getKnownReplicaIds() );
+        
+        CSNVector expectedUpdateVector = new CSNVector();
+        expectedUpdateVector.setCSN( csnB );
+        expectedUpdateVector.setCSN( csnD );
+        
+        Assert.assertEquals( expectedUpdateVector, store.getUpdateVector() );
+
+        CSNVector expectedPurgeVector = new CSNVector();
+        expectedPurgeVector.setCSN( csnA );
+        expectedPurgeVector.setCSN( csnC );
+        
+        Assert.assertEquals( expectedPurgeVector, store.getPurgeVector() );
+    }
+    
+    private void testGetLogs( CSN csn, Operation operation )
+    {
+        List operations = new ArrayList();
+        operations.add( operation );
+        testGetLogs( csn, operations );
+    }
+
+    private void testGetLogs( CSN csn, List operations )
+    {
+        Iterator it = operations.iterator();
+        ReplicationLogIterator rit;
+        
+        rit = store.getLogs( csn, true );
+        testGetLogs( it, rit );
+        
+        rit = store.getLogs( csn, false );
+        Assert.assertFalse( rit.next() );
+        rit.close();
+    }
+
+    private void testGetLogs( CSNVector updateVector, boolean inclusive, List operations
)
+    {
+        Iterator it = operations.iterator();
+        ReplicationLogIterator rit;
+        
+        rit = store.getLogs( updateVector, inclusive );
+        testGetLogs( it, rit );
+    }
+
+    private void testGetLogs( Iterator expectedIt, ReplicationLogIterator actualIt )
+    {
+        while( expectedIt.hasNext() )
+        {
+            Operation expected = ( Operation ) expectedIt.next();
+            Assert.assertTrue( actualIt.next() );
+
+            Operation actual = actualIt.getOperation();
+            Assert.assertEquals( expected.getCSN(), actual.getCSN() );
+            assertEquals( expected, actual );
+        }
+        Assert.assertFalse( actualIt.next() );
+        actualIt.close();
+    }
+
+    private void initStopWatch()
+    {
+        startTime = System.currentTimeMillis();
+    }
+    
+    private void printElapsedTime( String testName )
+    {
+        long endTime = System.currentTimeMillis();
+        System.out.println( "Subtest #" + ( ++testCount ) + " [" + testName + "]: " + ( endTime
- startTime ) + " ms" );
+        startTime = System.currentTimeMillis();
+    }
+    
+    private static void assertEquals( Operation expected, Operation actual )
+    {
+        Assert.assertEquals( expected.toString(), actual.toString() );
+    }
+    
+    private static class DirectoryServiceConfigurationImpl implements DirectoryServiceConfiguration
+    {
+        public DirectoryService getService()
+        {
+            return null;
+        }
+
+        public String getInstanceId()
+        {
+            return null;
+        }
+
+        public Hashtable getEnvironment()
+        {
+            return null;
+        }
+
+        public StartupConfiguration getStartupConfiguration()
+        {
+            MutableStartupConfiguration cfg = new MutableStartupConfiguration();
+            cfg.setWorkingDirectory( DB_PATH );
+            return cfg;
+        }
+
+        public GlobalRegistries getGlobalRegistries()
+        {
+            return null;
+        }
+
+        public PartitionNexus getPartitionNexus()
+        {
+            return null;
+        }
+
+        public InterceptorChain getInterceptorChain()
+        {
+            return null;
+        }
+
+        public boolean isFirstStart()
+        {
+            return false;
+        }
+
+        public DirectoryServiceListener getServiceListener()
+        {
+            return null;
+        }
+    }
+}



Mime
View raw message