DependencyTest.java revision 28215a00c6a6c49ab982f51dee97d501ce954ad3
/*
* 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 2007-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* Test that the dependencies are computed correctly when replaying
* sequences of operations that requires to follow a given order
* such as : ADD an entry, ADD a children entry.
*/
@SuppressWarnings("javadoc")
public class DependencyTest extends ReplicationTestCase
{
private final long CLEAN_DB_GENERATION_ID = 7883L;
private DN TEST_ROOT_DN;
{
}
/**
* Check that a sequence of dependents adds and mods is correctly ordered:
* Using a deep dit :
* TEST_ROOT_DN_STRING
* |
* dc=dependency1
* |
* dc=dependency2
* |
* dc=dependency3
* |
*
* |
* dc=dependencyN
* This test sends a sequence of interleaved ADD operations and MODIFY
* operations to build such a dit.
*
* Then test that the sequence of Delete necessary to remove
* all those entries is also correctly ordered.
*/
public void addModDelDependencyTest() throws Exception
{
int brokerId = 2;
int serverId = 1;
int replServerId = 81;
int addSequenceLength = 30;
cleanDB();
try
{
/*
* FIRST PART :
* Check that a sequence of dependent ADD is correctly ordered.
*
* - Create replication server
* - Send sequence of ADD messages to the replication server
* - Configure replication server
* - check that the last entry has been correctly added
*/
+ "objectClass: top\n"
+ "objectClass: organization\n"
replServer = newReplicationServer(replServerId, addSequenceLength * 5 + 100, "dependencyTestAddModDelDependencyTestDb");
// send a sequence of add operation
int sequence;
{
new LinkedList<ByteString>());
}
// configure and start replication of TEST_ROOT_DN_STRING on the server
// check that last entry in sequence got added.
"The last entry of the ADD sequence was not added.");
// Check that all the modify have been replayed
// (all the entries should have a description).
{
}
/*
* SECOND PART
*
* Now check that the dependencies between delete are correctly
* managed.
*
* disable the domain while we publish the delete message to
* to replication server so that when we enable it it receives the
* delete operation in bulk.
*/
// for full termination of all threads. (issue 1571)
while (sequence-->1)
{
}
// check that entry just below the base entry was deleted.
// (we can't delete the base entry because some other tests might
// have added other children)
"The last entry of the DEL sequence was not deleted.");
}
finally
{
{
}
}
}
{
}
{
}
{
}
private ModifyDNMsg modDNMsg(DN dn, String newRDN, int entryUUID, int newSuperiorEntryUUID, CSNGenerator gen)
{
return new ModifyDNMsg(dn, gen.newCSN(), stringUID(entryUUID), stringUID(newSuperiorEntryUUID), true, null, newRDN);
}
/**
* Check the dependency between moddn and delete operation
* when an entry is renamed to a new dn and then deleted.
* Disabled: need investigations to fix random failures
*/
public void moddnDelDependencyTest() throws Exception
{
int brokerId = 2;
int serverId = 1;
int replServerId = 82;
cleanDB();
try
{
// Create replication server, replication domain and broker.
+ "objectClass: top\n"
+ "objectClass: organization\n");
int renamedEntryUuid = 100;
// configure and start replication of TEST_ROOT_DN_STRING on the server
// add an entry to play with.
new LinkedList<ByteString>());
// check that the entry was correctly added
checkEntryHasAttributeValue(addDN, "entryuuid", stringUID(renamedEntryUuid), 30, "The initial entry add failed");
// disable the domain to make sure that the messages are all sent in a row.
// rename and delete the entry.
// enable back the domain to trigger message replay.
// check that entry does not exist anymore.
checkEntryHasNoSuchAttributeValue(DN.valueOf("dc=new_name" + "," + TEST_ROOT_DN_STRING), "entryuuid",
}
finally
{
{
}
}
}
/**
* Clean the database and replace with a single entry.
*
* @throws FileNotFoundException
* @throws IOException
* @throws Exception
*/
{
// Clear backend
TestCaseUtils.initializeTestBackend(false);
// Create top entry with uuid
+ "objectClass: top\n"
+ "objectClass: organization\n"
+ "o: test\n"
}
/**
* the second entry is in the database.
* The unique id of the entry is used to check that the correct entry
* has been added.
*/
public void addDelAddDependencyTest() throws Exception
{
int brokerId = 2;
int serverId = 1;
int replServerId = 83;
int addSequenceLength = 30;
cleanDB();
try
{
+ "objectClass: top\n"
+ "objectClass: organization\n");
replServer = newReplicationServer(replServerId, 5 * addSequenceLength + 100, "dependencyTestAddDelAddDependencyTestDb");
int sequence;
{
// add the entry a first time
new LinkedList<ByteString>());
// add again the entry with a new entryuuid.
new LinkedList<ByteString>());
}
// check that all entries have been deleted and added
// again by checking that they do have the correct entryuuid
{
"The second add was not replayed on entry " + addDn);
}
{
}
// check that the database was cleaned successfully
"The entry were not removed succesfully after test completion.");
}
finally
{
{
}
}
}
private ReplicationServer newReplicationServer(int replServerId, int windowSize, String dirName) throws Exception
{
return new ReplicationServer(conf);
}
private LDAPReplicationDomain startNewLDAPReplicationDomain(ReplicationServer replServer, DN baseDN, int serverId,
int heartBeatInterval) throws ConfigException
{
if (heartBeatInterval > 0)
{
}
return domain;
}
/**
* Check that the dependency of moddn operation are working by
* issuing a set of Add operation followed by a modrdn of the added entry.
*/
public void addModdnDependencyTest() throws Exception
{
int brokerId = 2;
int serverId = 1;
int replServerId = 84;
int addSequenceLength = 30;
cleanDB();
try
{
+ "objectClass: top\n"
+ "objectClass: organization\n");
replServer = newReplicationServer(replServerId, 5 * addSequenceLength + 100, "dependencyTestAddModdnDependencyTestDb");
int sequence;
{
// add the entry
new LinkedList<ByteString>());
// rename the entry
}
// configure and start replication of TEST_ROOT_DN_STRING on the server
// check that all entries have been renamed
{
"The rename was not applied correctly on :" + addDN);
}
// delete the entries to clean the database.
{
}
}
finally
{
{
}
}
}
/**
* Builds and return a uuid from an integer.
* This methods assume that unique integers are used and does not make any
* unicity checks. It is only responsible for generating a uid with a
* correct syntax.
*/
{
}
}