String tn = "ECLIncludeAttributes";
debugInfo(tn, "Starting test\n\n");
Backend backend2 = null;
Backend backend3 = null;
DeleteOperationBasis delOp =null;
LDAPReplicationDomain domain2 = null;
LDAPReplicationDomain domain3 = null;
LDAPReplicationDomain domain21 = null;
DN baseDn2 = null;
DN baseDn3 = null;
try
{
// Initialize a second test backend o=test2, in addtion to o=test
// Configure replication on this backend
// Add the root entry in the backend
backend2 = initializeTestBackend(false,
TEST_ROOT_DN_STRING2, TEST_BACKEND_ID2);
baseDn2 = DN.decode(TEST_ROOT_DN_STRING2);
SortedSet<String> replServers = new TreeSet<String>();
replServers.add("localhost:"+replicationServerPort);
DomainFakeCfg domainConf =
new DomainFakeCfg(baseDn2, 1702, replServers);
// on o=test2,sid=1702 include attrs set to : 'sn'
SortedSet<AttributeType> eclInclude = new TreeSet<AttributeType>();
eclInclude.add(DirectoryServer.getAttributeType("sn"));
eclInclude.add(DirectoryServer.getAttributeType("roomnumber"));
ExternalChangelogDomainFakeCfg eclCfg =
new ExternalChangelogDomainFakeCfg(true, eclInclude);
domainConf.setExternalChangelogDomain(eclCfg);
// Set a Changetime heartbeat interval low enough (less than default
// value that is 1000 ms) for the test to be sure to consider all changes
// as eligible.
domainConf.setChangetimeHeartbeatInterval(10);
domain2 = MultimasterReplication.createNewDomain(domainConf);
domain2.start();
backend3 = initializeTestBackend(false,
TEST_ROOT_DN_STRING3, TEST_BACKEND_ID3);
baseDn3 = DN.decode(TEST_ROOT_DN_STRING3);
domainConf =
new DomainFakeCfg(baseDn3, 1703, replServers);
// on o=test3,sid=1703 include attrs set to : 'objectclass'
eclInclude = new TreeSet<AttributeType>();
eclInclude.add(DirectoryServer.getAttributeType("objectclass"));
eclCfg =
new ExternalChangelogDomainFakeCfg(true, eclInclude);
domainConf.setExternalChangelogDomain(eclCfg);
// Set a Changetime heartbeat interval low enough (less than default
// value that is 1000 ms) for the test to be sure to consider all changes
// as eligible.
domainConf.setChangetimeHeartbeatInterval(10);
domain3 = MultimasterReplication.createNewDomain(domainConf);
domain3.start();
// on o=test2,sid=1704 include attrs set to : 'cn'
domainConf =
new DomainFakeCfg(baseDn2, 1704, replServers);
eclInclude = new TreeSet<AttributeType>();
eclInclude.add(DirectoryServer.getAttributeType("cn"));
eclCfg =
new ExternalChangelogDomainFakeCfg(true, eclInclude);
domainConf.setExternalChangelogDomain(eclCfg);
// Set a Changetime heartbeat interval low enough (less than default
// value that is 1000 ms) for the test to be sure to consider all changes
// as eligible.
domainConf.setChangetimeHeartbeatInterval(10);
domain21 = MultimasterReplication.createNewDomain(domainConf);
domain21.start();
sleep(1000);
Entry e2 = createEntry(baseDn2);
addEntry(e2);
Entry e3 = createEntry(baseDn3);
addEntry(e3);
String lentry = new String(
"dn: cn=Fiona Jensen," + TEST_ROOT_DN_STRING2 + "\n"
+ "objectclass: top\n"
+ "objectclass: person\n"
+ "objectclass: organizationalPerson\n"
+ "objectclass: inetOrgPerson\n"
+ "cn: Fiona Jensen\n"
+ "sn: Jensen\n"
+ "uid: fiona\n"
+ "telephonenumber: 12121212");
Entry uentry1 = TestCaseUtils.entryFromLdifString(lentry);
addEntry(uentry1); // add fiona in o=test2
lentry = new String(
"dn: cn=Robert Hue," + TEST_ROOT_DN_STRING3 + "\n"
+ "objectclass: top\n"
+ "objectclass: person\n"
+ "objectclass: organizationalPerson\n"
+ "objectclass: inetOrgPerson\n"
+ "cn: Robert Hue\n"
+ "sn: Robby\n"
+ "uid: robert\n"
+ "telephonenumber: 131313");
Entry uentry2 = TestCaseUtils.entryFromLdifString(lentry);
addEntry(uentry2); // add robert in o=test3
// mod 'sn' of fiona (o=test2) with 'sn' configured as ecl-incl-att
AttributeBuilder builder = new AttributeBuilder("sn");
builder.add("newsn");
Modification mod =
new Modification(ModificationType.REPLACE, builder.toAttribute());
List<Modification> mods = new ArrayList<Modification>();
mods.add(mod);
ModifyOperationBasis modOpBasis =
new ModifyOperationBasis(connection, 1, 1, null, uentry1.getDN(), mods);
modOpBasis.run();
waitOpResult(modOpBasis, ResultCode.SUCCESS);
// mod 'telephonenumber' of robert (o=test3)
builder = new AttributeBuilder("telephonenumber");
builder.add("555555");
mod =
new Modification(ModificationType.REPLACE, builder.toAttribute());
mods = new ArrayList<Modification>();
mods.add(mod);
ModifyOperationBasis modOpBasis2 =
new ModifyOperationBasis(connection, 1, 1, null, uentry2.getDN(), mods);
modOpBasis2.run();
waitOpResult(modOpBasis2, ResultCode.SUCCESS);
// moddn robert (o=test3) to robert2 (o=test3)
ModifyDNOperationBasis modDNOp = new ModifyDNOperationBasis(connection,
InternalClientConnection.nextOperationID(),
InternalClientConnection.nextMessageID(),
null,
DN.decode("cn=Robert Hue," + TEST_ROOT_DN_STRING3),
RDN.decode("cn=Robert Hue2"), true,
DN.decode(TEST_ROOT_DN_STRING3));
modDNOp.run();
waitOpResult(modDNOp, ResultCode.SUCCESS);
// del robert (o=test3)
delOp = new DeleteOperationBasis(connection,
InternalClientConnection.nextOperationID(),
InternalClientConnection.nextMessageID(), null,
DN.decode("cn=Robert Hue2," + TEST_ROOT_DN_STRING3));
delOp.run();
waitOpResult(delOp, ResultCode.SUCCESS);
getEntry(DN.decode("cn=Robert Hue2," + TEST_ROOT_DN_STRING3),5000,false);
// Search on ECL from start on all suffixes
String cookie = "";
ExternalChangelogRequestControl control =
new ExternalChangelogRequestControl(true,
new MultiDomainServerState(cookie));
ArrayList<Control> controls = new ArrayList<Control>(0);
controls.add(control);
LinkedHashSet<String> attributes = new LinkedHashSet<String>();
attributes.add("+");
attributes.add("*");
sleep(1000);
debugInfo(tn, "Search with cookie=" + cookie);
InternalSearchOperation searchOp = connection.processSearch(
ByteString.valueOf("cn=changelog"),
SearchScope.WHOLE_SUBTREE,
DereferencePolicy.NEVER_DEREF_ALIASES,
0, // Size limit
0, // Time limit
false, // Types only
LDAPFilter.decode("(targetDN=*)"),
attributes,
controls,
null);
waitOpResult(searchOp, ResultCode.SUCCESS);
LinkedList<SearchResultEntry> entries = searchOp.getSearchEntries();
sleep(2000);
assertTrue(entries != null);
String s = tn + " entries returned= ";
if (entries != null)
{
for (SearchResultEntry resultEntry : entries)
{
// Expect
debugInfo(tn, "Entry returned =" + resultEntry.toLDIFString());
s += "Entry:" + resultEntry.toLDIFString();
String targetdn = getAttributeValue(resultEntry, "targetdn");
if ((targetdn.endsWith("cn=robert hue,o=test3"))
||(targetdn.endsWith("cn=robert hue2,o=test3")))
{
HashSet<String> eoc = new HashSet<String>();
eoc.add("person");eoc.add("inetOrgPerson");eoc.add("organizationalPerson");eoc.add("top");
checkValues(resultEntry,"targetobjectclass",eoc);
}
if (targetdn.endsWith("cn=fiona jensen,o=test2"))
{
checkValue(resultEntry,"targetsn","jensen");
checkValue(resultEntry,"targetcn","Fiona Jensen");
}
checkValue(resultEntry,"changeinitiatorsname", "cn=Internal Client,cn=Root DNs,cn=config");
}
}
assertEquals(entries.size(),8, "Entries number returned by search" + s);
}
catch(Exception e)
{
fail("Ending "+tn+" test with exception:\n"
+ stackTraceToSingleLineString(e));
}
finally
{
try
{
delOp = new DeleteOperationBasis(connection,
InternalClientConnection.nextOperationID(),
InternalClientConnection.nextMessageID(), null,
DN.decode("cn=Fiona Jensen," + TEST_ROOT_DN_STRING2));
delOp.run();
waitOpResult(delOp, ResultCode.SUCCESS);
delOp = new DeleteOperationBasis(connection,
InternalClientConnection.nextOperationID(),
InternalClientConnection.nextMessageID(), null,
DN.decode(TEST_ROOT_DN_STRING2));
delOp.run();
waitOpResult(delOp, ResultCode.SUCCESS);
delOp = new DeleteOperationBasis(connection,
InternalClientConnection.nextOperationID(),
InternalClientConnection.nextMessageID(), null,
DN.decode(TEST_ROOT_DN_STRING3));
delOp.run();
waitOpResult(delOp, ResultCode.SUCCESS);
// Cleaning
if (domain21 != null)
domain21.shutdown();
if (domain2 != null)
MultimasterReplication.deleteDomain(baseDn2);
removeTestBackend2(backend2);