Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.CHECKPOINT_INTERVAL,
String.valueOf(Integer.MAX_VALUE));
final FileChannel channel = createFileChannel(overrides);
channel.start();
FileBackedTransaction tx = (FileBackedTransaction) channel.getTransaction();
InflightEventWrapper inflightPuts =
field("inflightPuts").ofType(InflightEventWrapper.class).in(
field("queue").ofType(FlumeEventQueue.class).in(tx).get()).get();
tx.begin();
for (int i = 0; i < 100; i++) {
channel.put(EventBuilder.withBody("TestEvent".getBytes()));
}
Assert.assertFalse(inflightPuts.getFileIDs().isEmpty());
Assert.assertFalse(inflightPuts.getInFlightPointers().isEmpty());
tx.rollback();
tx.close();
Assert.assertTrue(inflightPuts.getFileIDs().isEmpty());
Assert.assertTrue(inflightPuts.getInFlightPointers().isEmpty());
Assert.assertTrue(channel.getDepth() == 0);
Set<String> in = putEvents(channel, "testing-rollbacks", 100, 100);
tx = (FileBackedTransaction) channel.getTransaction();
InflightEventWrapper inflightTakes =
field("inflightTakes").ofType(InflightEventWrapper.class).in(
field("queue").ofType(FlumeEventQueue.class).in(tx).get()).get();
tx.begin();
for (int i = 0; i < 100; i++) {
channel.take();
}
Assert.assertFalse(inflightTakes.getFileIDs().isEmpty());
Assert.assertFalse(inflightTakes.getInFlightPointers().isEmpty());
tx.rollback();
tx.close();
Assert.assertTrue(inflightTakes.getFileIDs().isEmpty());
Assert.assertTrue(inflightTakes.getInFlightPointers().isEmpty());
Assert.assertTrue(channel.getDepth() == in.size());