checkChangelogSize(1);
// Verify that DS3 receives this change
try
{
ReplicationMsg msg = broker3.receive();
debugInfo("Broker 3 received expected update msg" + msg);
}
catch(SocketTimeoutException e)
{
fail("Update message is supposed to be received.");
}
//===========================================================
debugInfo(testCase + " ** TEST ** Persistence of the generation ID in RS1");
long genIdBeforeShut =
replServer1.getGenerationId(baseDn.toNormalizedString());
debugInfo("Shutdown replServer1");
broker2.stop();
broker2 = null;
broker3.stop();
broker3 = null;
replServer1.remove();
replServer1 = null;
debugInfo("Create again replServer1");
replServer1 = createReplicationServer(changelog1ID, false, testCase);
// To search the replication server db later in these tests, we need
// to attach the search backend to the replication server just created.
b = (ReplicationBackend)DirectoryServer.getBackend("replicationChanges");
b.setServer(replServer1);
debugInfo("Delay to allow DS to reconnect to replServer1");
long genIdAfterRestart =
replServer1.getGenerationId(baseDn.toNormalizedString());
debugInfo("Aft restart / replServer.genId=" + genIdAfterRestart);
assertTrue(replServer1!=null, "Replication server creation failed.");
assertTrue(genIdBeforeShut == genIdAfterRestart,
"generationId is expected to have the same value" +
" after replServer1 restart. Before : " + genIdBeforeShut +
" after : " + genIdAfterRestart);
// By the way also verify that no change occurred on the replication server db
// and still contain the ADD submitted initially.
Thread.sleep(500);
checkChangelogSize(1);
//===============================================================
debugInfo(testCase + " ** TEST ** Import with new data set + reset will"+
" spread a new gen ID on the topology, verify DS1 and RS1");
try
{
debugInfo("Create again broker2");
broker2 = openReplicationSession(baseDn,
server2ID, 100, getChangelogPort(changelog1ID), 1000, emptyOldChanges, genId);
assertTrue(broker2.isConnected(), "Broker2 failed to connect to replication server");
debugInfo("Create again broker3");
broker3 = openReplicationSession(baseDn,
server3ID, 100, getChangelogPort(changelog1ID), 1000, emptyOldChanges, genId);
assertTrue(broker3.isConnected(), "Broker3 failed to connect to replication server");
}
catch(SocketException se)
{
fail("Broker connection is expected to be accepted.");
}
debugInfo("Launch on-line import on DS1");
long oldGenId = genId;
genId=-1;
disconnectFromReplServer(changelog1ID);
performLdifImport();
connectServer1ToChangelog(changelog1ID);
debugInfo("Create Reset task on DS1 to propagate the new gen ID as the reference");
Entry taskReset = TestCaseUtils.makeEntry(
"dn: ds-task-id=resetgenid"+genId+ UUID.randomUUID() +
",cn=Scheduled Tasks,cn=Tasks",
"objectclass: top",
"objectclass: ds-task",
"objectclass: ds-task-reset-generation-id",
"ds-task-class-name: org.nasutekds.server.tasks.SetGenerationIdTask",
"ds-task-reset-generation-id-domain-base-dn: " + baseDnStr);
addTask(taskReset, ResultCode.SUCCESS, null);
waitTaskState(taskReset, TaskState.COMPLETED_SUCCESSFULLY, null);
// Broker 2 and 3 should receive 1 change status message to order them
// to enter the bad gen id status
ChangeStatusMsg csMsg = (ChangeStatusMsg)waitForSpecificMsg(broker2,
ChangeStatusMsg.class.getName());
if (csMsg.getRequestedStatus() != ServerStatus.BAD_GEN_ID_STATUS)
{
fail("Broker 2 connection is expected to receive 1 ChangeStatusMsg" +
" to enter the bad gen id status"
+ csMsg);
}
csMsg = (ChangeStatusMsg)waitForSpecificMsg(broker3,
ChangeStatusMsg.class.getName());
if (csMsg.getRequestedStatus() != ServerStatus.BAD_GEN_ID_STATUS)
{
fail("Broker 2 connection is expected to receive 1 ChangeStatusMsg" +
" to enter the bad gen id status"
+ csMsg);
}
debugInfo("DS1 root entry must contain the new gen ID");
genId = readGenIdFromSuffixRootEntry();
assertTrue(genId != -1, "DS is expected to have a new genID computed " +
" after on-line import but genId=" + genId);
assertTrue(genId != oldGenId, "The new genID after import and reset of genID "
+ "is expected to be diffrent from previous one");
debugInfo("RS1 must have the new gen ID");
rgenId = replServer1.getGenerationId(baseDn.toNormalizedString());
assertEquals(genId, rgenId, "DS and replServer are expected to have same genId.");
debugInfo("RS1 must have been cleared since it has not the proper generation ID");
checkChangelogSize(0);
assertTrue(!replServer1.getReplicationServerDomain(
baseDn.toNormalizedString(), false).
isDegradedDueToGenerationId(server1ID),
"Expecting that DS1 status in RS1 is : not in bad gen id.");
//===============================================================
debugInfo(testCase + " ** TEST ** Previous test set a new gen ID on the "+
"topology, verify degradation of DS2 and DS3");
assertTrue(replServer1.getReplicationServerDomain(
baseDn.toNormalizedString(), false).
isDegradedDueToGenerationId(server2ID),
"Expecting that DS2 with old gen ID is in bad gen id from RS1");
assertTrue(replServer1.getReplicationServerDomain(
baseDn.toNormalizedString(), false).
isDegradedDueToGenerationId(server3ID),
"Expecting that DS3 with old gen ID is in bad gen id from RS1");
debugInfo("Add entries to DS1, update should not be sent to DS2 and DS3 that are in bad gen id");
String[] ent3 = { createEntry(UUID.randomUUID()) };
this.addTestEntriesToDB(ent3);
debugInfo("RS1 must have stored that update.");
Thread.sleep(500);
checkChangelogSize(1);
try
{
ReplicationMsg msg = broker2.receive();
fail("No update message is supposed to be received by broker2 in bad gen id. " + msg);
} catch(SocketTimeoutException e) { /* expected */ }
try
{
ReplicationMsg msg = broker3.receive();
fail("No update message is supposed to be received by broker3 in bad gen id. " + msg);
} catch(SocketTimeoutException e) { /* expected */ }
debugInfo("DS2 is publishing a change and RS1 must ignore this change, DS3 must not receive it.");
AddMsg emsg = (AddMsg)createAddMsg();
broker2.publish(emsg);
// Updates count in RS1 must stay unchanged = to 1
Thread.sleep(500);
checkChangelogSize(1);
try
{
ReplicationMsg msg = broker3.receive();
fail("No update message is supposed to be received by broker3 in bad gen id. "+ msg);
} catch(SocketTimeoutException e) { /* expected */ }
//===============================================================
debugInfo(testCase + " ** TEST ** Previous test put DS2 and DS3 in bad gen id, "+
" now simulates \"dsreplication initialize \"by doing a TU+reset " +
" from DS1 to DS2 and DS3, verify NON degradation of DS2 and DS3");
// In S1 launch the total update to initialize S2
addTask(taskInitRemoteS2, ResultCode.SUCCESS, null);
// S2 should be re-initialized and have a new valid genId
// Signal that we just entered the full update status
broker2.signalStatusChange(ServerStatus.FULL_UPDATE_STATUS);
int receivedEntriesNb = this.receiveImport(broker2, server2ID, null);
debugInfo("broker2 has been initialized from DS with #entries=" + receivedEntriesNb);
broker2.stop();
// Simulates the broker restart at the end of the import
broker2 = openReplicationSession(baseDn,
server2ID, 100, getChangelogPort(changelog1ID), 1000, emptyOldChanges, genId);
broker3.stop();
// Simulates the broker restart at the end of the import
broker3 = openReplicationSession(baseDn,
server3ID, 100, getChangelogPort(changelog1ID), 1000, emptyOldChanges, genId);
debugInfo("Adding reset task to DS1");
taskReset = TestCaseUtils.makeEntry(
"dn: ds-task-id=resetgenid"+ UUID.randomUUID() +
",cn=Scheduled Tasks,cn=Tasks",
"objectclass: top",
"objectclass: ds-task",
"objectclass: ds-task-reset-generation-id",
"ds-task-class-name: org.nasutekds.server.tasks.SetGenerationIdTask",
"ds-task-reset-generation-id-domain-base-dn: " + baseDnStr);
addTask(taskReset, ResultCode.SUCCESS, null);
waitTaskState(taskReset, TaskState.COMPLETED_SUCCESSFULLY, null);
debugInfo("Verify that RS1 has still the right genID");
assertEquals(replServer1.getGenerationId(baseDn.toNormalizedString()), rgenId);
// Updates count in RS1 must stay unchanged = to 1
Thread.sleep(500);
checkChangelogSize(1);
debugInfo("Verifying that DS2 is not in bad gen id any more");
assertTrue(!replServer1.getReplicationServerDomain(
baseDn.toNormalizedString(), false).
isDegradedDueToGenerationId(server2ID),
"Expecting that DS2 is not in bad gen id from RS1");
debugInfo("Verifying that DS3 is not in bad gen id any more");
assertTrue(!replServer1.getReplicationServerDomain(
baseDn.toNormalizedString(), false).
isDegradedDueToGenerationId(server3ID),
"Expecting that DS3 is not in bad gen id from RS1");
debugInfo("Verify that DS2 receives the add message stored in RS1 DB");
try
{
ReplicationMsg msg = broker2.receive();
assertTrue(msg instanceof AddMsg, "Excpected to receive an AddMsg but received: " + msg);
}
catch(SocketTimeoutException e)
{
fail("The msg stored in RS1 DB is expected to be received by DS2)");
}
debugInfo("Verify that DS3 receives the add message stored in RS1 DB");
try
{
ReplicationMsg msg = broker3.receive();
assertTrue(msg instanceof AddMsg, "Excpected to receive an AddMsg but received: " + msg);
}
catch(SocketTimeoutException e)
{
fail("The msg stored in RS1 DB is expected to be received by DS3)");
}
debugInfo("DS2 is publishing a change and RS1 must store this change, DS3 must receive it.");
emsg = (AddMsg)createAddMsg();
broker2.publish(emsg);
Thread.sleep(500);
checkChangelogSize(2);
try
{
ReplicationMsg msg = broker3.receive();
/* expected */
AddMsg rcvmsg = (AddMsg)msg;
assertEquals(rcvmsg.getChangeNumber(), emsg.getChangeNumber());
}