/** * Add a test message with the given ExcerptAppender and return the index position of the entry * * @param appender ExceptAppender * @param msg test message * @return index position of the entry */ private long appendEntry(@NotNull final ExcerptAppender appender, String msg) { DocumentContext dc = appender.writingDocument(); try { dc.wire().write().text(msg); return dc.index(); } finally { dc.close(); } }
@Test public void testAppenderFullFs() throws Exception { ChronicleQueue queue = SingleChronicleQueueBuilder.binary(basePath) .blockSize(256 << 1000) .rollCycle(RollCycles.DAILY) .build(); ExcerptAppender appender = queue.acquireAppender(); byte[] payload = new byte[1024]; Random r = new Random(); r.nextBytes(payload); final LocalDateTime now = LocalDateTime.now(Clock.systemUTC()); for (int i = 0; i < 1024 * 200; i++) { DocumentContext dc = appender.writingDocument(); try { Wire w = dc.wire(); w.write().dateTime(now); w.write().bytes(payload); } finally { dc.close(); } } }
/** * Read next message, forward or backward, depending on the settings of the Tailer * * @param tailer ExcerptTailer * @return entry or null, if no entry available */ private String readNextEntry(@NotNull final ExcerptTailer tailer) { DocumentContext dc = tailer.readingDocument(); try { if (dc.isPresent()) { Object parent = dc.wire().parent(); assert parent == tailer; return dc.wire().read().text(); } return null; } finally { dc.close(); } }
private static long doReadBad(@NotNull ExcerptTailer tailer, int expected, boolean additionalClose) { int[] i = {0}; long t_index = 0; while (true) { try (DocumentContext dc = tailer.readingDocument()) { if (!dc.isPresent()) break; t_index = tailer.index(); dc.wire().read("log").marshallable(m -> { String msg = m.read("msg").text(); assertNotNull(msg); i[0]++; }); if (additionalClose) { dc.close(); } } } assertEquals(expected, i[0]); return t_index; }
DocumentContext wd = appender.writingDocument(); wd.rollbackOnClose(); wd.close();
@Override public boolean action() throws InvalidEventHandlerException, InterruptedException { try { if (tailer == null) { tailer = rollingChronicleQueue.createTailer(); if (index > 0) tailer.moveToIndex(index); tailer.readingDocument(false).close(); } try (DocumentContext documentContext = tailer.readingDocument(false)) { if (!documentContext.isPresent()) return false; StringBuilder sb = Wires.acquireStringBuilder(); @NotNull ValueIn valueIn = documentContext.wire().read(sb); if ("NetworkStats".contentEquals(sb)) { valueIn.marshallable(ns); final String userId = ns.userId(); if (userId != null && !userId.isEmpty()) { updateMap(ns, documentContext.index()); } } } return true; } catch (Throwable t) { t.printStackTrace(); return true; } }