@Test public void testLastIndexAppended() { try (ChronicleQueue chronicle = builder(getTmpDir(), this.wireType) .build()) { ExcerptAppender appender = chronicle.acquireAppender(); appender.writeDocument(w -> w.writeEventName("hello").text("world0")); final long nextIndexToWrite = appender.lastIndexAppended() + 1; appender.writeDocument(w -> w.getValueOut().bytes(new byte[0])); // System.out.println(chronicle.dump()); Assert.assertEquals(nextIndexToWrite, appender.lastIndexAppended()); } }
public void appendMessage(@NotNull ChronicleQueue queue, long expectedIndex, String msg) { @NotNull ExcerptAppender appender = queue.acquireAppender(); switch (appendMode) { case 1: appender.writeDocument(w -> w.write(() -> "msg").text(msg)); break; case 2: Bytes bytes = Bytes.elasticByteBuffer(); new BinaryWire(bytes).write(() -> "msg").text(msg); appender.writeBytes(bytes); bytes.release(); break; default: try (DocumentContext dc = appender.writingDocument()) { Wire wire = dc.wire(); wire.write(() -> "msg").text(msg); } break; } long index = appender.lastIndexAppended(); assertHexEquals(expectedIndex, index); }
Thread thread = Thread.currentThread(); while (!thread.isInterrupted()) { appender.pretouch(); Jvm.pause(10); while (end > System.nanoTime()) { long start = System.nanoTime(); try (DocumentContext dc = appender.writingDocument(false)) { writeMessage(dc.wire(), messageSize);
private void write(@NotNull ChronicleQueue aChronicle, int messages) { final ExcerptAppender myAppender = aChronicle.acquireAppender(); for (int myCount = 0; myCount < messages; myCount++) { myAppender.writeDocument(aMarshallable -> aMarshallable.write().bytes(Long.toString(currentTimeMillis()).getBytes(StandardCharsets.UTF_8))); // System.out.println(Long.toHexString(myAppender.lastIndexAppended())); } } }
private static void write(final ExcerptAppender appender, final Data data) throws Exception { try (final DocumentContext dc = appender.writingDocument()) { final ObjectOutput out = dc.wire().objectOutput(); out.writeInt(data.id); } }
@Test public void testIndex() { try (final ChronicleQueue queue = builder(getTmpDir(), this.wireType) .rollCycle(RollCycles.HOURLY) .build()) { final ExcerptAppender appender = queue.acquireAppender(); int cycle = appender.cycle(); // create 100 documents for (int i = 0; i < 5; i++) { final int j = i; appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j)); if (i == 2) { final long cycle1 = queue.rollCycle().toCycle(appender.lastIndexAppended()); Assert.assertEquals(cycle1, cycle); } } final ExcerptTailer tailer = queue.createTailer(); assertTrue(tailer.moveToIndex(queue.rollCycle().toIndex(cycle, 2))); StringBuilder sb = new StringBuilder(); tailer.readDocument(wire -> wire.read(() -> "key").text(sb)); Assert.assertEquals("value=2", sb.toString()); tailer.readDocument(wire -> wire.read(() -> "key").text(sb)); Assert.assertEquals("value=3", sb.toString()); tailer.readDocument(wire -> wire.read(() -> "key").text(sb)); Assert.assertEquals("value=4", sb.toString()); } }
@Test public void testMultipleAppenders() { try (ChronicleQueue syncQ = builder(getTmpDir(), this.wireType) .rollCycle(TEST_DAILY) .build()) { ExcerptAppender syncA = syncQ.acquireAppender(); assumeFalse(syncA.padToCacheAlignMode() == WORD); ExcerptAppender syncB = syncQ.acquireAppender(); ExcerptAppender syncC = syncQ.acquireAppender(); int count = 0; for (int i = 0; i < 3; i++) { syncA.writeText("hello A" + i); assertEquals(count++, (int) syncA.lastIndexAppended()); syncB.writeText("hello B" + i); assertEquals(count++, (int) syncB.lastIndexAppended()); try (DocumentContext dc = syncC.writingDocument(true)) { dc.wire().getValueOut().text("some meta " + i); } } String expected = expectedMultipleAppenders(); assertEquals(expected, syncQ.dump()); } }
default void writeBytes(@NotNull Bytes bytes) throws UnrecoverableTimeoutException { writeBytes((BytesStore) bytes); }
@Test public void shouldIndicateNoProcessIdWhenDocumentIsComplete() throws IOException { try (final RollingChronicleQueue queue = ChronicleQueue.singleBuilder(getTmpDir()). testBlockSize(). build()) { final QueueInspector inspector = new QueueInspector(queue); final ExcerptAppender appender = queue.acquireAppender(); appender.writeDocument(37L, ValueOut::int64); try (final DocumentContext ctx = appender.writingDocument()) { ctx.wire().write("foo").int32(17L); } final int writingThreadId = inspector.getWritingThreadId(); assertThat(writingThreadId, is(not(OS.getProcessId()))); assertThat(QueueInspector.isValidThreadId(writingThreadId), is(false)); } }
@Test public void testIndexWritingDocument() { try (final ChronicleQueue chronicle = builder(getTmpDir(), this.wireType) .build()) { final ExcerptAppender appender = chronicle.acquireAppender(); long index; try (DocumentContext dc = appender.writingDocument()) { dc.wire().write(() -> "FirstName").text("Quartilla"); index = dc.index(); } try (DocumentContext dc = appender.writingDocument(true)) { dc.wire().write(() -> "FirstName").text("Quartilla"); } Assert.assertEquals(index, appender.lastIndexAppended()); } }
Wire wire; try (DocumentContext dc = appender.writingDocument()) { wire = dc.wire(); wire.write().text("hello world"); File dir = new File(appender.queue().fileAbsolutePath()); files = dir.listFiles(pathname -> pathname.getAbsolutePath().endsWith(".cq4")); appender.writeText("hello world 2"); ExcerptTailer excerptTailer = q.createTailer().toEnd(); q.acquireAppender() .writeText(EXPECTED); Assert.assertEquals(EXPECTED, excerptTailer.readText());
/** * test that if we make EPOC the current time, then the cycle is == 0 * * @ */ @Test public void testEPOC() { try (final ChronicleQueue chronicle = builder(getTmpDir(), this.wireType) .epoch(System.currentTimeMillis()) .rollCycle(RollCycles.HOURLY) .build()) { final ExcerptAppender appender = chronicle.acquireAppender(); appender.writeDocument(wire -> wire.write(() -> "key").text("value=v")); Assert.assertTrue(appender.cycle() == 0); } }
@NotNull public JDBCStatement createWriter() { return in.acquireAppender() .methodWriterBuilder(JDBCStatement.class) .recordHistory(true) .get(); }
@Before public void setup() { chroniclePath = new File(OS.TARGET, "read_only"); try (ChronicleQueue readWrite = ChronicleQueue.singleBuilder(chroniclePath) .readOnly(false) .testBlockSize() .build()) { final ExcerptAppender appender = readWrite.acquireAppender(); appender.writeText(STR1); try (DocumentContext dc = appender.writingDocument()) { dc.wire().bytes().writeUtf8(STR2); } } }
.methodWriterBuilder(Msg.class) .recordHistory(true) .build(); .methodWriterBuilder(Msg.class) .recordHistory(true) .build(); msg.msg("somedata-4"); try (DocumentContext dc = outQueue.acquireAppender().writingDocument(true)) { dc.wire().write("some metadata");
public static void main(String[] args) { SingleChronicleQueue outQueue = SingleChronicleQueueBuilder.binary("target/" + "monitor") .rollCycle(RollCycles.TEST_SECONDLY).build(); ExcerptAppender outQueueAppender = outQueue.acquireAppender(); HeartbeatListener heartbeatWriter = outQueueAppender.methodWriterBuilder(HeartbeatListener.class).methodWriterListener((m, a) -> validateAll(a)).recordHistory(true).build(); Monitor.addPeriodicUpdateSource(10, () -> currentTimeMillis -> { outQueueAppender.pretouch(); }); long lastHB = 0; while (true) { if (System.currentTimeMillis() - lastHB > 1) { // write a hb to the queue MessageHistory.get().reset(); Heartbeat heartBeat = new Heartbeat(UUID.randomUUID().toString()); heartbeatWriter.heartbeat(heartBeat); lastHB = System.currentTimeMillis(); } } }
@Override public Throwable call() throws Exception { ChronicleQueue queue0 = null; try (ChronicleQueue queue = queueBuilder(path).build()) { queue0 = queue; ExcerptAppender appender = queue.acquireAppender(); System.out.println("Starting pretoucher"); while (!Thread.currentThread().isInterrupted() && !queue.isClosed()) { Jvm.pause(50); appender.pretouch(); } } catch (Throwable e) { if (queue0 != null && queue0.isClosed()) return null; exception = e; return e; } return null; } }
PingDTO pdtio = new PingDTO(); PingDTO.constructionExpected++; Pinger pinger = cq.acquireAppender().methodWriter(Pinger.class); for (int i = 0; i < 5; i++) { pinger.ping(pdtio);
@Test(expected = IllegalStateException.class) //: no messages written public void testNoMessagesWritten() { try (final ChronicleQueue chronicle = builder(getTmpDir(), this.wireType) .build()) { final ExcerptAppender appender = chronicle.acquireAppender(); appender.lastIndexAppended(); } }
@NotNull default <T> T methodWriter(@NotNull Class<T> tClass, Class... additional) { return queue().methodWriter(tClass, additional); }