// First establish a connection so that the database is created.
getConnection().close();
// Then shut down the database cleanly so that it can be used
// to seed the replication slave.
final TestConfiguration config = TestConfiguration.getCurrent();
config.shutdownDatabase();
// Copy the database to the slave.
final String masterDb = config.getDatabasePath(MASTER_DB);
final String slaveDb = config.getDatabasePath(SLAVE_DB);
PrivilegedFileOpsForTests.copy(new File(masterDb), new File(slaveDb));
// And start the slave.
DataSource startSlaveDS = JDBCDataSource.getDataSource(SLAVE_DB);
JDBCDataSource.setBeanProperty(startSlaveDS, "connectionAttributes",
"startSlave=true;slaveHost=" + config.getHostName() +
";slavePort=" + config.getPort());
SlaveThread slave = new SlaveThread(startSlaveDS);
slave.start();
// Start the master. This will fail until the slave is up, so do
// it in a loop until successful or time runs out.
DataSource startMasterDS = JDBCDataSource.getDataSource();
String startMasterAttr =
"startMaster=true;slaveHost=" + config.getHostName() +
";slavePort=" + config.getPort();
JDBCDataSource.setBeanProperty(
startMasterDS, "connectionAttributes", startMasterAttr);
println("Starting master with attributes: " + startMasterAttr);
long giveUp =
System.currentTimeMillis() + NetworkServerTestSetup.getWaitTime();