// replication writer, and receive sequence number updates from the
// sequence server.
ReplicationDataServer dataServer = new ReplicationDataServer(sequenceServer.getPort(), workingDir1, 0);
// Start the HTTP data server.
TaskRunner serverRunner = new TaskRunner(dataServer, "data-server");
serverRunner.start();
/*
* The server starts in another thread so we need to wait until it has
* started. We will wait until the dynamically allocated port is
* exported via the getPort method which occurs after server startup.
*/
timerStart = System.currentTimeMillis();
while (dataServer.getPort() == 0 && (System.currentTimeMillis() - timerStart < 10000)) {
Thread.sleep(10);
}
Assert.assertFalse("Server port was not dynamically allocated.", sequenceServer.getPort() == 0);
// Create a HTTP replication data client receiving data from the data
// server.
ReplicationDataClient dataClient = new ReplicationDataClient(new InetSocketAddress(dataServer.getPort()), "");
// Create a replication data writer to receiving data from the HTTP data
// source.
File workingDir2 = dataUtils.newFolder();
dataClient.setChangeSink(new ReplicationWriter(workingDir2));
// Start the HTTP data server and HTTP data client.
TaskRunner clientRunner = new TaskRunner(dataClient, "data-client");
clientRunner.start();
// Send the test replication intervals.
for (int i = 0; i < sequenceCount; i++) {
source.sendSequence();
}
// Wait for all the data to reach the destination.
File finalStateFile = new File(workingDir2, new ReplicationSequenceFormatter(9, 3).getFormattedName(
sequenceCount, ".state.txt"));
timerStart = System.currentTimeMillis();
while (!finalStateFile.exists() && (System.currentTimeMillis() - timerStart < 10000)) {
Thread.sleep(100);
}
// Verify that all of the replication sequences made it to the
// destination.
Assert.assertTrue("The state file for sequence " + sequenceCount + " doesn't exist.", finalStateFile.exists());
// Shut down the pipelines.
clientRunner.interrupt();
serverRunner.interrupt();
clientRunner.join();
serverRunner.join();
source.release();
}