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

Jean-Noel Rouvignac
21.39.2015 a9ef51ce0ecc2f38368f9999debb71ea6b47df90
Test code cleanup


NamingConflictTest.java
Extracted fields to simplify code in test methods.
Extracted methods setUpLocal(), tearDown(), addMsg(), modDnMsg(), replayMsg(), createAndAddEntry(), createParentEntry(), createChildEntry().

ModifyConflictTest.java:
Made the code a bit more readable.
2 files modified
570 ■■■■■ changed files
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java 80 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/NamingConflictTest.java 490 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java
@@ -594,7 +594,7 @@
    EntryHistorical hist = EntryHistorical.newInstanceFromEntry(entry);
    // simulate a REPLACE of the attribute with values : value1, value2, value3 at time t1.
    Modification mod = new Modification(REPLACE, Attributes.create(DESCRIPTION, "value1", "value2", "value3"));
    Modification mod = newModification(REPLACE, DESCRIPTION, "value1", "value2", "value3");
    testModify(entry, hist, 1, true, mod);
    Attribute attr = buildSyncHist(DESCRIPTION,
@@ -604,9 +604,8 @@
    assertEquals(hist.encodeAndPurge(), attr);
    // simulate a DELETE of the attribute values : value3 and value4 at time t2.
    mod = new Modification(DELETE, Attributes.create(DESCRIPTION, "value3", "value4"));
    List<Modification> mods = replayModify(entry, hist, mod, 2);
    mod = newModification(DELETE, DESCRIPTION, "value3", "value4");
    List<Modification> mods = replayModify(entry, hist, 2, mod);
    mod = mods.get(0);
    assertEquals(mod.getAttribute(), Attributes.create(DESCRIPTION, "value3"));
    assertEquals(mod.getModificationType(), DELETE);
@@ -636,9 +635,11 @@
    Attribute values3and4 = Attributes.create(DESCRIPTION, "value3", "value4");
    Attribute values1and2 = Attributes.create(DESCRIPTION, "value1", "value2");
    Modification mod;
    List<Modification> mods;
    // simulate a DELETE of the attribute values : value3 and value4 at time t2.
    Modification mod = new Modification(DELETE, values3and4);
    List<Modification> mods = replayModify(entry, hist, mod, 2);
    mod = new Modification(DELETE, values3and4);
    mods = replayModify(entry, hist, 2, mod);
    entry.applyModifications(mods);
    // check that the MOD is not altered by the replay mechanism.
    mod = mods.get(0);
@@ -646,8 +647,7 @@
    assertEquals(mod.getAttribute(), values3and4);
    // check that the entry now contains value1 and value2 and no other values.
    AttributeType descriptionAttrType = getAttributeType(DESCRIPTION);
    Attribute resultEntryAttr = entry.getAttribute(descriptionAttrType).get(0);
    Attribute resultEntryAttr = entry.getAttribute(DESCRIPTION).get(0);
    assertEquals(resultEntryAttr, values1and2);
    Attribute attr = buildSyncHist(DESCRIPTION,
@@ -657,8 +657,8 @@
    // simulate a REPLACE of the attribute with values : value1, value2, value3
    // at time t1.
    mod = new Modification(REPLACE, Attributes.create(DESCRIPTION, "value1", "value2", "value3"));
    mods = replayModify(entry, hist, mod, 1);
    mod = newModification(REPLACE, DESCRIPTION, "value1", "value2", "value3");
    mods = replayModify(entry, hist, 1, mod);
    entry.applyModifications(mods);
    mod = mods.get(0);
    // check that value3 has been removed from the MOD-REPLACE because
@@ -774,7 +774,7 @@
    Modification mod2 = newModification(ADD, DESCRIPTION, "Init Value");
    List<Modification> mods = newLinkedList(mod1, mod2);
    replayModifies(entry, hist, mods, 11);
    replayModifies(entry, hist, 11, mods);
    assertThat(mods).as("DEL and ADD of the same attribute same value was not correct").containsExactly(mod1, mod2);
    attr = buildSyncHist(DESCRIPTION,
        ":000000000000000b000000000000:add:Init Value");
@@ -821,12 +821,12 @@
    List<Modification> mods = newLinkedList(mod1, mod2);
    List<Modification> mods2 = new LinkedList<>(mods);
    replayModifies(entry, hist, mods, 12);
    replayModifies(entry, hist, 12, mods);
    assertEquals(hist.encodeAndPurge(), attrDel);
    assertThat(mods).as("DEL one value, del by Replace of the same attribute was not correct").containsExactly(mod1, mod2);
    // Replay the same modifs again
    replayModifies(entry, hist, mods2, 12);
    replayModifies(entry, hist, 12, mods2);
    assertEquals(hist.encodeAndPurge(), attrDel);
    assertEquals(mods2.size(), 2,
      "DEL one value, del by Replace of the same attribute was not correct");
@@ -850,7 +850,7 @@
    Modification mod2 = newModification(DELETE, DESCRIPTION, "Init Value");
    List<Modification> mods = newLinkedList(mod1, mod2);
    replayModifies(entry, hist, mods, 11);
    replayModifies(entry, hist, 11, mods);
    Attribute attr = buildSyncHist(DESCRIPTION,
        ":000000000000000b000000000000:del:Init Value");
    assertEquals(hist.encodeAndPurge(), attr);
@@ -935,21 +935,23 @@
        ":000000000000000a000000000000:add:init value");
    assertEquals(hist.encodeAndPurge(), attr);
    Modification mod;
    List<Modification> mods;
    /*
     * Now simulate an add at an earlier date that the previous add. The
     * conflict resolution should detect that this add must be kept.
     * and that the previous value must be discarded, and therefore
     * turn the add into a replace.
     */
    Modification mod = newModification(ADD, DISPLAYNAME, "older value");
    List<Modification> mods = replayModify(entry, hist, mod, 1);
    mod = newModification(ADD, DISPLAYNAME, "older value");
    mods = replayModify(entry, hist, 1, mod);
    assertEquals(hist.encodeAndPurge(), olderValue);
    /*
     * After replay the mods should contain only one mod,
     * the mod should now be a replace with the older value.
     */
    testMods(mods, 1, REPLACE, "older value");
    assertUniqueMod(mods, REPLACE, "older value");
    /*
     * Now simulate a new value at a later date.
@@ -957,7 +959,7 @@
     * and skip this change.
     */
    mod = newModification(ADD, DISPLAYNAME, "new value");
    mods = replayModify(entry, hist, mod, 2);
    mods = replayModify(entry, hist, 2, mod);
    assertEquals(hist.encodeAndPurge(), olderValue);
    assertTrue(mods.isEmpty());
  }
@@ -1020,9 +1022,8 @@
    assertEquals(hist.encodeAndPurge(), firstValue);
    /*
     * simulate a add of the displayName attribute done at time t2
     * with a second value. This should not work because there is already
     * a value
     * simulate a add of the displayName attribute done at time t2 with a second value.
     * This should not work because there is already a value
     */
    testModify(entry, hist, 2, false, newModification(ADD, DISPLAYNAME, "second value"));
    assertEquals(hist.encodeAndPurge(), firstValue);
@@ -1040,19 +1041,17 @@
   * Check that the mods given as first parameter match the next parameters.
   *
   * @param mods The mods that must be tested.
   * @param size the size that the mods must have.
   * @param modType the type of Modification that the first mod of the
   *                mods should have.
   * @param value the value that the first mod of the mods should have.
   */
  private void testMods(
      List<Modification> mods, int size, ModificationType modType, String value)
  private void assertUniqueMod(List<Modification> mods, ModificationType modType, String value)
  {
    assertEquals(size, mods.size());
    Modification newMod = mods.get(0);
    assertEquals(newMod.getModificationType(), modType);
    ByteString val = newMod.getAttribute().iterator().next();
    assertEquals(val.toString(), value);
    assertThat(mods).hasSize(1);
    Modification mod = mods.get(0);
    assertEquals(mod.getModificationType(), modType);
    String firstVal = mod.getAttribute().iterator().next().toString();
    assertEquals(firstVal, value);
  }
  /** Create an initialize an entry that can be used for modify conflict resolution tests. */
@@ -1117,7 +1116,7 @@
  private void testModify(Entry entry, EntryHistorical hist, int date,
      boolean keepChangeResult, Modification mod) throws DirectoryException
  {
    List<Modification> mods = replayModify(entry, hist, mod, date);
    List<Modification> mods = replayModify(entry, hist, date, mod);
    if (keepChangeResult)
    {
@@ -1140,22 +1139,16 @@
    entry.applyModifications(mods);
  }
  private void replayModifies(Entry entry, EntryHistorical hist, List<Modification> mods, int date)
  private void replayModifies(Entry entry, EntryHistorical hist, int date, List<Modification> mods)
  {
    CSN t = new CSN(date, 0, 0);
    LocalBackendModifyOperation modOp = modifyOperation(entry, t, mods);
    LocalBackendModifyOperation modOp = modifyOperation(entry, date, mods);
    hist.replayOperation(modOp, entry);
  }
  private List<Modification> replayModify(
      Entry entry, EntryHistorical hist, Modification mod, int date)
  private List<Modification> replayModify(Entry entry, EntryHistorical hist, int date, Modification mod)
  {
    CSN t = new CSN(date, 0, 0);
    List<Modification> mods = newArrayList(mod);
    LocalBackendModifyOperation modOp = modifyOperation(entry, t, mods);
    LocalBackendModifyOperation modOp = modifyOperation(entry, date, mods);
    hist.replayOperation(modOp, entry);
    if (mod.getModificationType() == ADD)
@@ -1192,12 +1185,12 @@
    return new LocalBackendAddOperation(addOpBasis);
  }
  private LocalBackendModifyOperation modifyOperation(Entry entry, CSN t, List<Modification> mods)
  private LocalBackendModifyOperation modifyOperation(Entry entry, int date, List<Modification> mods)
  {
    ModifyOperationBasis modOpBasis = new ModifyOperationBasis(getRootConnection(), 1, 1,
        null, entry.getName(), mods);
    LocalBackendModifyOperation modOp = new LocalBackendModifyOperation(modOpBasis);
    modOp.setAttachment(SYNCHROCONTEXT, new ModifyContext(t, "uniqueId"));
    modOp.setAttachment(SYNCHROCONTEXT, new ModifyContext(new CSN(date, 0, 0), "uniqueId"));
    return modOp;
  }
@@ -1216,8 +1209,7 @@
    return builder.toAttribute();
  }
  private void assertContainsOnlyValues(Entry entry, String attrName,
      String... expectedValues)
  private void assertContainsOnlyValues(Entry entry, String attrName, String... expectedValues)
  {
    List<Attribute> attrs = entry.getAttribute(attrName);
    Attribute attr = attrs.get(0);
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/NamingConflictTest.java
@@ -35,31 +35,61 @@
import org.opends.server.admin.std.meta.ReplicationDomainCfgDefn.IsolationPolicy;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyDNOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.replication.ReplicationTestCase;
import org.opends.server.replication.common.CSN;
import org.opends.server.replication.common.CSNGenerator;
import org.opends.server.replication.protocol.AddMsg;
import org.opends.server.replication.protocol.DeleteMsg;
import org.opends.server.replication.protocol.ModifyDNMsg;
import org.opends.server.replication.protocol.UpdateMsg;
import org.opends.server.types.Attribute;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.RDN;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.testng.Assert.*;
/**
 * Test the naming conflict resolution code.
 */
/** Test the naming conflict resolution code. */
@SuppressWarnings("javadoc")
public class NamingConflictTest extends ReplicationTestCase
{
  private static final AtomicBoolean SHUTDOWN = new AtomicBoolean(false);
  private DN baseDN;
  private LDAPReplicationDomain domain;
  private CSNGenerator gen;
  private TestSynchronousReplayQueue queue;
  @BeforeMethod
  public void setUpLocal() throws Exception
  {
    baseDN = DN.valueOf(TEST_ROOT_DN_STRING);
    TestCaseUtils.initializeTestBackend(true);
    queue = new TestSynchronousReplayQueue();
    final DomainFakeCfg conf = new DomainFakeCfg(baseDN, 1, new TreeSet<String>());
    conf.setIsolationPolicy(IsolationPolicy.ACCEPT_ALL_UPDATES);
    domain = MultimasterReplication.createNewDomain(conf, queue);
    domain.start();
    gen = new CSNGenerator(201, 0);
  }
  @AfterMethod
  public void tearDown() throws Exception
  {
    MultimasterReplication.deleteDomain(baseDN);
  }
  /**
   * Test for issue 3402 : test, that a modrdn that is older than an other
   * modrdn but that is applied later is ignored.
@@ -72,152 +102,51 @@
   * It then uses this session to simulate conflicts and therefore
   * test the naming conflict resolution code.
   */
  @Test(enabled=true)
  @Test
  public void simultaneousModrdnConflict() throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    String parentUUID = getEntryUUID(baseDN);
    final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING);
    TestSynchronousReplayQueue queue = new TestSynchronousReplayQueue();
    DomainFakeCfg conf = new DomainFakeCfg(baseDN, 1, new TreeSet<String>());
    conf.setIsolationPolicy(IsolationPolicy.ACCEPT_ALL_UPDATES);
    LDAPReplicationDomain domain =
      MultimasterReplication.createNewDomain(conf, queue);
    domain.start();
    try
    {
      /*
       * Create a CSN generator to generate new CSNs
       * when we need to send operations messages to the replicationServer.
       */
      CSNGenerator gen = new CSNGenerator(201, 0);
      String parentUUID = getEntryUUID(DN.valueOf(TEST_ROOT_DN_STRING));
      Entry entry = TestCaseUtils.entryFromLdifString(
          "dn: cn=simultaneousModrdnConflict, "+ TEST_ROOT_DN_STRING + "\n"
          + "objectClass: top\n" + "objectClass: person\n"
          + "objectClass: organizationalPerson\n"
          + "objectClass: inetOrgPerson\n" + "uid: user.1\n"
          + "description: This is the description for Aaccf Amar.\n" + "st: NC\n"
          + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
          + "$Rockford, NC  85762\n" + "mail: user.1@example.com\n"
          + "cn: Aaccf Amar\n" + "l: Rockford\n"
          + "street: 17984 Thirteenth Street\n"
          + "employeeNumber: 1\n"
          + "sn: Amar\n" + "givenName: Aaccf\n" + "postalCode: 85762\n"
          + "userPassword: password\n" + "initials: AA\n");
      TestCaseUtils.addEntry(entry);
    Entry entry = createAndAddEntry("simultaneousModrdnConflict");
      String entryUUID = getEntryUUID(entry.getName());
      // generate two consecutive CSN that will be used in backward order
      CSN csn1 = gen.newCSN();
      CSN csn2 = gen.newCSN();
      ModifyDNMsg  modDnMsg = new ModifyDNMsg(
          entry.getName(), csn2,
          entryUUID, parentUUID, false,
          TEST_ROOT_DN_STRING,
      "uid=simultaneous2");
    replayMsg(modDnMsg(entry, entryUUID, parentUUID, csn2, "uid=simultaneous2"));
      // Put the message in the replay queue
      domain.processUpdate(modDnMsg);
      // Make the domain replay the change from the replay queue
      domain.replay(queue.take().getUpdateMessage(), SHUTDOWN);
      // This MODIFY DN uses an older DN and should therefore be cancelled
      // at replay time.
      modDnMsg = new ModifyDNMsg(
          entry.getName(), csn1,
          entryUUID, parentUUID, false,
          TEST_ROOT_DN_STRING,
      "uid=simulatneouswrong");
      // Put the message in the replay queue
      domain.processUpdate(modDnMsg);
      // Make the domain replay the change from the replay queue
      // and resolve conflict
      domain.replay(queue.take().getUpdateMessage(), SHUTDOWN);
    // This MODIFY DN uses an older DN and should therefore be cancelled at replay time.
    replayMsg(modDnMsg(entry, entryUUID, parentUUID, csn1, "uid=simulatneouswrong"));
      // Expect the conflict resolution
      assertFalse(DirectoryServer.entryExists(entry.getName()),
      "The modDN conflict was not resolved as expected.");
    assertFalse(entryExists(entry.getName()), "The modDN conflict was not resolved as expected.");
    }
    finally
  private ModifyDNMsg modDnMsg(Entry entry, String entryUUID, String parentUUID, CSN csn, String newRDN)
      throws Exception
    {
      MultimasterReplication.deleteDomain(baseDN);
    }
    return new ModifyDNMsg(entry.getName(), csn, entryUUID, parentUUID, false, TEST_ROOT_DN_STRING, newRDN);
  }
  /**
   * Test that when a previous conflict is resolved because
   * a delete operation has removed one of the conflicting entries
   * the other conflicting entry is correctly renamed to its
   * original name.
   * the other conflicting entry is correctly renamed to its original name.
   */
  @Test(enabled=true)
  @Test
  public void conflictCleaningDelete() throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING);
    TestSynchronousReplayQueue queue = new TestSynchronousReplayQueue();
    DomainFakeCfg conf = new DomainFakeCfg(baseDN, 1, new TreeSet<String>());
    conf.setIsolationPolicy(IsolationPolicy.ACCEPT_ALL_UPDATES);
    LDAPReplicationDomain domain =
      MultimasterReplication.createNewDomain(conf, queue);
    domain.start();
    try
    {
      /*
       * Create a CSN generator to generate new CSNs
       * when we need to send operations messages to the replicationServer.
       */
      CSNGenerator gen = new CSNGenerator(201, 0);
      String entryldif =
        "dn: cn=conflictCleaningDelete, "+ TEST_ROOT_DN_STRING + "\n"
        + "objectClass: top\n" + "objectClass: person\n"
        + "objectClass: organizationalPerson\n"
        + "objectClass: inetOrgPerson\n" + "uid: user.1\n"
        + "description: This is the description for Aaccf Amar.\n" + "st: NC\n"
        + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
        + "$Rockford, NC  85762\n" + "mail: user.1@example.com\n"
        + "cn: Aaccf Amar\n" + "l: Rockford\n"
        + "street: 17984 Thirteenth Street\n"
        + "employeeNumber: 1\n"
        + "sn: Amar\n" + "givenName: Aaccf\n" + "postalCode: 85762\n"
        + "userPassword: password\n" + "initials: AA\n";
      Entry entry = TestCaseUtils.entryFromLdifString(entryldif);
    Entry entry = createAndAddEntry("conflictCleaningDelete");
      // Add the first entry
      TestCaseUtils.addEntry(entry);
      String parentUUID = getEntryUUID(DN.valueOf(TEST_ROOT_DN_STRING));
    String parentUUID = getEntryUUID(baseDN);
      CSN csn1 = gen.newCSN();
      // Now try to add the same entry with same DN but a different
      // unique ID though the replication
      AddMsg addMsg = new AddMsg(csn1,
            entry.getName(),
            "c9cb8c3c-615a-4122-865d-50323aaaed48", parentUUID,
            entry.getObjectClasses(), entry.getUserAttributes(),
            null);
      // Put the message in the replay queue
      domain.processUpdate(addMsg);
      // Make the domain replay the change from the replay queue
      domain.replay(queue.take().getUpdateMessage(), SHUTDOWN);
    replayMsg(addMsg(entry, csn1, parentUUID, "c9cb8c3c-615a-4122-865d-50323aaaed48"));
      // Now delete the first entry that was added at the beginning
      TestCaseUtils.deleteEntry(entry.getName());
@@ -231,84 +160,36 @@
          "The wrong entry has been renamed");
      assertNull(resultEntry.getAttribute(LDAPReplicationDomain.DS_SYNC_CONFLICT));
    }
    finally
  private AddMsg addMsg(Entry entry, CSN csn, String parentUUID, String childUUID)
    {
      MultimasterReplication.deleteDomain(baseDN);
    }
    return new AddMsg(csn,
          entry.getName(),
          childUUID, parentUUID,
          entry.getObjectClasses(), entry.getUserAttributes(),
          null);
  }
  /**
   * Test that when a previous conflict is resolved because
   * a MODDN operation has removed one of the conflicting entries
   * the other conflicting entry is correctly renamed to its
   * original name.
   *
   * @throws Exception if the test fails.
   * the other conflicting entry is correctly renamed to its original name.
   */
  @Test(enabled=true)
  @Test
  public void conflictCleaningMODDN() throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING);
    TestSynchronousReplayQueue queue = new TestSynchronousReplayQueue();
    DomainFakeCfg conf = new DomainFakeCfg(baseDN, 1, new TreeSet<String>());
    conf.setIsolationPolicy(IsolationPolicy.ACCEPT_ALL_UPDATES);
    LDAPReplicationDomain domain =
      MultimasterReplication.createNewDomain(conf, queue);
    domain.start();
    try
    {
      /*
       * Create a CSN generator to generate new CSNs when we need to send
       * operations messages to the replicationServer.
       */
      CSNGenerator gen = new CSNGenerator(201, 0);
      String entryldif =
        "dn: cn=conflictCleaningDelete, "+ TEST_ROOT_DN_STRING + "\n"
        + "objectClass: top\n" + "objectClass: person\n"
        + "objectClass: organizationalPerson\n"
        + "objectClass: inetOrgPerson\n" + "uid: user.1\n"
        + "description: This is the description for Aaccf Amar.\n" + "st: NC\n"
        + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
        + "$Rockford, NC  85762\n" + "mail: user.1@example.com\n"
        + "cn: Aaccf Amar\n" + "l: Rockford\n"
        + "street: 17984 Thirteenth Street\n"
        + "employeeNumber: 1\n"
        + "sn: Amar\n" + "givenName: Aaccf\n" + "postalCode: 85762\n"
        + "userPassword: password\n" + "initials: AA\n";
      Entry entry = TestCaseUtils.entryFromLdifString(entryldif);
      // Add the first entry
      TestCaseUtils.addEntry(entry);
      String parentUUID = getEntryUUID(DN.valueOf(TEST_ROOT_DN_STRING));
    Entry entry = createAndAddEntry("conflictCleaningDelete");
    String parentUUID = getEntryUUID(baseDN);
      CSN csn1 = gen.newCSN();
      // Now try to add the same entry with same DN but a different
      // unique ID though the replication
      AddMsg addMsg = new AddMsg(csn1,
            entry.getName(),
            "c9cb8c3c-615a-4122-865d-50323aaaed48", parentUUID,
            entry.getObjectClasses(), entry.getUserAttributes(),
            null);
      // Put the message in the replay queue
      domain.processUpdate(addMsg);
      // Make the domain replay the change from the replay queue
      domain.replay(queue.take().getUpdateMessage(), SHUTDOWN);
    replayMsg(addMsg(entry, csn1, parentUUID, "c9cb8c3c-615a-4122-865d-50323aaaed48"));
      // Now delete the first entry that was added at the beginning
      InternalClientConnection conn =
        InternalClientConnection.getRootConnection();
      ModifyDNOperation modDNOperation =
        conn.processModifyDN(entry.getName(), RDN.decode("cn=foo"), false);
        getRootConnection().processModifyDN(entry.getName(), RDN.decode("cn=foo"), false);
      assertEquals(modDNOperation.getResultCode(), ResultCode.SUCCESS);
      // Expect the conflict resolution : the second entry should now
@@ -320,10 +201,32 @@
          "The wrong entry has been renamed");
      assertNull(resultEntry.getAttribute(LDAPReplicationDomain.DS_SYNC_CONFLICT));
    }
    finally
  private Entry createAndAddEntry(String commonName) throws Exception
    {
      MultimasterReplication.deleteDomain(baseDN);
    }
    Entry entry = TestCaseUtils.entryFromLdifString(
        "dn: cn=" + commonName + ", " + TEST_ROOT_DN_STRING + "\n"
        + "objectClass: top\n"
        + "objectClass: person\n"
        + "objectClass: organizationalPerson\n"
        + "objectClass: inetOrgPerson\n"
        + "uid: user.1\n"
        + "description: This is the description for Aaccf Amar.\n"
        + "st: NC\n"
        + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
        + "$Rockford, NC  85762\n"
        + "mail: user.1@example.com\n"
        + "cn: Aaccf Amar\n"
        + "l: Rockford\n"
        + "street: 17984 Thirteenth Street\n"
        + "employeeNumber: 1\n"
        + "sn: Amar\n"
        + "givenName: Aaccf\n"
        + "postalCode: 85762\n"
        + "userPassword: password\n"
        + "initials: AA\n");
    TestCaseUtils.addEntry(entry);
    return entry;
  }
  /**
@@ -350,48 +253,11 @@
   *                           - the child entry to be renamed under root entry
   *
   */
  @Test(enabled=true)
  @Test
  public void removeParentConflict1() throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING);
    TestSynchronousReplayQueue queue = new TestSynchronousReplayQueue();
    DomainFakeCfg conf = new DomainFakeCfg(baseDN, 1, new TreeSet<String>());
    conf.setIsolationPolicy(IsolationPolicy.ACCEPT_ALL_UPDATES);
    LDAPReplicationDomain domain =
      MultimasterReplication.createNewDomain(conf, queue);
    domain.start();
    try
    {
      /*
       * Create a CSN generator to generate new CSNs
       * when we need to send operations messages to the replicationServer.
       */
      CSNGenerator gen = new CSNGenerator(201, 0);
      Entry parentEntry = TestCaseUtils.entryFromLdifString(
          "dn: ou=rpConflict, "+ TEST_ROOT_DN_STRING + "\n"
          + "objectClass: top\n"
          + "objectClass: organizationalUnit\n");
      Entry childEntry = TestCaseUtils.entryFromLdifString(
          "dn: cn=child, ou=rpConflict,"+ TEST_ROOT_DN_STRING + "\n"
          + "objectClass: top\n"
          + "objectClass: person\n"
          + "objectClass: organizationalPerson\n"
          + "objectClass: inetOrgPerson\n" + "uid: user.1\n"
          + "description: This is the description for Aaccf Amar.\n" + "st: NC\n"
          + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
          + "$Rockford, NC  85762\n" + "mail: user.1@example.com\n"
          + "cn: Aaccf Amar\n" + "l: Rockford\n"
          + "street: 17984 Thirteenth Street\n"
          + "employeeNumber: 1\n"
          + "sn: Amar\n" + "givenName: Aaccf\n" + "postalCode: 85762\n"
          + "userPassword: password\n" + "initials: AA\n");
    Entry parentEntry = createParentEntry();
    Entry childEntry = createChildEntry();
      TestCaseUtils.addEntry(parentEntry);
      TestCaseUtils.addEntry(childEntry);
@@ -402,65 +268,18 @@
      DeleteMsg  delMsg = new DeleteMsg(parentEntry.getName(), csn2, parentUUID);
      delMsg.setSubtreeDelete(true);
      // Put the message in the replay queue
      domain.processUpdate(delMsg);
      // Make the domain replay the change from the replay queue
      domain.replay(queue.take().getUpdateMessage(), SHUTDOWN);
    replayMsg(delMsg);
      // Expect the subtree to be deleted and no conflict entry created
      assertFalse(DirectoryServer.entryExists(parentEntry.getName()),
      "DEL subtree on parent was not processed as expected.");
      assertFalse(DirectoryServer.entryExists(parentEntry.getName()),
      "DEL subtree on parent was not processed as expected.");
    }
    finally
    {
      MultimasterReplication.deleteDomain(baseDN);
    }
    assertFalse(entryExists(parentEntry.getName()), "DEL subtree on parent was not processed as expected.");
    assertFalse(entryExists(parentEntry.getName()), "DEL subtree on parent was not processed as expected.");
  }
  @Test(enabled=true)
  @Test
  public void removeParentConflict2() throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING);
    TestSynchronousReplayQueue queue = new TestSynchronousReplayQueue();
    DomainFakeCfg conf = new DomainFakeCfg(baseDN, 1, new TreeSet<String>());
    conf.setIsolationPolicy(IsolationPolicy.ACCEPT_ALL_UPDATES);
    LDAPReplicationDomain domain =
      MultimasterReplication.createNewDomain(conf, queue);
    domain.start();
    try
    {
      /*
       * Create a CSN generator to generate new CSNs
       * when we need to send operations messages to the replicationServer.
       */
      CSNGenerator gen = new CSNGenerator(201, 0);
      Entry parentEntry = TestCaseUtils.entryFromLdifString(
          "dn: ou=rpConflict, "+ TEST_ROOT_DN_STRING + "\n"
          + "objectClass: top\n"
          + "objectClass: organizationalUnit\n");
      Entry childEntry = TestCaseUtils.entryFromLdifString(
          "dn: cn=child, ou=rpConflict,"+ TEST_ROOT_DN_STRING + "\n"
          + "objectClass: top\n"
          + "objectClass: person\n"
          + "objectClass: organizationalPerson\n"
          + "objectClass: inetOrgPerson\n" + "uid: user.1\n"
          + "description: This is the description for Aaccf Amar.\n" + "st: NC\n"
          + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
          + "$Rockford, NC  85762\n" + "mail: user.1@example.com\n"
          + "cn: Aaccf Amar\n" + "l: Rockford\n"
          + "street: 17984 Thirteenth Street\n"
          + "employeeNumber: 1\n"
          + "sn: Amar\n" + "givenName: Aaccf\n" + "postalCode: 85762\n"
          + "userPassword: password\n" + "initials: AA\n");
    Entry parentEntry = createParentEntry();
    Entry childEntry = createChildEntry();
      TestCaseUtils.addEntry(parentEntry);
      TestCaseUtils.addEntry(childEntry);
@@ -472,70 +291,22 @@
      DeleteMsg  delMsg = new DeleteMsg(parentEntry.getName(), csn2, parentUUID);
      // NOT SUBTREE
      // Put the message in the replay queue
      domain.processUpdate(delMsg);
      // Make the domain replay the change from the replay queue
      domain.replay(queue.take().getUpdateMessage(), SHUTDOWN);
    replayMsg(delMsg);
      // Expect the parent entry to be deleted
      assertFalse(DirectoryServer.entryExists(parentEntry.getName()), "Parent entry expected to be deleted : " + parentEntry.getName());
    assertFalse(entryExists(parentEntry.getName()), "Parent entry expected to be deleted : " + parentEntry.getName());
      // Expect the child entry to be moved as conflict entry under the root
      // entry of the suffix
      DN childDN = DN.valueOf("entryuuid="+childUUID+
          "+cn=child,o=test");
      assertTrue(DirectoryServer.entryExists(childDN),
          "Child entry conflict exist with DN="+childDN);
    }
    finally
    {
      MultimasterReplication.deleteDomain(baseDN);
    }
    DN childDN = DN.valueOf("entryuuid=" + childUUID + "+cn=child,o=test");
    assertTrue(entryExists(childDN), "Child entry conflict exist with DN=" + childDN);
  }
  @Test(enabled=true)
  @Test
  public void removeParentConflict3() throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING);
    TestSynchronousReplayQueue queue = new TestSynchronousReplayQueue();
    DomainFakeCfg conf = new DomainFakeCfg(baseDN, 1, new TreeSet<String>());
    conf.setIsolationPolicy(IsolationPolicy.ACCEPT_ALL_UPDATES);
    LDAPReplicationDomain domain =
      MultimasterReplication.createNewDomain(conf, queue);
    domain.start();
    try
    {
      /*
       * Create a CSN generator to generate new CSNs
       * when we need to send operations messages to the replicationServer.
       */
      CSNGenerator gen = new CSNGenerator(201, 0);
      Entry parentEntry = TestCaseUtils.entryFromLdifString(
          "dn: ou=rpConflict, "+ TEST_ROOT_DN_STRING + "\n"
          + "objectClass: top\n"
          + "objectClass: organizationalUnit\n");
      Entry childEntry = TestCaseUtils.entryFromLdifString(
          "dn: cn=child, ou=rpConflict,"+ TEST_ROOT_DN_STRING + "\n"
          + "objectClass: top\n"
          + "objectClass: person\n"
          + "objectClass: organizationalPerson\n"
          + "objectClass: inetOrgPerson\n" + "uid: user.1\n"
          + "description: This is the description for Aaccf Amar.\n" + "st: NC\n"
          + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
          + "$Rockford, NC  85762\n" + "mail: user.1@example.com\n"
          + "cn: Aaccf Amar\n" + "l: Rockford\n"
          + "street: 17984 Thirteenth Street\n"
          + "employeeNumber: 1\n"
          + "sn: Amar\n" + "givenName: Aaccf\n" + "postalCode: 85762\n"
          + "userPassword: password\n" + "initials: AA\n");
    Entry parentEntry = createParentEntry();
    Entry childEntry = createChildEntry();
      TestCaseUtils.addEntry(parentEntry);
      String parentUUID = getEntryUUID(parentEntry.getName());
@@ -555,24 +326,53 @@
          new ArrayList<Attribute>());
      // Put the message in the replay queue
      domain.processUpdate(addMsg);
      // Make the domain replay the change from the replay queue
      domain.replay(queue.take().getUpdateMessage(), SHUTDOWN);
    replayMsg(addMsg);
      // Expect the parent entry to be deleted
      assertFalse(DirectoryServer.entryExists(parentEntry.getName()),
          "Parent entry exists ");
    assertFalse(entryExists(parentEntry.getName()), "Parent entry exists ");
      // Expect the child entry to be moved as conflict entry under the root
      // entry of the suffix
      DN childDN = DN.valueOf("entryuuid="+childUUID+
          "+cn=child,o=test");
      assertTrue(DirectoryServer.entryExists(childDN),
          "Child entry conflict exist with DN="+childDN);
    DN childDN = DN.valueOf("entryuuid=" + childUUID + "+cn=child,o=test");
    assertTrue(entryExists(childDN), "Child entry conflict exist with DN=" + childDN);
    }
    finally
  private Entry createParentEntry() throws Exception
    {
      MultimasterReplication.deleteDomain(baseDN);
    return TestCaseUtils.entryFromLdifString(
        "dn: ou=rpConflict, "+ TEST_ROOT_DN_STRING + "\n"
        + "objectClass: top\n"
        + "objectClass: organizationalUnit\n");
    }
  private Entry createChildEntry() throws Exception
  {
    return TestCaseUtils.entryFromLdifString(
        "dn: cn=child, ou=rpConflict,"+ TEST_ROOT_DN_STRING + "\n"
        + "objectClass: top\n"
        + "objectClass: person\n"
        + "objectClass: organizationalPerson\n"
        + "objectClass: inetOrgPerson\n"
        + "uid: user.1\n"
        + "description: This is the description for Aaccf Amar.\n"
        + "st: NC\n"
        + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
        + "$Rockford, NC  85762\n"
        + "mail: user.1@example.com\n"
        + "cn: Aaccf Amar\n"
        + "l: Rockford\n"
        + "street: 17984 Thirteenth Street\n"
        + "employeeNumber: 1\n"
        + "sn: Amar\n"
        + "givenName: Aaccf\n"
        + "postalCode: 85762\n"
        + "userPassword: password\n"
        + "initials: AA\n");
  }
  private void replayMsg(UpdateMsg updateMsg) throws InterruptedException
  {
    domain.processUpdate(updateMsg);
    domain.replay(queue.take().getUpdateMessage(), SHUTDOWN);
  }
}