use of net.openhft.chronicle.queue.impl.StoreFileListener in project Chronicle-Queue by OpenHFT.
the class AcquireReleaseTest method testAccquireAndRelease.
@Test
public void testAccquireAndRelease() throws Exception {
File dir = DirectoryUtils.tempDir("AcquireReleaseTest");
try {
AtomicInteger acount = new AtomicInteger();
AtomicInteger qcount = new AtomicInteger();
StoreFileListener sfl = new StoreFileListener() {
@Override
public void onAcquired(int cycle, File file) {
System.out.println("onAcquired(): " + file);
acount.incrementAndGet();
}
@Override
public void onReleased(int cycle, File file) {
System.out.println("onReleased(): " + file);
// TODO Auto-generated method stub
qcount.incrementAndGet();
}
};
AtomicLong time = new AtomicLong(1000l);
TimeProvider tp = () -> time.getAndAccumulate(1000, (x, y) -> x + y);
ChronicleQueue queue = SingleChronicleQueueBuilder.binary(dir).testBlockSize().rollCycle(RollCycles.TEST_SECONDLY).storeFileListener(sfl).timeProvider(tp).build();
for (int i = 0; i < 10; i++) {
queue.acquireAppender().writeDocument(w -> {
w.write("a").marshallable(m -> {
m.write("b").text("c");
});
});
}
Assert.assertEquals(10, acount.get());
Assert.assertEquals(9, qcount.get());
queue.close();
} finally {
try {
IOTools.deleteDirWithFiles(dir, 2);
} catch (IORuntimeException e) {
// ignored
}
}
}
Aggregations