@Test
public void testFailover() throws InterruptedException, IOException {
final Logger logger = LogManager.getLogger("testFailover");
logger.debug("Starting testFailover");
for (int i = 0; i < 10; ++i) {
final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Primary " + i, "Test");
msg.put("counter", Integer.toString(i));
EventLogger.logEvent(msg);
}
boolean[] fields = new boolean[10];
for (int i = 0; i < 10; ++i) {
final Event event = primary.poll();
Assert.assertNotNull("Received " + i + " events. Event " + (i + 1) + " is null", event);
final String value = event.getHeaders().get("counter");
Assert.assertNotNull("Missing counter", value);
final int counter = Integer.parseInt(value);
if (fields[counter]) {
Assert.fail("Duplicate event");
} else {
fields[counter] = true;
}
}
for (int i = 0; i < 10; ++i) {
Assert.assertTrue("Channel contained event, but not expected message " + i, fields[i]);
}
// Give the AvroSink time to receive notification and notify the channel.
Thread.sleep(500);
primary.stop();
for (int i = 0; i < 10; ++i) {
final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Alternate " + i, "Test");
msg.put("cntr", Integer.toString(i));
EventLogger.logEvent(msg);
}
fields = new boolean[10];
for (int i = 0; i < 10; ++i) {
final Event event = alternate.poll();