@SuppressWarnings("unused") @UsedViaReflection SCQMeta(@NotNull WireIn wire) { this.roll = Objects.requireNonNull(wire.read(MetaDataField.roll).typedMarshallable()); this.deltaCheckpointInterval = wire.bytes().readRemaining() > 0 ? wire.read(MetaDataField.deltaCheckpointInterval).int32() : -1; // disabled. this.sourceId = wire.bytes().readRemaining() > 0 ? wire.read(MetaDataField.sourceId).int32() : 0; }
/** * used by {@link Demarshallable} * * @param wire a wire */ @UsedViaReflection private SCQIndexing(@NotNull WireIn wire) { this(wire.read(IndexingFields.indexCount).int32(), wire.read(IndexingFields.indexSpacing).int32(), wire.read(IndexingFields.index2Index).int64ForBinding(wire.newLongReference()), wire.read(IndexingFields.lastIndex).int64ForBinding(wire.newLongReference()), wire::newLongArrayReference); }
@NotNull private List<Integer> fillResults(@NotNull ExcerptTailer tailer, @NotNull List<Integer> results) { for (int i = 0; i < 10; i++) { try (DocumentContext documentContext = tailer.readingDocument()) { if (!documentContext.isPresent()) break; results.add(documentContext.wire().read(() -> "msg").int32()); } } return results; }
/** * used by {@link Demarshallable} * * @param wire a wire */ @UsedViaReflection private SCQRoll(@NotNull WireIn wire) { length = wire.read(RollFields.length).int32(); format = wire.read(RollFields.format).text(); epoch = wire.read(RollFields.epoch).int64(); ValueIn rollTimeVIN = wire.read(RollFields.rollTime); if (rollTimeVIN.hasNext()) rollTime = rollTimeVIN.time(); String zoneId = wire.read(RollFields.rollTimeZone).text(); if (zoneId != null) rollTimeZone = ZoneId.of(zoneId); else rollTimeZone = null; }
private static void expectValue(final int expectedValue, final ExcerptTailer tailer) { try (final DocumentContext documentContext = tailer.readingDocument()) { assertTrue(documentContext.isPresent()); assertEquals(expectedValue, documentContext.wire().getValueIn().int32()); } }
@Test public void test() { File dir = getTmpDir(); try (final ChronicleQueue queue = SingleChronicleQueueBuilder.builder(dir, wireType) .testBlockSize() .build()) { final ExcerptTailer tailer = queue.createTailer(); assertFalse(tailer.readDocument(r -> r.read(TestKey.test).int32())); final ExcerptAppender appender = queue.acquireAppender(); appender.writeDocument(w -> w.write(TestKey.test).int32(1)); Jvm.pause(100); assertTrue(tailer.readDocument(r -> r.read(TestKey.test).int32())); } }
v = valueIn.int32(); if (lastRead + 1 != v) { System.out.println(dc.wire());
for (int i = 0; i < 2; ) { boolean read = tailer.readDocument(r -> { int result = r.read(TestKey.test).int32(); results[result] = result; });
final DocumentContext context = newTailer.readingDocument(); if (context.isPresent() && context.isData()) { assertTrue(context.wire().read().int32() != 0); totalCount++; } else if (!context.isPresent()) {
try (DocumentContext dc = tailer.readingDocument()) { if (dc.isPresent()) { fail("Should be at the end of the queue but dc.isPresent and we read: " + String.valueOf(dc.wire().read(() -> "msg").int32())); int i = dc.wire().read(() -> "msg").int32(); assertEquals("Should've read 4, instead we read: " + i, 4, i); try (DocumentContext dc = tailer.readingDocument()) { assertTrue(dc.isPresent()); int i = dc.wire().read(() -> "msg").int32(); assertEquals(j, i); fail("Should be at the end of the queue but dc.isPresent and we read: " + String.valueOf(dc.wire().read(() -> "msg").int32())); assertEquals(5, dc.wire().read(() -> "msg").int32());
@Test public void testAppendAndRead() { try (final ChronicleQueue queue = builder(getTmpDir(), this.wireType) .build()) { final ExcerptAppender appender = queue.acquireAppender(); final int cycle = appender.cycle(); for (int i = 0; i < 10; i++) { final int n = i; appender.writeDocument(w -> w.write(TestKey.test).int32(n)); assertEquals(n, queue.rollCycle().toSequenceNumber(appender.lastIndexAppended())); } final ExcerptTailer tailer = queue.createTailer(); // Sequential read for (int i = 0; i < 10; i++) { final int n = i; assertTrue(tailer.readDocument(r -> assertEquals(n, r.read(TestKey.test).int32()))); assertEquals(n + 1, queue.rollCycle().toSequenceNumber(tailer.index())); } // Random read for (int i = 0; i < 10; i++) { final int n = i; assertTrue("n: " + n, tailer.moveToIndex(queue.rollCycle().toIndex(cycle, n))); assertTrue("n: " + n, tailer.readDocument(r -> assertEquals(n, r.read(TestKey.test).int32()))); assertEquals(n + 1, queue.rollCycle().toSequenceNumber(tailer.index())); } } }
@Test public void testLongLivingTailerAppenderReAcquiredEachSecond() { SetTimeProvider timeProvider = new SetTimeProvider(); final File dir = DirectoryUtils.tempDir(testName.getMethodName()); final RollCycles rollCycle = RollCycles.TEST_SECONDLY; try (ChronicleQueue queuet = binary(dir) .rollCycle(rollCycle) .timeProvider(timeProvider) .build()) { final ExcerptTailer tailer = queuet.createTailer(); // write first message try (ChronicleQueue queue = binary(dir) .rollCycle(rollCycle) .timeProvider(timeProvider) .build()) { for (int i = 0; i < 5; i++) { final ExcerptAppender appender = queue.acquireAppender(); timeProvider.advanceMillis(1100); try (final DocumentContext dc = appender.writingDocument()) { dc.wire().write("some").int32(i); } try (final DocumentContext dc = tailer.readingDocument()) { Assert.assertEquals(i, dc.wire().read("some").int32()); } } } } }
@Test public void testAppendAndReadAtIndex() { try (final ChronicleQueue queue = builder(getTmpDir(), this.wireType) .rollCycle(TEST2_DAILY) .build()) { final ExcerptAppender appender = queue.acquireAppender(); appender.cycle(); for (int i = 0; i < 5; i++) { final int n = i; appender.writeDocument(w -> w.write(TestKey.test).int32(n)); assertEquals(i, queue.rollCycle().toSequenceNumber(appender.lastIndexAppended())); } final ExcerptTailer tailer = queue.createTailer(); for (int i = 0; i < 5; i++) { final long index = queue.rollCycle().toIndex(appender.cycle(), i); assertTrue(tailer.moveToIndex(index)); final int n = i; assertTrue(tailer.readDocument(r -> assertEquals(n, queue.rollCycle().toSequenceNumber(r.read(TestKey.test) .int32())))); long index2 = tailer.index(); long sequenceNumber = queue.rollCycle().toSequenceNumber(index2); assertEquals(n + 1, sequenceNumber); } } }
@Override public void readMarshallable(@NotNull WireIn wire) { bits = wire.read(() -> "bits").int32(); mask = (1 << bits) - 1; }
@Override public void readMarshallable(@NotNull WireIn wire) throws IllegalStateException { wire.read(() -> "wireType").asEnum(WireType.class, wt -> wireType = wt); wire.read(() -> "port").int32(this, (o, i) -> o.port = i); wire.read(() -> "logTCPMessages").asEnum(YamlLogging.YamlLoggingLevel.class, this, (o, b) -> o.logTCPMessages = b); wire.read(() -> "heartbeatIntervalTicks").int32(this, (o, i) -> o.heartbeatIntervalTicks = i); wire.read(() -> "heartbeatIntervalTimeout").int32(this, (o, i) -> o.heartbeatIntervalTimeout = i); }
@UsedViaReflection private UberHandler(@NotNull WireIn wire) { remoteIdentifier = wire.read(() -> "remoteIdentifier").int32(); localIdentifier = wire.read(() -> "localIdentifier").int32(); @Nullable final WireType wireType = wire.read(() -> "wireType").object(WireType.class); clusterName = wire.read(() -> "clusterName").text(); wireType(wireType); }
@SuppressWarnings("unused") @UsedViaReflection SCQMeta(@NotNull WireIn wire) { this.roll = Objects.requireNonNull(wire.read(MetaDataField.roll).typedMarshallable()); this.deltaCheckpointInterval = wire.bytes().readRemaining() > 0 ? wire.read(MetaDataField.deltaCheckpointInterval).int32() : -1; // disabled. this.sourceId = wire.bytes().readRemaining() > 0 ? wire.read(MetaDataField.sourceId).int32() : 0; }
/** * used by {@link Demarshallable} * * @param wire a wire */ @UsedViaReflection private SCQIndexing(@NotNull WireIn wire) { this(wire.read(IndexingFields.indexCount).int32(), wire.read(IndexingFields.indexSpacing).int32(), wire.read(IndexingFields.index2Index).int64ForBinding(wire.newLongReference()), wire.read(IndexingFields.lastIndex).int64ForBinding(wire.newLongReference()), wire::newLongArrayReference); }
@Override protected void readMarshallableFields(@NotNull WireIn wireIn) { super.readMarshallableFields(wireIn); valueClass = wireIn.read(() -> "valueClass").typeLiteral(); valueSizeMarshaller = wireIn.read(() -> "valueSizeMarshaller").object(SizeMarshaller.class); valueReader = wireIn.read(() -> "valueReader").object(SizedReader.class); valueDataAccess = wireIn.read(() -> "valueDataAccess").object(DataAccess.class); constantlySizedEntry = wireIn.read(() -> "constantlySizedEntry").bool(); alignment = wireIn.read(() -> "alignment").int32(); worstAlignment = wireIn.read(() -> "worstAlignment").int32(); }
@Override public void readMarshallable(@NotNull WireIn wire) throws IllegalStateException { wire.read(() -> "spec").text(this, (o, s) -> o.spec = s) .read(() -> "name").text(this, (o, s) -> o.name = s) .read(() -> "cluster").text(this, (o, s) -> o.cluster = s) .read(() -> "maxEntries").int64(this, (o, e) -> o.maxEntries = e) .read(() -> "averageValueSize").int32(this, (o, e) -> o.averageValueSize = e) .read(() -> "putReturnsNull").bool(this, (o, b) -> o.putReturnsNull = b) .read(() -> "removeReturnsNull").bool(this, (o, b) -> o.removeReturnsNull = b); }