我想阅读写入 SingleChronicleQueue 实例的最后一条消息。
虽然“chronicle.createTailer().direction(TailerDirection.BACKWARD).toEnd()”在我们与最后一条写入消息处于同一周期时有效,但只要我们处于未来周期之一(与最后一次写入相比)消息),tailer.readDocument(...) 总是返回“false”。
我已经基于 SingleChronicleQueueTest.testForwardFollowedBackBackwardTailer测试实现了一个重现问题的测试:
@Test
public void testForwardFollowedBackBackwardTailer() {
File tmpDir = getTmpDir();
// when "forwardToFuture" flag is set, go one day to the future
AtomicBoolean forwardToFuture = new AtomicBoolean(false);
TimeProvider timeProvider = () -> forwardToFuture.get()
? System.currentTimeMillis() + Duration.ofDays(1).toMillis()
: System.currentTimeMillis();
try (RollingChronicleQueue chronicle = SingleChronicleQueueBuilder.binary(tmpDir)
.rollCycle(TEST2_DAILY)
.wireType(this.wireType)
.timeProvider(timeProvider)
.build()) {
ExcerptAppender appender = chronicle.acquireAppender();
int entries = chronicle.rollCycle().defaultIndexSpacing() + 2;
for (int i = 0; i < entries; i++) {
int finalI = i;
appender.writeDocument(w -> w.writeEventName("hello").text("world" + finalI));
}
// go to the future (and to the next roll cycle)
forwardToFuture.set(true);
for (int i = 0; i < 3; i++) {
readForward(chronicle, entries);
readBackward(chronicle, entries);
}
}
}
在对“testForwardFollowedBackwardTailer”方法进行这些更改后,测试在“readBackward”方法中的 assertTrue(documentContext.isPresent()) 行失败。
有没有办法可靠地从 SingleChronicleQueue 实例中读取最后一条消息,无论最后一条消息过去多远?(没有从一开始就通读整个编年史实例)