source.setChangeSink(sequenceServer);
// Create a replication data writer and receive data from the primary
// data source (via the sequence server).
File workingDir1 = dataUtils.newFolder();
sequenceServer.setChangeSink(new ReplicationWriter(workingDir1));
// Send sequence through the primary pipeline to ensure the
// sequence server is running.
source.sendSequence();
// Create a HTTP replication data server using the data from the
// 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();