*/
@SuppressWarnings("unchecked")
@Test(enabled=true, groups="slow")
public void addModDelDependencyTest() throws Exception
{
ReplicationServer replServer = null;
LDAPReplicationDomain domain = null;
DN baseDn = DN.decode(TEST_ROOT_DN_STRING);
int brokerId = 2;
int serverId = 1;
int replServerId = 81;
int AddSequenceLength = 30;
cleanDB();
try
{
/*
* FIRST PART :
* Check that a sequence of dependent ADD is correctly ordered.
*
* - Create replication server
* - Send sequence of ADD messages to the replication server
* - Configure replication server
* - check that the last entry has been correctly added
*/
String entryldif =
"dn:" + TEST_ROOT_DN_STRING + "\n"
+ "objectClass: top\n"
+ "objectClass: organization\n"
+ "entryuuid: " + stringUID(1) + "\n";
Entry entry = TestCaseUtils.entryFromLdifString(entryldif);
AttributeType uidType =
DirectoryServer.getSchema().getAttributeType("entryuuid");
// find a free port for the replicationServer
ServerSocket socket = TestCaseUtils.bindFreePort();
int replServerPort = socket.getLocalPort();
socket.close();
ReplServerFakeConfiguration conf =
new ReplServerFakeConfiguration(replServerPort, "dependencyTestAddModDelDependencyTestDb",
0, replServerId, 0,
AddSequenceLength*5+100, null);
replServer = new ReplicationServer(conf);
ReplicationBroker broker =
openReplicationSession(baseDn, brokerId, 1000, replServerPort, 1000,
false, CLEAN_DB_GENERATION_ID);
Thread.sleep(2000);
// send a sequence of add operation
String addDn = TEST_ROOT_DN_STRING;
ChangeNumberGenerator gen = new ChangeNumberGenerator(brokerId, 0L);
int sequence;
for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
{
entry.removeAttribute(uidType);
entry.addAttribute(Attributes.create("entryuuid", stringUID(sequence+1)),
new LinkedList<AttributeValue>());
addDn = "dc=dependency" + sequence + "," + addDn;
AddMsg addMsg =
new AddMsg(gen.newChangeNumber(), addDn, stringUID(sequence+1),
stringUID(sequence),
entry.getObjectClassAttribute(),
entry.getAttributes(), null );
broker.publish(addMsg);
ModifyMsg modifyMsg =
new ModifyMsg(gen.newChangeNumber(), DN.decode(addDn),
generatemods("description", "test"),
stringUID(sequence+1));
broker.publish(modifyMsg);
}
// configure and start replication of TEST_ROOT_DN_STRING on the server
SortedSet<String> replServers = new TreeSet<String>();
replServers.add("localhost:"+replServerPort);
DomainFakeCfg domainConf =
new DomainFakeCfg(baseDn, serverId, replServers);
domainConf.setHeartbeatInterval(100000);
domain = MultimasterReplication.createNewDomain(domainConf);
domain.start();
// check that last entry in sequence got added.
Entry lastEntry = getEntry(DN.decode(addDn), 30000, true);
assertNotNull(lastEntry,
"The last entry of the ADD sequence was not added.");
// Check that all the modify have been replayed
// (all the entries should have a description).
addDn = TEST_ROOT_DN_STRING;
for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
{
addDn = "dc=dependency" + sequence + "," + addDn;
boolean found =
checkEntryHasAttribute(DN.decode(addDn), "description", "test",
10000, true);
if (!found)
{
fail("The modification was not replayed on entry " + addDn);
}
}
/*
* SECOND PART
*
* Now check that the dependencies between delete are correctly
* managed.
*
* disable the domain while we publish the delete message to
* to replication server so that when we enable it it receives the
* delete operation in bulk.
*/
domain.disable();
Thread.sleep(2000); // necesary because disable does not wait
// for full termination of all threads. (issue 1571)
DN deleteDN = DN.decode(addDn);
while (sequence-->1)
{
DeleteMsg delMsg = new DeleteMsg(deleteDN.toString(),
gen.newChangeNumber(),
stringUID(sequence + 1));
broker.publish(delMsg);
deleteDN = deleteDN.getParent();
}
domain.enable();
// check that entry just below the base entry was deleted.
// (we can't delete the base entry because some other tests might
// have added other children)
DN node1 = DN.decode("dc=dependency1," + TEST_ROOT_DN_STRING);
Entry baseEntry = getEntry(node1, 30000, false);
assertNull(baseEntry,
"The last entry of the DEL sequence was not deleted.");
}
finally
{
if (replServer != null)
replServer.remove();
if (domain != null)
MultimasterReplication.deleteDomain(baseDn);
}
}