@Test()
public void testMaxPSearch() throws Exception
{
TestCaseUtils.initializeTestBackend(true);
//Modify the configuration to allow only 1 concurrent persistent search.
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
ArrayList<ByteString> values = new ArrayList<ByteString>();
values.add(ByteString.valueOf("1"));
LDAPAttribute attr = new LDAPAttribute("ds-cfg-max-psearches", values);
ArrayList<RawModification> mods = new ArrayList<RawModification>();
mods.add(new LDAPModification(ModificationType.REPLACE, attr));
ModifyOperation modifyOperation =
conn.processModify(ByteString.valueOf("cn=config"), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
//Create a persistent search request.
LinkedHashSet<String> attributes = new LinkedHashSet<String>();
attributes.add("cn");
List<Control> controls = new LinkedList<Control>();
// 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);
PersistentSearchControl persSearchControl = new PersistentSearchControl(
changeTypes, true, true);
controls.add(persSearchControl);
final InternalSearchOperation search =
conn.processSearch("o=test", SearchScope.BASE_OBJECT,
DereferencePolicy.NEVER_DEREF_ALIASES, 0, // Size limit
0, // Time limit
true, // Types only
"(objectClass=*)", attributes, controls, null);