Source:
public void testSeekByTimestamp() throws Exception { manager.createIfNotExists(logName, 1); LogAppender<KeyValueMessage> appender = manager.getAppender(logName); appender.append(0, KeyValueMessage.of("id1")); appender.append(0, KeyValueMessage.of("id2")); appender.append(0, KeyValueMessage.of("id3")); appender.append(0, KeyValueMessage.of("id4")); appender.append(0, KeyValueMessage.of("id5")); Instant now = Instant.now(); Thread.sleep(3000); appender.append(0, KeyValueMessage.of("id6")); appender.append(0, KeyValueMessage.of("id7")); appender.append(0, KeyValueMessage.of("id8")); LogOffset offset9 = appender.append(0, KeyValueMessage.of("id9")); LogPartition logPartition = LogPartition.of(logName, 0); try (LogTailer<KeyValueMessage> tailer = manager.createTailer(GROUP, logPartition)) { Assert.assertEquals("id1", tailer.read(DEF_TIMEOUT).message().key()); tailer.seek(offset9); Assert.assertEquals("id9", tailer.read(DEF_TIMEOUT).message().key()); tailer.commit(); assertEquals("There should be no lag, because we at the last record", 0, manager.getLag(logName, GROUP).lag()); LogOffset logOffset = tailer.offsetForTimestamp(logPartition, now.toEpochMilli()); tailer.seek(logOffset); tailer.commit(); assertEquals("After moving the tailer, we should have a lag of 4.", 4, manager.getLag(logName, GROUP).lag()); Assert.assertEquals("id6", tailer.read(DEF_TIMEOUT).message().key()); Assert.assertEquals("id7", tailer.read(DEF_TIMEOUT).message().key()); Assert.assertEquals("id8", tailer.read(DEF_TIMEOUT).message().key()); Assert.assertEquals("Must read 9 again","id9", tailer.read(DEF_TIMEOUT).message().key()); } }

Target:
public void testSeekByTimestamp() throws Exception { manager.createIfNotExists(logName, 1); LogAppender<KeyValueMessage> appender = manager.getAppender(logName); appender.append(0, KeyValueMessage.of("id1")); appender.append(0, KeyValueMessage.of("id2")); appender.append(0, KeyValueMessage.of("id3")); appender.append(0, KeyValueMessage.of("id4")); appender.append(0, KeyValueMessage.of("id5")); Instant now = Instant.now(); Thread.sleep(3000); appender.append(0, KeyValueMessage.of("id6")); appender.append(0, KeyValueMessage.of("id7")); appender.append(0, KeyValueMessage.of("id8")); LogOffset offset9 = appender.append(0, KeyValueMessage.of("id9")); LogPartition logPartition = LogPartition.of(logName, 0); try (LogTailer<KeyValueMessage> tailer = manager.createTailer(GROUP, logPartition)) { Assert.assertEquals("id1", tailer.read(DEF_TIMEOUT).message().key()); tailer.seek(offset9); Assert.assertEquals("id9", tailer.read(DEF_TIMEOUT).message().key()); tailer.commit(); assertEquals("There should be no lag, because we are at the last record", 0, manager.getLag(logName, GROUP).lag()); LogOffset logOffset = tailer.offsetForTimestamp(logPartition, now.toEpochMilli()); tailer.seek(logOffset); tailer.commit(); assertEquals("After moving the tailer, we should have a lag of 4.", 4, manager.getLag(logName, GROUP).lag()); Assert.assertEquals("id6", tailer.read(DEF_TIMEOUT).message().key()); Assert.assertEquals("id7", tailer.read(DEF_TIMEOUT).message().key()); Assert.assertEquals("id8", tailer.read(DEF_TIMEOUT).message().key()); Assert.assertEquals("Must read 9 again","id9", tailer.read(DEF_TIMEOUT).message().key()); } }