PersistentSearchControl persSearchControl = new PersistentSearchControl(
changeTypes, changesOnly, returnECs);
controls.add(persSearchControl);
// Creates request
SearchRequestProtocolOp searchRequest =
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)"),
null);
// Connects and bind
debugInfo(tn, "Search with cookie=" + cookie + "\"");
s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
org.nasutekds.server.tools.LDAPReader r = new org.nasutekds.server.tools.LDAPReader(s);
LDAPWriter w = new LDAPWriter(s);
s.setSoTimeout(5000);
bindAsManager(w, r);
// 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();
debugInfo(tn, "Search Persistent filter=(targetDN=*"+tn+"*,o=test)");
LDAPMessage message;
message = new LDAPMessage(2, searchRequest, controls);
w.writeMessage(message);
this.sleep(500);
SearchResultEntryProtocolOp searchResultEntry = null;
SearchResultDoneProtocolOp searchResultDone = null;
if (changesOnly == false)
{
// Wait for change 1
debugInfo(tn, "Waiting for init search expected to return change 1");
searchEntries = 0;
message = null;
try
{
while ((searchEntries<1) && (message = r.readMessage()) != null)
{
debugInfo(tn, "Init search Result=" +
message.getProtocolOpType() + message + " " + searchEntries);
switch (message.getProtocolOpType())
{
case LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY:
searchResultEntry = message.getSearchResultEntryProtocolOp();
searchEntries++;
// FIXME:ECL Double check 1 is really the valid value here.
checkValue(searchResultEntry.toSearchResultEntry(),"changenumber",
(compatMode?"1":"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("init search failed with e=" + stackTraceToSingleLineString(e));
}
debugInfo(tn, "INIT search done with success. searchEntries="
+ searchEntries + " #searchesDone="+ searchesDone);
}
// Produces change 2
cn = new ChangeNumber(TimeThread.getTime(), ts++, 1201);
String expectedDn = "uid=" + tn + "2," + TEST_ROOT_DN_STRING;
delMsg = new DeleteMsg(expectedDn, cn,
"11111111-1112-1113-1114-111111111115");
debugInfo(tn, " publishing " + delMsg.getChangeNumber());
server01.publish(delMsg);
this.gblCN = cn;
this.sleep(1000);
debugInfo(tn, delMsg.getChangeNumber() +
" published , psearch will now wait for new entries");
// wait for the 1 new entry
searchEntries = 0;
searchResultEntry = null;
searchResultDone = null;
message = null;
while ((searchEntries<1) && (message = r.readMessage()) != null)
{
debugInfo(tn, "psearch search 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 2
for (LDAPAttribute a : searchResultEntry.getAttributes())
{
if (a.getAttributeType().equalsIgnoreCase("targetDN"))
{
for (ByteString av : a.getValues())
{
assertTrue(av.toString().equalsIgnoreCase(expectedDn),
"Entry returned by psearch is " + av.toString() +
" when expected is " + expectedDn);
}
}
}
debugInfo(tn, "Second search done successfully : " + searchResultEntry);
server01.stop();
try { s.close(); } catch (Exception e) {};
while (!s.isClosed()) sleep(100);
// TODO: Testing ACI is disabled because it is currently failing when
// ran in the precommit target while it works well when running alone.
// anonymous search returns entries from cn=changelog whereas it
// should not. Probably a previous test in the nightlytests suite is
// removing/modifying some ACIs...
// When problem found, we have to re-enable this test.
if (false)
{
// ACI step
debugInfo(tn, "Starting ACI step");
s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
r = new org.nasutekds.server.tools.LDAPReader(s);
w = new LDAPWriter(s);
s.setSoTimeout(5000);
bindAsWhoEver(w, r, "toto", "tutu", LDAPResultCode.OPERATIONS_ERROR);
searchRequest =
new SearchRequestProtocolOp(
ByteString.valueOf("cn=changelog"),
SearchScope.WHOLE_SUBTREE,
DereferencePolicy.NEVER_DEREF_ALIASES,
Integer.MAX_VALUE,
Integer.MAX_VALUE,