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())); } } }
ctx.wire().write().int32(i); ctx.wire().write().bytes(new byte[1024]);
@Test public void shouldHandleCycleRoll() { File dir = tempDir("shouldHandleCycleRoll"); try (final SingleChronicleQueue queue = createQueue(dir, clock::get)) { final Pretoucher pretoucher = new Pretoucher(createQueue(dir, clock::get), chunkListener, capturedCycles::add); range(0, 10).forEach(i -> { try (final DocumentContext ctx = queue.acquireAppender().writingDocument()) { assertThat(capturedCycles.size(), is(i)); ctx.wire().write().int32(i); ctx.wire().write().bytes(new byte[1024]); } try { pretoucher.execute(); } catch (InvalidEventHandlerException e) { e.printStackTrace(); } assertThat(capturedCycles.size(), is(i + 1)); try { pretoucher.execute(); } catch (InvalidEventHandlerException e) { e.printStackTrace(); } assertThat(capturedCycles.size(), is(i + 1)); clock.addAndGet(TimeUnit.SECONDS.toMillis(5L)); }); assertThat(capturedCycles.size(), is(10)); //assertThat(chunkListener.chunkMap.isEmpty(), is(false)); } }
@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(); } } }
@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()); } }
@Override public LogOffset append(int partition, M message) { ExcerptAppender appender = partitions.get(partition).acquireAppender(); if (NO_CODEC.equals(codec)) { // default format for backward compatibility appender.writeDocument(w -> w.write(MSG_KEY).object(message)); } else { appender.writeDocument(w -> w.write().bytes(codec.encode(message))); } long offset = appender.lastIndexAppended(); LogOffset ret = new LogOffsetImpl(name, partition, offset); if (log.isDebugEnabled()) { log.debug(String.format("append to %s, value: %s", ret, message)); } return ret; }
@Override default void writeMarshallable(@NotNull final WireOut wire) { wire.write(() -> "key").bytes(key()); if (ENGINE_REPLICATION_COMPRESSION != null && value() != null) wire.write(() -> "value").compress(ENGINE_REPLICATION_COMPRESSION, value().bytesForRead()); else wire.write(() -> "value").bytes(value()); wire.write(() -> "timestamp").int64(timestamp()); wire.write(() -> "identifier").int8(identifier()); wire.write(() -> "isDeleted").bool(isDeleted()); wire.write(() -> "bootStrapTimeStamp").int64(bootStrapTimeStamp()); wire.writeComment("remoteIdentifier=" + remoteIdentifier()); } }