throws Exception
{
final int serverId = 123;
final DN baseDn = DN.decode(TEST_ROOT_DN_STRING);
TestCaseUtils.initializeTestBackend(true);
ReplicationServer rs = createReplicationServer();
// Create Replication Server and Domain
LDAPReplicationDomain rd1 = createReplicationDomain(serverId);
try
{
long startTime = TimeThread.getTime();
final DN dn1 = DN.decode("cn=test1," + baseDn.toString());
final AttributeType histType =
DirectoryServer.getAttributeType(EntryHistorical.HISTORICALATTRIBUTENAME);
logError(Message.raw(Category.SYNC, Severity.INFORMATION,
"Starting replication test : changesCmpTest"));
// Add the first test entry.
TestCaseUtils.addEntry(
"dn: cn=test1," + baseDn.toString(),
"displayname: Test1",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"cn: test1",
"sn: test"
);
// Perform a first modification to update the historical attribute
int resultCode = TestCaseUtils.applyModifications(false,
"dn: cn=test1," + baseDn.toString(),
"changetype: modify",
"add: description",
"description: foo");
assertEquals(resultCode, 0);
// Read the entry back to get its historical and included changeNumber
Entry entry = DirectoryServer.getEntry(dn1);
List<Attribute> attrs1 = entry.getAttribute(histType);
assertTrue(attrs1 != null);
assertTrue(attrs1.isEmpty() != true);
String histValue =
attrs1.get(0).iterator().next().getValue().toString();
logError(Message.raw(Category.SYNC, Severity.INFORMATION,
"First historical value:" + histValue));
// Perform a 2nd modification to update the hist attribute with
// a second value
resultCode = TestCaseUtils.applyModifications(false,
"dn: cn=test1," + baseDn.toString(),
"changetype: modify",
"add: description",
"description: bar");
assertEquals(resultCode, 0);
Entry entry2 = DirectoryServer.getEntry(dn1);
List<Attribute> attrs2 = entry2.getAttribute(histType);
assertTrue(attrs2 != null);
assertTrue(attrs2.isEmpty() != true);
for (AttributeValue av : attrs2.get(0)) {
logError(Message.raw(Category.SYNC, Severity.INFORMATION,
"Second historical value:" + av.getValue().toString()));
}
LinkedList<ReplicationMsg> opList = new LinkedList<ReplicationMsg>();
TestBroker session = new TestBroker(opList);
boolean result =
rd1.buildAndPublishMissingChanges(
new ChangeNumber(startTime, 0, serverId),
session);
assertTrue(result, "buildAndPublishMissingChanges has failed");
assertEquals(opList.size(), 3, "buildAndPublishMissingChanges should return 3 operations");
assertTrue(opList.getFirst().getClass().equals(AddMsg.class));
// Build a change number from the first modification
String hv[] = histValue.split(":");
logError(Message.raw(Category.SYNC, Severity.INFORMATION, hv[1]));
ChangeNumber fromChangeNumber = new ChangeNumber(hv[1]);
opList = new LinkedList<ReplicationMsg>();
session = new TestBroker(opList);
result =
rd1.buildAndPublishMissingChanges(
fromChangeNumber,
session);
assertTrue(result, "buildAndPublishMissingChanges has failed");
assertEquals(opList.size(), 1, "buildAndPublishMissingChanges should return 1 operation");
assertTrue(opList.getFirst().getClass().equals(ModifyMsg.class));
}
finally
{
MultimasterReplication.deleteDomain(baseDn);
rs.remove();
}
}