assertNotNull(ldapStatistics);
try
{
// Create broker on o=test
ReplicationBroker server01 = openReplicationSession(
DN.decode(TEST_ROOT_DN_STRING), 1201,
100, replicationServerPort,
brokerSessionTimeout, true);
server01.setChangeTimeHeartbeatInterval(100); //ms
int ts = 1;
// Create broker on o=test2
ReplicationBroker server02 = openReplicationSession(
DN.decode(TEST_ROOT_DN_STRING2), 1202,
100, replicationServerPort,
brokerSessionTimeout, true, EMPTY_DN_GENID);
server02.setChangeTimeHeartbeatInterval(100); //ms
// Produce update 1
ChangeNumber cn1 =
new ChangeNumber(TimeThread.getTime(), ts++, 1201);
DeleteMsg delMsg1 =
new DeleteMsg("uid=" + tn + "1," + TEST_ROOT_DN_STRING, cn1,
"11111111-1111-1111-1111-111111111111");
debugInfo(tn, " publishing " + delMsg1);
server01.publish(delMsg1);
this.sleep(500); // let's be sure the message is in the RS
// Produce update 2
ChangeNumber cn2 =
new ChangeNumber(TimeThread.getTime(), ts++, 1202);
DeleteMsg delMsg2 =
new DeleteMsg("uid=" + tn + "2," + TEST_ROOT_DN_STRING2, cn2,
"22222222-2222-2222-2222-222222222222");
debugInfo(tn, " publishing " + delMsg2);
server02.publish(delMsg2);
this.sleep(500); // let's be sure the message is in the RS
// Produce update 3
ChangeNumber cn3 =
new ChangeNumber(TimeThread.getTime(), ts++, 1202);
DeleteMsg delMsg3 =
new DeleteMsg("uid=" + tn + "3," + TEST_ROOT_DN_STRING2, cn3,
"33333333-3333-3333-3333-333333333333");
debugInfo(tn, " publishing " + delMsg3);
server02.publish(delMsg3);
this.sleep(500); // let's be sure the message is in the RS
// Creates cookie control
String cookie = "";
ArrayList<Control> controls = createControls(cookie);
if (compatMode)
{
cookie = null;
controls = new ArrayList<Control>(0);
}
// Creates psearch control
HashSet<PersistentSearchChangeType> changeTypes =
new HashSet<PersistentSearchChangeType>();
changeTypes.add(PersistentSearchChangeType.ADD);
changeTypes.add(PersistentSearchChangeType.DELETE);
changeTypes.add(PersistentSearchChangeType.MODIFY);
changeTypes.add(PersistentSearchChangeType.MODIFY_DN);
boolean returnECs = true;
PersistentSearchControl persSearchControl = new PersistentSearchControl(
changeTypes, changesOnly, returnECs);
controls.add(persSearchControl);
LinkedHashSet<String> attributes = new LinkedHashSet<String>();
attributes.add("+");
attributes.add("*");
// Creates request 1
SearchRequestProtocolOp searchRequest1 =
new SearchRequestProtocolOp(
ByteString.valueOf("cn=changelog"),
SearchScope.WHOLE_SUBTREE,
DereferencePolicy.NEVER_DEREF_ALIASES,
Integer.MAX_VALUE,
Integer.MAX_VALUE,
false,
LDAPFilter.decode("(targetDN=*"+tn+"*,o=test)"),
attributes);
// Creates request 2
SearchRequestProtocolOp searchRequest2 =
new SearchRequestProtocolOp(
ByteString.valueOf("cn=changelog"),
SearchScope.WHOLE_SUBTREE,
DereferencePolicy.NEVER_DEREF_ALIASES,
Integer.MAX_VALUE,
Integer.MAX_VALUE,
false,
LDAPFilter.decode("(targetDN=*"+tn+"*,o=test2)"),
attributes);
// Creates request 3
SearchRequestProtocolOp searchRequest3 =
new SearchRequestProtocolOp(
ByteString.valueOf("cn=changelog"),
SearchScope.WHOLE_SUBTREE,
DereferencePolicy.NEVER_DEREF_ALIASES,
Integer.MAX_VALUE,
Integer.MAX_VALUE,
false,
LDAPFilter.decode("objectclass=*"),
attributes);
// Connects and bind
s1 = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
org.nasutekds.server.tools.LDAPReader r1 = new org.nasutekds.server.tools.LDAPReader(s1);
LDAPWriter w1 = new LDAPWriter(s1);
s1.setSoTimeout(15000);
bindAsManager(w1, r1);
// Connects and bind
s2 = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
org.nasutekds.server.tools.LDAPReader r2 = new org.nasutekds.server.tools.LDAPReader(s2);
LDAPWriter w2 = new LDAPWriter(s2);
s2.setSoTimeout(30000);
bindAsManager(w2, r2);
// Connects and bind
s3 = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
org.nasutekds.server.tools.LDAPReader r3 = new org.nasutekds.server.tools.LDAPReader(s3);
LDAPWriter w3 = new LDAPWriter(s3);
s3.setSoTimeout(15000);
bindAsManager(w3, r3);
// Since we are going to be watching the post-response count, we need to
// wait for the server to become idle before kicking off the next request
// to ensure that any remaining post-response processing from the previous
// operation has completed.
assertTrue(DirectoryServer.getWorkQueue().waitUntilIdle(10000));
InvocationCounterPlugin.resetAllCounters();
long searchRequests = ldapStatistics.getSearchRequests();
long searchEntries = ldapStatistics.getSearchResultEntries();
long searchReferences = ldapStatistics.getSearchResultReferences();
long searchesDone = ldapStatistics.getSearchResultsDone();
LDAPMessage message;
message = new LDAPMessage(2, searchRequest1, controls);
w1.writeMessage(message);
this.sleep(500);
message = new LDAPMessage(2, searchRequest2, controls);
w2.writeMessage(message);
this.sleep(500);
message = new LDAPMessage(2, searchRequest3, controls);
w3.writeMessage(message);
this.sleep(500);
SearchResultEntryProtocolOp searchResultEntry = null;
SearchResultDoneProtocolOp searchResultDone = null;
if (changesOnly == false)
{
debugInfo(tn, "Search1 Persistent filter="+searchRequest1.getFilter().toString()
+ " expected to return change " + cn1);
searchEntries = 0;
message = null;
try
{
while ((searchEntries<1) && (message = r1.readMessage()) != null)
{
debugInfo(tn, "Search1 Result=" +
message.getProtocolOpType() + " " + message);
switch (message.getProtocolOpType())
{
case LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY:
searchResultEntry = message.getSearchResultEntryProtocolOp();
searchEntries++;
if (searchEntries==1)
{
checkValue(searchResultEntry.toSearchResultEntry(),"replicationcsn",cn1.toString());
checkValue(searchResultEntry.toSearchResultEntry(),"changenumber",
(compatMode?"10":"0"));
}
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_REFERENCE:
searchReferences++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE:
searchResultDone = message.getSearchResultDoneProtocolOp();
assertEquals(
searchResultDone.getResultCode(), ResultCode.SUCCESS,
searchResultDone.getErrorMessage().toString());
searchesDone++;
break;
}
}
}
catch(Exception e)
{
fail("Search1 failed with e=" + stackTraceToSingleLineString(e));
}
debugInfo(tn, "Search1 done with success. searchEntries="
+ searchEntries + " #searchesDone="+ searchesDone);
searchEntries = 0;
message = null;
try
{
debugInfo(tn, "Search 2 Persistent filter="+searchRequest2.getFilter().toString()
+ " expected to return change " + cn2 + " & " + cn3);
while ((searchEntries<2) && (message = r2.readMessage()) != null)
{
debugInfo(tn, "Search 2 Result=" +
message.getProtocolOpType() + message);
switch (message.getProtocolOpType())
{
case LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY:
searchResultEntry = message.getSearchResultEntryProtocolOp();
searchEntries++;
checkValue(searchResultEntry.toSearchResultEntry(),"changenumber",
(compatMode?"10":"0"));
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_REFERENCE:
searchReferences++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE:
searchResultDone = message.getSearchResultDoneProtocolOp();
assertEquals(
searchResultDone.getResultCode(), ResultCode.SUCCESS,
searchResultDone.getErrorMessage().toString());
searchesDone++;
break;
}
}
}
catch(Exception e)
{
fail("Search2 failed with e=" + stackTraceToSingleLineString(e));
}
debugInfo(tn, "Search2 done with success. searchEntries="
+ searchEntries + " #searchesDone="+ searchesDone);
searchEntries = 0;
message = null;
try
{
debugInfo(tn, "Search3 Persistent filter="+searchRequest3.getFilter().toString()
+ " expected to return change top + " + cn1 + " & " + cn2 + " & " + cn3);
while ((searchEntries<4) && (message = r3.readMessage()) != null)
{
debugInfo(tn, "Search3 Result=" +
message.getProtocolOpType() + " " + message);
switch (message.getProtocolOpType())
{
case LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY:
searchResultEntry = message.getSearchResultEntryProtocolOp();
searchEntries++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_REFERENCE:
searchReferences++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE:
searchResultDone = message.getSearchResultDoneProtocolOp();
assertEquals(
searchResultDone.getResultCode(), ResultCode.SUCCESS,
searchResultDone.getErrorMessage().toString());
searchesDone++;
break;
}
}
}
catch(Exception e)
{
fail("Search3 failed with e=" + stackTraceToSingleLineString(e));
}
debugInfo(tn, "Search3 done with success. searchEntries="
+ searchEntries + " #searchesDone="+ searchesDone);
}
// Produces additional change
ChangeNumber cn11 = new ChangeNumber(TimeThread.getTime(), 11, 1201);
String expectedDn11 = "uid=" + tn + "11," + TEST_ROOT_DN_STRING;
DeleteMsg delMsg11 = new DeleteMsg(expectedDn11, cn11,
"44444444-4444-4444-4444-444444444444");
debugInfo(tn, " publishing " + delMsg11);
server01.publish(delMsg11);
this.sleep(500);
debugInfo(tn, delMsg11.getChangeNumber() + " published additionally ");
// Produces additional change
ChangeNumber cn12 = new ChangeNumber(TimeThread.getTime(), 12, 1202);
String expectedDn12 = "uid=" + tn + "12," + TEST_ROOT_DN_STRING2;
DeleteMsg delMsg12 = new DeleteMsg(expectedDn12, cn12,
"55555555-5555-5555-5555-555555555555");
debugInfo(tn, " publishing " + delMsg12 );
server02.publish(delMsg12);
this.sleep(500);
debugInfo(tn, delMsg12.getChangeNumber() + " published additionally ");
// Produces additional change
ChangeNumber cn13 = new ChangeNumber(TimeThread.getTime(), 13, 1202);
String expectedDn13 = "uid=" + tn + "13," + TEST_ROOT_DN_STRING2;
DeleteMsg delMsg13 = new DeleteMsg(expectedDn13, cn13,
"66666666-6666-6666-6666-666666666666");
debugInfo(tn, " publishing " + delMsg13);
server02.publish(delMsg13);
this.sleep(500);
debugInfo(tn, delMsg13.getChangeNumber() + " published additionally ");
// wait 11
searchEntries = 0;
searchResultEntry = null;
searchResultDone = null;
message = null;
while ((searchEntries<1) && (message = r1.readMessage()) != null)
{
debugInfo(tn, "Search 11 Result=" +
message.getProtocolOpType() + " " + message);
switch (message.getProtocolOpType())
{
case LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY:
searchResultEntry = message.getSearchResultEntryProtocolOp();
searchEntries++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_REFERENCE:
searchReferences++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE:
searchResultDone = message.getSearchResultDoneProtocolOp();
assertEquals(
searchResultDone.getResultCode(), ResultCode.SUCCESS,
searchResultDone.getErrorMessage().toString());
// assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
searchesDone++;
break;
}
}
sleep(1000);
debugInfo(tn, "Search 1 successfully receives additional changes");
// wait 12 & 13
searchEntries = 0;
searchResultEntry = null;
searchResultDone = null;
message = null;
while ((searchEntries<2) && (message = r2.readMessage()) != null)
{
debugInfo(tn, "psearch search 12 Result=" +
message.getProtocolOpType() + " " + message);
switch (message.getProtocolOpType())
{
case LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY:
searchResultEntry = message.getSearchResultEntryProtocolOp();
searchEntries++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_REFERENCE:
searchReferences++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE:
searchResultDone = message.getSearchResultDoneProtocolOp();
assertEquals(
searchResultDone.getResultCode(), ResultCode.SUCCESS,
searchResultDone.getErrorMessage().toString());
// assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
searchesDone++;
break;
}
}
sleep(1000);
debugInfo(tn, "Search 2 successfully receives additional changes");
// wait 11 & 12 & 13
searchEntries = 0;
searchResultEntry = null;
searchResultDone = null;
message = null;
while ((searchEntries<3) && (message = r3.readMessage()) != null)
{
debugInfo(tn, "psearch search 13 Result=" +
message.getProtocolOpType() + " " + message);
switch (message.getProtocolOpType())
{
case LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY:
searchResultEntry = message.getSearchResultEntryProtocolOp();
searchEntries++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_REFERENCE:
searchReferences++;
break;
case LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE:
searchResultDone = message.getSearchResultDoneProtocolOp();
assertEquals(
searchResultDone.getResultCode(), ResultCode.SUCCESS,
searchResultDone.getErrorMessage().toString());
// assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
searchesDone++;
break;
}
}
sleep(1000);
// Check we received change 13
for (LDAPAttribute a : searchResultEntry.getAttributes())
{
if (a.getAttributeType().equalsIgnoreCase("targetDN"))
{
for (ByteString av : a.getValues())
{
assertTrue(av.toString().equalsIgnoreCase(expectedDn13),
"Entry returned by psearch 13 is " + av.toString() +
" when expected is " + expectedDn13);
}
}
}
debugInfo(tn, "Search 3 successfully receives additional changes");
server01.stop();
server02.stop();
try { s1.close(); } catch (Exception e) {};
try { s2.close(); } catch (Exception e) {};
try { s3.close(); } catch (Exception e) {};