if (!tailer.moveToIndex(fromIndex)) { if (firstIndex > fromIndex) { tailer.toStart(); } else { return;
private static long countEntries(final ChronicleQueue queue) { final ExcerptTailer tailer = queue.createTailer(); tailer.toStart().direction(TailerDirection.FORWARD); long entryCount = 0L; while (true) { try (final DocumentContext ctx = tailer.readingDocument()) { if (!ctx.isPresent()) { break; } entryCount++; } } return entryCount; }
try { final ExcerptTailer tailer = q.createTailer(); final long start = tailer.toStart().index(); final long end = tailer.toEnd().index();
tailer.toStart();
private static void readMessage(final ChronicleQueue queue, final boolean manuallyReleaseResources, final Consumer<ExcerptTailer> refHolder) { final Bytes<ByteBuffer> bytes = Bytes.elasticByteBuffer(); try { final ExcerptTailer tailer = queue.createTailer(); while (bytes.isEmpty()) { tailer.toStart().readBytes(bytes); } refHolder.accept(tailer); assertThat(Math.signum(bytes.readInt()) >= 0, is(true)); if (manuallyReleaseResources) { try { ((SingleChronicleQueueExcerpts.StoreTailer) tailer).releaseResources(); } catch (RuntimeException e) { // ignore } } } finally { bytes.release(); } }
tailer.toStart(); for (int i = 0; i < indexes.length; i++) { assertTrue(tailer.moveToIndex(indexes[i]));
@Test public void appendAndTail() { ChronicleQueue tailer_queue = ChronicleQueue.singleBuilder(path) .testBlockSize() .buffered(false) .build(); ExcerptTailer tailer = tailer_queue.createTailer(); tailer = tailer.toStart(); long t_index; t_index = doReadBad(tailer, messages, false); assertEquals(a_index, t_index); tailer = tailer_queue.createTailer(); tailer = tailer.toStart(); t_index = doReadBad(tailer, messages, true); assertEquals(a_index, t_index); }
tailer.toStart(); final int expectedMessageCount = THREAD_COUNT * messagesPerThread; int messageCount = 0;
@Test public void shouldHandleLargeEpoch() { try (final ChronicleQueue chronicle = builder(getTmpDir(), this.wireType) .epoch(System.currentTimeMillis()) .epoch(1284739200000L) .rollCycle(DAILY) .build()) { final ExcerptAppender appender = chronicle.acquireAppender(); appender.writeDocument(wire -> wire.write(() -> "key").text("value=v")); final ExcerptTailer excerptTailer = chronicle.createTailer().toStart(); assertThat(excerptTailer.readingDocument().isPresent(), is(true)); } }
@Test public void shouldBeAbleToReadFromQueueWithNonZeroEpoch() { try (final ChronicleQueue chronicle = builder(getTmpDir(), this.wireType) .epoch(System.currentTimeMillis()) .rollCycle(RollCycles.DAILY) .build()) { final ExcerptAppender appender = chronicle.acquireAppender(); appender.writeDocument(wire -> wire.write(() -> "key").text("value=v")); Assert.assertTrue(appender.cycle() == 0); final ExcerptTailer excerptTailer = chronicle.createTailer().toStart(); assertThat(excerptTailer.readingDocument().isPresent(), is(true)); } }
private void read(@NotNull ChronicleQueue aChronicle, int expected) { final ExcerptTailer myTailer = aChronicle.createTailer(); final int myLast = HOURLY.toCycle(myTailer.toEnd().index()); final int myFirst = HOURLY.toCycle(myTailer.toStart().index()); int myCycle = myFirst - 1; long myIndex = HOURLY.toIndex(myCycle, 0); int count = 0; while (myCycle <= myLast) { // System.out.println(Long.toHexString(myIndex)); if (myTailer.moveToIndex(myIndex)) { while (myTailer.readDocument(read())) { count++; } } myIndex = HOURLY.toIndex(++myCycle, 0); } Assert.assertEquals(expected, count); }
void readForward(@NotNull ChronicleQueue chronicle, int entries) { ExcerptTailer forwardTailer = chronicle.createTailer() .direction(TailerDirection.FORWARD) .toStart(); for (int i = 0; i < entries; i++) { try (DocumentContext documentContext = forwardTailer.readingDocument()) { Assert.assertTrue(documentContext.isPresent()); Assert.assertEquals(i, RollCycles.DAILY.toSequenceNumber(documentContext.index())); StringBuilder sb = Wires.acquireStringBuilder(); ValueIn valueIn = documentContext.wire().readEventName(sb); Assert.assertTrue("hello".contentEquals(sb)); String actual = valueIn.text(); Assert.assertEquals("world" + i, actual); } } try (DocumentContext documentContext = forwardTailer.readingDocument()) { Assert.assertFalse(documentContext.isPresent()); } }
@Test public void shouldHandleCycleRollWhenInReadOnlyMode() { final MutableTimeProvider timeProvider = new MutableTimeProvider(); final ChronicleQueue queue = build(createQueue(dataDirectory, RollCycles.MINUTELY, 0, "cycleRoll", false). timeProvider(timeProvider)); final StringEvents events = queue.acquireAppender().methodWriterBuilder(StringEvents.class).build(); timeProvider.setTime(System.currentTimeMillis()); events.onEvent("firstEvent"); timeProvider.addTime(2, TimeUnit.MINUTES); events.onEvent("secondEvent"); final ChronicleQueue readerQueue = build(createQueue(dataDirectory, RollCycles.MINUTELY, 0, "cycleRoll", true). timeProvider(timeProvider)); final ExcerptTailer tailer = readerQueue.createTailer(); tailer.toStart(); try (final DocumentContext context = tailer.readingDocument()) { assertThat(context.isPresent(), is(true)); } tailer.toEnd(); try (final DocumentContext context = tailer.readingDocument()) { assertThat(context.isPresent(), is(false)); } }
@Test public void testTail() { File basePath = getTmpDir(); try (ChronicleQueue queue = ChronicleQueue.singleBuilder(basePath) .testBlockSize() .build()) { checkNoFiles(basePath); ExcerptTailer tailer = queue.createTailer(); checkNoFiles(basePath); tailer.toStart(); checkNoFiles(basePath); assertFalse(tailer.readDocument(d -> { })); checkNoFiles(basePath); } }
assertEquals(0, results.size()); tailer.toStart(); checkOneFile(baseDir); fillResults(tailer, results);
@Test public void testReadingDocumentForEmptyQueue() { File dir = getTmpDir(); try (ChronicleQueue chronicle = builder(dir, this.wireType) .rollCycle(RollCycles.HOURLY) .build()) { ExcerptTailer tailer = chronicle.createTailer(); // DocumentContext is empty as we have no queue and don't know what the wire type will be. try (DocumentContext dc = tailer.readingDocument()) { assertFalse(dc.isPresent()); } try (ChronicleQueue chronicle2 = builder(dir, this.wireType) .rollCycle(RollCycles.HOURLY) .build()) { ExcerptAppender appender = chronicle2.acquireAppender(); appender.writeDocument(w -> w.write(() -> "test - message").text("text")); while (tailer.state() == TailerState.UNINITIALISED) tailer.toStart(); // DocumentContext should not be empty as we know what the wire type will be. try (DocumentContext dc = tailer.readingDocument()) { assertTrue(dc.isPresent()); dc.wire().read(() -> "test - message").text("text", Assert::assertEquals); } } } }
tailer.toStart();
@Override public void toStart() { log.debug(String.format("toStart: %s", id)); cqTailer.toStart(); if (!cqTailer.state().equals(TailerState.FOUND_CYCLE)) { log.info("Unable to move to start because the tailer is not initialized, " + this); } }