HistoricalTest.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* Tests the Historical class.
*/
@SuppressWarnings("javadoc")
public class HistoricalTest extends ReplicationTestCase
{
private int replServerPort;
/**
* Set up replication on the test backend.
*/
{
super.setUp();
// Create an internal connection.
// The replication server.
+ "objectClass: top\n"
+ "objectClass: ds-cfg-replication-server\n"
+ "cn: replication Server\n"
+ "ds-cfg-replication-db-directory: HistoricalTest\n"
+ "ds-cfg-replication-server-id: 102\n";
// The suffix to be synchronized.
+ "objectClass: top\n"
+ "objectClass: ds-cfg-replication-domain\n"
+ "ds-cfg-server-id: 1\n"
+ "ds-cfg-receive-status: true\n";
}
/**
* Tests that the attribute modification history is correctly read from
* and written to an operational attribute of the entry.
* Also test that historical is purged according to the purge delay that
* is provided.
*/
public void testEncodingAndPurge() throws Exception
{
// Add a test entry.
"dn: uid=user.1," + TEST_ROOT_DN_STRING,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: user.1",
"cn: Aaccf Amar",
"sn: Amar",
"givenName: Aaccf",
"userPassword: password",
"description: Initial description",
"displayName: 1"
);
// Modify the test entry to give it some history.
// Test both single and multi-valued attributes.
"dn: uid=user.1," + TEST_ROOT_DN_STRING,
"changetype: modify",
"add: cn;lang-en",
"cn;lang-en: Aaccf Amar",
"cn;lang-en: Aaccf A Amar",
"-",
"replace: description",
"description: replaced description",
"-",
"add: displayName",
"displayName: 2",
"-",
"delete: displayName",
"displayName: 1",
"-"
);
{
"-h", "127.0.0.1",
"-D", "cn=Directory Manager",
"-w", "password",
"-f", path
};
"dn: uid=user.1," + TEST_ROOT_DN_STRING,
"changetype: modify",
"replace: displayName",
"displayName: 2",
"-"
);
// Read the entry back to get its history operational attribute.
// Check that encoding and decoding preserves the history information.
"dn: uid=user.1," + TEST_ROOT_DN_STRING,
"changetype: modify",
"replace: displayName",
"displayName: 3",
"-"
);
// Read the entry back to get its history operational attribute.
// The purge time is not done so the hist attribute should be not empty
// Now wait for the purge time to be done
// Read the entry back to get its history operational attribute.
// The hist attribute should now be empty since purged
}
/**
* The scenario for this test case is that two modify operations occur at
* two different servers at nearly the same time, each operation adding a
* different value for a single-valued attribute. Replication then
* replays the operations and we expect the conflict to be resolved on both
* servers by keeping whichever value was actually added first.
* For the unit test, we employ a single directory server. We use the
* broker API to simulate the ordering that would happen on the first server
* on one entry, and the reverse ordering that would happen on the
* second server on a different entry. Confused yet?
*/
public void conflictSingleValue() throws Exception
{
final AttributeType attrType =
final AttributeType entryuuidType =
/*
* Open a session to the replicationServer using the broker API.
* This must use a different serverId to that of the directory server.
*/
// Clear the backend and create top entrye
// Add the first test entry.
"dn: cn=test1," + TEST_ROOT_DN_STRING,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"cn: test1",
"sn: test"
);
// Read the entry back to get its UUID.
// Add the second test entry.
"dn: cn=test2," + TEST_ROOT_DN_STRING,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"cn: test2",
"sn: test",
"description: Description"
);
// Read the entry back to get its UUID.
// A change on a first server.
// A change on a second server.
// Simulate the ordering t1:add:A followed by t2:add:B that would
// happen on one server.
// Replay an add of a value A at time t1 on a first server.
// It would be nice to avoid these sleeps.
// We need to preserve the replay order but the order could be changed
// due to the multi-threaded nature of the replication replay.
// Putting a sentinel value in the modification is not foolproof since
// the operation might not get replayed at all.
// Replay an add of a value B at time t2 on a second server.
// Simulate the reverse ordering t2:add:B followed by t1:add:A that
// would happen on the other server.
// Replay an add of a value A at time t1 on a first server.
// See how the conflicts were resolved.
// The two values should be the first value added.
}
throws Exception
{
}
{
}
/**
* Test that historical information is correctly added when performing ADD,
* MOD and MODDN operations.
*/
@Test
public void historicalAdd() throws Exception
{
// Clear the backend.
// Add the first test entry.
"dn: " + dn1,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"cn: test1",
"sn: test"
);
// Read the entry that was just added.
// Check that we can build an Add operation from this entry.
// This will ensure both that the Add historical information is
// correctly added and also that the code that rebuild operation
// from this historical information is working.
// Perform a few check on the Operation to see that it
// was correctly generated.
// Now apply a modifications to the entry and check that the
// ADD historical information has been preserved.
TestCaseUtils.applyModifications(false,
"dn: " + dn1,
"changetype: modify",
"add: description",
"description: foo");
// Read the modified entry.
// use historical information to generate new list of operations
// equivalent to the operations that have been applied to this entry.
// Perform a few check on the operation list to see that it
// was correctly generated.
// rename the entry.
TestCaseUtils.applyModifications(false,
"dn: " + dn1,
"changetype: moddn",
"newrdn: cn=test2",
"deleteoldrdn: 1");
// Read the modified entry.
// use historical information to generate new list of operations
// equivalent to the operations that have been applied to this entry.
// Perform a few check on the operation list to see that it
// was correctly generated.
// Now clear the backend and try to run the generated operations
// to check that applying them do lead to an equivalent result.
{
op.setInternalOperation(true);
op.setSynchronizationOperation(true);
}
}
/**
* Performs a few check on the provided ADD operations, particularly
* that a ADDmsg can be created from it with valid values for fields
* DN, entryuid, ...)
*/
{
int count = 0;
{
count++;
if (op instanceof FakeAddOperation)
{
// perform a few check on the Operation to see that it
// was correctly generated :
// - the dn should be dn1,
// - the entry id and the parent id should match the ids from the entry
}
else
{
// The first operation should be an ADD operation.
"FakeAddOperation was not correctly generated from historical information");
}
}
}
/**
* Test the task that purges the replication historical stored in the user
* entry.
* Steps :
* - creates entry containing historical
* - wait for the purge delay
* - launch the purge task
* - verify that all historical has been purged
*
* TODO: another test should be written that configures the task no NOT have
* the time to purge everything in 1 run .. and thus to relaunch it to finish
* the purge. And verify that the second run starts on the CSN where
* the previous task run had stopped.
*/
public void testRecurringPurgeIn1Run() throws Exception
{
int entryCount = 10;
// and configuring the purge delay.
// set the purge delay to 1 minute
// FIXME could we change this setting to also accept seconds?
// This way this test would not take one minute to run
// (and it could also fail less often in jenkins).
"set-replication-domain-prop",
"--provider-name","Multimaster Synchronization",
"--domain-name", testName,
"--set","conflicts-historical-purge-delay:1m");
// Let's go past the purge delay
// launch the purge
final int maxWaitTimeInSeconds = 120;
"objectclass: top",
"objectclass: ds-task",
"objectclass: ds-task-purge-conflicts-historical",
"ds-task-class-name: org.opends.server.tasks.PurgeConflictsHistoricalTask",
"ds-task-purge-conflicts-historical-domain-dn: " + TEST_ROOT_DN_STRING,
"ds-task-purge-conflicts-historical-maximum-duration: " + maxWaitTimeInSeconds);
// every entry should be purged from its hist
int expectedNumberOfEntries = 0;
waitForSearchResult(TEST_ROOT_DN_STRING, WHOLE_SUBTREE, "(ds-sync-hist=*)", SUCCESS, expectedNumberOfEntries);
}
/**
* Add a provided number of generated entries containing historical.
* @param dnSuffix A suffix to be added to the dn
* @param entryCnt The number of entries to create
*/
{
for (int i=0; i<entryCnt;i++)
{
// Add a test entry.
sdn,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: user"+i,
"cn: Aaccf Amar",
"sn: Amar",
"givenName: Aaccf",
"userPassword: password",
"description: Initial description",
"displayName: 1"
);
// Modify the test entry to give it some history.
// Test both single and multi-valued attributes.
sdn,
"changetype: modify",
"add: cn;lang-en",
"cn;lang-en: Aaccf Amar",
"cn;lang-en: Aaccf A Amar",
"-",
"replace: givenName",
"givenName: new given",
"-",
"replace: userPassword",
"userPassword: new pass",
"-",
"replace: description",
"description: replaced description",
"-",
"replace: sn",
"sn: replaced sn",
"-",
"add: displayName",
"displayName: 2",
"-",
"delete: displayName",
"displayName: 1",
"-"
);
{
"-h", "127.0.0.1",
"-D", "cn=Directory Manager",
"-w", "password",
"-f", path
};
sdn,
"changetype: modify",
"replace: displayName",
"displayName: 2",
"-"
);
}
}
}