ReplicationServerFailoverTest.java revision 8d21db36015f8560d9cd2bcee9817f2c0a07a386
/*
* 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 2006-2009 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* Test if the replication domain is able to switch of replication server
* if there is some replication server failure.
*/
@Test(sequential = true)
public class ReplicationServerFailoverTest extends ReplicationTestCase
{
private static final int DS1_ID = 1;
private static final int DS2_ID = 2;
private static final int RS1_ID = 31;
private static final int RS2_ID = 32;
private int rs1Port = -1;
private int rs2Port = -1;
private LDAPReplicationDomain rd1;
private LDAPReplicationDomain rd2;
private ReplicationServer rs1;
private ReplicationServer rs2;
/** The tracer object for the debug logger. */
{
if (logger.isTraceEnabled())
{
}
}
private void initTest() throws IOException
{
}
{
{
}
{
}
// Clear any reference to a domain in synchro plugin
}
/**
* Test the failover feature when one RS fails:
* 1 DS (DS1) and 2 RS (RS1 and RS2) in topology.
* DS1 connected to one RS
* Both RS are connected together (RS1<->RS2)
* The RS connected to DS1 fails, DS1 should be connected
* to the other RS
*
* @throws Exception If a problem occurred
*/
@Test
public void testFailOverSingle() throws Exception
{
int rsPort = -1;
initTest();
try
{
// Start RS1
// Start RS2
// Start DS1
// Wait a bit so that connections are performed
// DS1 connected to RS1 ?
// Check which replication server is connected to this LDAP server
{
// Simulate RS1 failure
// Let time for failover to happen
// DS1 connected to RS2 ?
}
{ // Simulate RS2 failure
// DS1 connected to RS1 ?
}
else {
fail("DS1 is not connected to a RS");
}
} finally
{
endTest();
}
}
/**
* Test the failover feature when one RS fails:
* 2 DS (DS1 and DS2) and 2 RS (RS1 and RS2) in topology.
* Each DS connected to its own RS (DS1<->RS1, DS2<->RS2)
* Both RS are connected together (RS1<->RS2)
* RS1 fails, DS1 and DS2 should be both connected to RS2
* RS1 comes back (no change)
* RS2 fails, DS1 and DS2 should be both connected to RS1
*
* @throws Exception If a problem occurred
*/
public void testFailOverMulti() throws Exception
{
initTest();
try
{
// Start RS1
// Start RS2
// Start DS1
// Start DS2
// Wait a bit so that connections are performed
// Simulate RS1 failure
// DS1 connected to RS2 ?
// DS2 connected to RS2 ?
// Restart RS1
// DS1 connected to RS2 ?
// DS2 connected to RS2 ?
// Simulate RS2 failure
// DS1 connected to RS1 ?
// DS2 connected to RS1 ?
// Restart RS2
// DS1 connected to RS1 ?
// DS2 connected to RS1 ?
} finally
{
endTest();
}
}
/**
* Check connection of the provided replication domain to the provided
* replication server. Waits for connection to be ok up to secTimeout seconds
* before failing.
*/
throws Exception
{
switch (dsId)
{
case DS1_ID:
break;
case DS2_ID:
break;
default:
fail("Unknown replication domain server id.");
}
int rsPort = -1;
switch (rsId)
{
case RS1_ID:
break;
case RS2_ID:
break;
default:
fail("Unknown replication server id.");
}
int nSec = 0;
// Go out of the loop only if connection is verified or if timeout occurs
while (true)
{
// Test connection
int rdPort = -1;
boolean rightPort = false;
if (connected)
{
rightPort = true;
}
{
// Connection verified
+ nSec + " seconds.");
return;
}
// Sleep 1 second
nSec++;
if (nSec > secTimeout)
{
// Timeout reached, end with error
}
}
}
/**
* Find needed free TCP ports.
*/
private void findFreePorts() throws IOException
{
}
/**
* Creates a new ReplicationServer.
*/
throws ConfigException
{
int port = -1;
{
}
{
}
else
{
fail("Unknown replication server id.");
}
100, replServers);
return new ReplicationServer(conf);
}
/**
* Creates a new ReplicationDomain.
*/
throws Exception
{
// Create a domain with two replication servers
// domainConf.setHeartbeatInterval(500);
return replicationDomain;
}
{
// First check that the Replication domain is connected
if (!rd.isConnected())
return -1;
}
}