List<Event> channelEvents = new ArrayList<Event>();
Transaction txn = channel.getTransaction();
txn.begin();
for (int i = 0; i < 10; i++) {
Event e = channel.take();
Assert.assertNotNull(e);
channelEvents.add(e);
}
try {
txn.commit();
} catch (Throwable t) {
txn.rollback();
} finally {
txn.close();
}
source.stop();
for (Event e : channelEvents) {
Assert.assertNotNull(e);
String str = new String(e.getBody(), Charsets.UTF_8);
logger.info(str);
if (keepFields.equals("true") || keepFields.equals("all")) {
Assert.assertArrayEquals(bodyWithTandH.trim().getBytes(),
e.getBody());
} else if (keepFields.equals("false") || keepFields.equals("none")) {
Assert.assertArrayEquals(data1.getBytes(), e.getBody());
} else if (keepFields.equals("hostname")) {
Assert.assertArrayEquals(bodyWithHostname.getBytes(), e.getBody());
} else if (keepFields.equals("timestamp")) {
Assert.assertArrayEquals(bodyWithTimestamp.getBytes(), e.getBody());
}
}
}