mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

fdorson
06.05.2009 7938c7ece07363df886d2a3be2cd55870fffbfe4
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/common/ServerStateTest.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 */
package org.opends.server.replication.common;
@@ -30,9 +30,17 @@
import java.util.Set;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.AddOperationBasis;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.replication.ReplicationTestCase;
import org.opends.server.replication.common.ChangeNumber;
import org.opends.server.replication.common.ServerState;
import org.opends.server.replication.plugin.LDAPReplicationDomain;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.ResultCode;
import org.opends.server.util.TimeThread;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -102,4 +110,86 @@
    assertEquals(b, generatedServerState.getBytes()) ;
  }
  /**
   * Ensures that the Directory Server is able to
   * translate a ruv entry to a sever state.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test
  public void translateRuvEntryTest()
         throws Exception
  {
    Entry synchroServerEntry = null;
    String RuvString =
      "dn: nsuniqueid=ffffffff-ffffffff-ffffffff-ffffffff, o=test\n"
      +"objectClass: top\n"
      +"objectClass: extensibleobject\n"
      +"objectClass: ldapSubEntry\n"
      +"o: test\n"
      +"nsds50ruv: {replicageneration} 49098853000000010000\n"
      +"nsds50ruv: {replica 3 ldap://kawax:3389} 491d517b000000030000 "
      +"491d564a000000030000\n"
      +"nsds50ruv: {replica 1 ldap://kawax:1389} 490989e8000000010000 "
      +"490989e8000000010000\n"
      +"ds6ruv: {PRIO 3 ldap://kawax:3389}\n"
      +"ds6ruv: {PRIO 1 ldap://kawax:1389}\n"
      +"entryUUID: ffffffff-ffff-ffff-ffff-ffffffffffff\n";
    Entry RuvEntry = TestCaseUtils.entryFromLdifString(RuvString);
    AddOperationBasis addOp = new AddOperationBasis(InternalClientConnection.
        getRootConnection(), InternalClientConnection.nextOperationID(),
        InternalClientConnection.nextMessageID(), null, RuvEntry.getDN(),
        RuvEntry.getObjectClasses(), RuvEntry.getUserAttributes(),
        RuvEntry.getOperationalAttributes());
    addOp.setInternalOperation(true);
    addOp.run();
    assertTrue(addOp.getResultCode() == ResultCode.SUCCESS);
    // Instantiate a Replication domain
    // suffix synchronized
    String synchroServerLdif =
      "dn: cn=o=test, cn=domains, cn=Multimaster Synchronization, cn=Synchronization Providers,cn=config\n"
      + "objectClass: top\n"
      + "objectClass: ds-cfg-replication-domain\n"
      + "cn: o=test\n"
      + "ds-cfg-base-dn: o=test\n"
      + "ds-cfg-replication-server: localhost:3389\n"
      + "ds-cfg-server-id: 1\n"
      + "ds-cfg-receive-status: true\n"
      + "ds-cfg-window-size: 10";
    // When adding the replicationDomain entry the checkRUVCompat
    // method is called and should translate the RuvEntry Added
    // into a serverState + generationId
    synchroServerEntry = TestCaseUtils.entryFromLdifString(synchroServerLdif);
    DirectoryServer.getConfigHandler().addEntry(synchroServerEntry, null);
    assertNotNull(DirectoryServer.getConfigEntry(synchroServerEntry.getDN()),
      "Unable to add the synchronized server");
    LDAPReplicationDomain replDomain = LDAPReplicationDomain.
    retrievesReplicationDomain(DN.decode("o=test"));
    // Then check serverSate and GenId
    assertTrue(replDomain.getGenerationID() == 1225361491);
    ServerState state = replDomain.getServerState();
    assertTrue(state.getMaxChangeNumber((short) 1).
        compareTo(new ChangeNumber("0000011d4d42b240000100000000")) == 0);
    assertTrue(state.getMaxChangeNumber((short) 3).
        compareTo(new ChangeNumber("0000011d9a991110000300000000")) == 0);
    // Remove the configuration entry
    DirectoryServer.getConfigHandler().deleteEntry(synchroServerEntry.getDN(),
        null);
    assertNull(DirectoryServer.getConfigEntry(synchroServerEntry.getDN()),
      "Unable to remove the synchronized server");
  }
}