ReplicationTestCase.java revision c1c0b08b5ce89eacff706ff6785d88f5640e96be
/*
* 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
* 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
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. 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 2006-2009 Sun Microsystems, Inc.
*/
/**
* An abstract class that all Replication unit test should extend.
*/
public abstract class ReplicationTestCase extends DirectoryServerTestCase
{
// The tracer object for the debug logger
// This is the generation id matching the memory test backend
// with its initial root entry o=test created.
// This matches the backend obtained calling:
// TestCaseUtils.initializeTestBackend(true).
// (using the default TestCaseUtils.TEST_ROOT_DN_STRING suffix)
protected static final long TEST_DN_WITH_ROOT_ENTRY_GENID = 5095L;
/**
* Generation id for a fully empty domain.
*/
public static final long EMPTY_DN_GENID = 48L;
/**
* The internal connection used for operation
*/
protected InternalClientConnection connection;
/**
* Created entries that need to be deleted for cleanup
*/
protected Entry synchroServerEntry;
protected Entry replServerEntry;
/**
* Replication monitor stats
*/
private String monitorAttr;
private long lastCount;
/**
* schema check flag
*/
protected boolean schemaCheck;
// Call the paranoiaCheck at test cleanup or not.
// Must not been touched except if sub class has its own clean up code,
// for instance:
// @AfterClass
// public void classCleanUp() throws Exception
// {
// callParanoiaCheck = false;
// super.classCleanUp();
//
// // Clear my own stuff that I have setup (in my own setup() method for instance)
// myReplServerInstantiatedWithConstructor.remove(); // This removes the replication changes backend
//
// // Now call paramoiaCheck myself
// paranoiaCheck();
// }
protected boolean callParanoiaCheck = true;
/**
* The replication plugin entry
*/
protected final String SYNCHRO_PLUGIN_DN =
"cn=Multimaster Synchronization, cn=Synchronization Providers,cn=config";
/**
* Set up the environment for performing the tests in this suite.
*
* @throws Exception
* If the environment could not be set up.
*/
{
// This test suite depends on having the schema available.
// Initialize the test backend (TestCaseUtils.TEST_ROOT_DN_STRING)
// (in case previous (non replication?) tests were run before...)
// Create an internal connection
callParanoiaCheck = true;
}
/**
* Retrieves the domain associated to the baseDn, and the value of the generationId
* of this domain. If the domain does not exist, returns the default hard-coded\
* value of the generationId corresponding to 'no entry'.
*
* @param baseDn The baseDn for which we want the generationId
* @return The value of the generationId.
*/
{
// This is the value of the generationId computed by the server when the
// test suffix (o=test) has only the root entry created.
long genId = TEST_DN_WITH_ROOT_ENTRY_GENID;
try
{
}
catch(Exception e) {}
return genId;
}
/**
* Open a replicationServer session to the local ReplicationServer.
* The generation is read from the replicationDomain object. If it
* does not exist, take the 'empty backend' generationID.
*/
protected ReplicationBroker openReplicationSession(
throws Exception, SocketException
{
}
/**
* Open a replicationServer session to the local ReplicationServer
* providing the generationId.
*/
protected ReplicationBroker openReplicationSession(
long generationId)
throws Exception, SocketException
{
if (emptyOldChanges)
if (timeout != 0)
// to the replicationServer.
if (emptyOldChanges)
{
/*
* loop receiving update until there is nothing left
* to make sure that message from previous tests have been consumed.
*/
try
{
while (true)
{
{
logError(new MessageBuilder(
" received ErrorMessage when emptying old changes ").append(
}
}
}
catch (Exception e)
{
logError(new MessageBuilder(
}
}
return broker;
}
/**
* Open an ECL replicationServer session to the local ReplicationServer
protected ReplicationBroker openECLReplicationSession(
int window_size, int port, int timeout, boolean emptyOldChanges,
Short serverId)
throws Exception, SocketException
{
ServerState state = new ServerState();
//if (emptyOldChanges)
// new PersistentServerState(baseDn, serverId, new ServerState());
ReplicationBroker broker = new ReplicationBroker(null,
state, "cn=changelog", serverId, window_size,
-1, 100000, getReplSessionSecurity(), (byte)1);
ArrayList<String> servers = new ArrayList<String>(1);
servers.add("localhost:" + port);
broker.start(servers);
if (timeout != 0)
broker.setSoTimeout(timeout);
checkConnection(30, broker, port); // give some time to the broker to connect
// to the replicationServer.
if (emptyOldChanges)
{
// loop receiving update until there is nothing left
// to make sure that message from previous tests have been consumed.
try
{
while (true)
{
ReplicationMsg rMsg = broker.receive();
if (rMsg instanceof ErrorMsg)
{
ErrorMsg eMsg = (ErrorMsg)rMsg;
logError(new MessageBuilder(
"ReplicationTestCase/openReplicationSession ").append(
" received ErrorMessage when emptying old changes ").append(
eMsg.getDetails()).toMessage());
}
}
}
catch (Exception e)
{
logError(new MessageBuilder(
"ReplicationTestCase/openReplicationSession ").append(e.getMessage())
.append(" when emptying old changes").toMessage());
}
}
return broker;
}
*/
/**
* Check connection of the provided ds to the
* replication server. Waits for connection to be ok up to secTimeout seconds
* before failing.
*/
{
int nSec = 0;
// Go out of the loop only if connection is verified or if timeout occurs
while (true)
{
// Test connection
if (connected)
{
// Connection verified
return;
}
// Sleep 1 second
try
{
} catch (InterruptedException ex)
{
}
nSec++;
if (nSec > secTimeout)
{
// Timeout reached, end with error
}
}
}
/**
* Open a replicationServer session to the local ReplicationServer
* with a default value generationId.
*
*/
protected ReplicationBroker openReplicationSession(
throws Exception, SocketException
{
}
/**
* Open a new session to the ReplicationServer
* starting with a given ServerState.
*/
protected ReplicationBroker openReplicationSession(
throws Exception, SocketException
{
if (timeout != 0)
return broker;
}
/**
* Open a replicationServer session with flow control to the local
* ReplicationServer.
*
*/
protected ReplicationBroker openReplicationSession(
boolean emptyOldChanges)
throws Exception, SocketException
{
}
protected ReplicationBroker openReplicationSession(
boolean emptyOldChanges, long generationId)
throws Exception, SocketException
{
if (emptyOldChanges)
if (timeout != 0)
if (emptyOldChanges)
{
/*
* loop receiving update until there is nothing left
* to make sure that message from previous tests have been consumed.
*/
try
{
while (true)
{
{
logError(new MessageBuilder(
" received ErrorMessage when emptying old changes ").append(
}
}
}
catch (Exception e)
{ }
}
return broker;
}
/**
* suppress all the config entries created by the tests in this class
*/
protected void cleanConfigEntries()
{
"ReplicationTestCase/Cleaning config entries"));
// Delete entries
try
{
while (true)
{
"cleaning config entry " + dn));
dn);
{
}
}
}
catch (NoSuchElementException e) {
// done
}
}
/**
* suppress all the real entries created by the tests in this class
*/
protected void cleanRealEntries()
{
"ReplicationTestCase/Cleaning entries"));
// Delete entries
try
{
while (true)
{
null,
dn);
{
"ReplicationTestCase/Cleaning entries" +
"DEL " + dn +
}
}
}
catch (NoSuchElementException e) {
// done
}
}
/**
* Clean up the environment. return null;
*
* @throws Exception If the environment could not be set up.
*/
public void classCleanUp() throws Exception
{
" ##### Calling ReplicationTestCase.classCleanUp ##### "));
// Clear the test backend (TestCaseUtils.TEST_ROOT_DN_STRING)
// (in case our test created some emtries in it)
// Clean the default DB dir for replication server
{
{
{
}
}
}
if (callParanoiaCheck)
}
/**
* After having run, each replication test should not leave any of the following:
* - config entry for replication server
* - config entry for a replication domain
* - replication domain object
* - config entry for a replication changes backend
* - replication changes backend object
* This method checks for existence of anything of that type.
*/
protected void paranoiaCheck()
{
"Performing paranoia check"));
// Check for config entries for replication server
assertNoConfigEntriesWithFilter("(objectclass=ds-cfg-replication-server)",
"Found unexpected replication server config left");
// Check for config entries for replication domain
assertNoConfigEntriesWithFilter("(objectclass=ds-cfg-replication-domain)",
"Found unexpected replication domain config left");
// Check for config entries for replication changes backend
"(ds-cfg-java-class=org.opends.server.replication.server.ReplicationBackend)",
"Found unexpected replication changes backend config left");
// Check for left domain object
assertEquals(MultimasterReplication.getNumberOfDomains(), 0, "Some replication domain objects left");
// Check for left replication changes backend object
assertEquals(DirectoryServer.getBackend("replicationChanges"), null, "Replication changes backend object has been left");
}
/**
* Performs a search on the config backend with the specified filter.
* Fails if a config entry is found.
* @param filter The filter to apply for the search
* @param errorMsg The error message to display if a config entry is found
*/
{
try
{
// Search for matching entries in config backend
// Check that no entries have been found
{
}
} catch (Exception e)
{
fail("assertNoConfigEntriesWithFilter: could not search config backend" +
}
}
/**
* Configure the replication for this test.
*/
protected void configureReplication() throws Exception
{
if (replServerEntry != null)
{
// Add the replication server
"Unable to add the replication server");
}
if (synchroServerEntry != null)
{
// We also have a replicated suffix (replication domain)
"Unable to add the synchronized server");
}
}
/**
* Get the value of the specified attribute for a given replication
* domain from the monitor entry.
* @return The monitor value
* @throws Exception If an error occurs.
*/
{
int count = 0;
do
{
if (count++>0)
}
throw new Exception("Could not read monitoring information");
}
/**
* Check that the entry with the given dn has the given valueString value
* for the given attrTypeStr attribute type.
*/
{
boolean found = false;
if (count<1)
count=1;
do
{
for (int j=0; j < 3; j++)
{
{
break;
}
}
{
}
try
{
{
{
}
}
}
finally
{
}
if (found != hasAttribute)
return found;
}
/**
* Retrieves an entry from the local Directory Server.
* @throws Exception When the entry cannot be locked.
*/
{
if (count<1)
count=1;
{
count--;
}
for (int i=0; i < 3; i++)
{
{
break;
}
}
{
}
try
{
return null;
else
}
finally
{
}
}
/**
* Update the monitor count for the specified monitor attribute.
*/
monitorAttr = attr;
try
{
}
{
assertTrue(false);
}
}
/**
* Get the delta between the current / last monitor counts.
* @return The delta between the current and last monitor count.
*/
protected long getMonitorDelta() {
long delta = 0;
try {
assertTrue(false);
}
return delta;
}
/**
* Generate a new modification replace with the given information.
*
* @param attrName The attribute to replace.
* @param attrValue The new value for the attribute
*
* @return The modification replace.
*/
{
return mods;
}
/**
* Utility method to create, run a task and check its result.
*/
{
// Add the task.
"Add of the task definition was not successful");
// Wait until the task completes.
do
{
filter);
try
{
} catch (Exception e)
{
continue;
}
if (completionTime == null)
{
{
break;
}
}
} while (completionTime == null);
if (completionTime == null)
{
fail("The task has not completed after 30 seconds.");
}
// Check that the task state is as expected.
"The task completed in an unexpected state");
}
/**
* Create a new replication session security object that can be used in
* unit tests.
*
* @return A new replication session security object.
* @throws ConfigException If an error occurs.
*/
protected static ReplSessionSecurity getReplSessionSecurity()
throws ConfigException
{
}
/**
* Add a task to the configuration of the current running DS.
* @param taskEntry The task to add.
* @param expectedResult The expected result code for the ADD.
* @param errorMessageID The expected error messageID when the expected
* result code is not SUCCESS
*/
{
try
{
// Change config of DS to launch the total update task
// Add the task.
"Result of ADD operation of the task is: "
+ " Expected:"
{
"Error MsgID of the task <"
+ "> equals <"
+ errorMessage + ">");
}
else
{
}
// Entry will be removed at the end of the test
}
catch(Exception e)
{
}
}
{
int cpt=40;
try
{
do
{
filter);
try
{
} catch (Exception e)
{
fail("Task entry was not returned from the search.");
continue;
}
try
{
// Check that the task state is as expected.
}
catch(Exception e)
{
}
cpt--;
}
while ((taskState != expectedTaskState) &&
(cpt > 0));
// Check that the task contains some log messages.
{
{
fail("No log messages were written to the task entry on a failed task");
}
}
{
if (expectedMessage != null)
{
}
}
{
// We usually wait the running state after adding the task
// and if the task is fast enough then it may be already done
// and we can go on.
}
else
{
" Expected task state:" + expectedTaskState);
}
}
catch(Exception e)
{
}
}
/**
* Add to the current DB the entries necessary to the test
*/
{
try
{
// Change config of DS to launch the total update task
{
null,
addOp.setInternalOperation(true);
{
}
else
{
}
}
}
catch(Exception e)
{
}
}
/**
* Get the entryUUID for a given DN.
*
* @throws Exception if the entry does not exist or does not have
* an entryUUID.
*/
{
int count = 10;
if (count<1)
count=1;
{
for (int i=0; i < 3; i++)
{
{
break;
}
}
{
}
try
{
{
{
break;
}
}
}
finally
{
}
count --;
}
return found;
}
/**
* Utility method : removes a domain deleting the passed config entry
*/
{
// Delete entries
try
{
"cleaning config entry " + dn));
dn);
{
}
} catch (NoSuchElementException e)
{
// done
}
}
}