use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testReadAtIndexWithIndexes.
@Test
public void testReadAtIndexWithIndexes() {
final File file = createTempFile("testReadAtIndexWithIndexes");
try {
final SingleChronicleQueue chronicle = (SingleChronicleQueue) createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
// create 100 documents
for (int i = 0; i < 100; i++) {
final int j = i;
appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
}
// creates the indexes
new Indexer(chronicle).index();
final ExcerptTailer tailer = chronicle.createTailer();
tailer.index(67);
StringBuilder sb = new StringBuilder();
tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
Assert.assertEquals("value=67", sb.toString());
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testLastWrittenIndexPerAppenderNoData.
@Test(expected = IllegalStateException.class)
public void testLastWrittenIndexPerAppenderNoData() {
final File file = createTempFile("testLastWrittenIndexPerAppenderNoData");
try {
final ChronicleQueue chronicle = createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
appender.lastWrittenIndex();
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testReadAtIndex.
@Test
public void testReadAtIndex() {
final File file = createTempFile("testReadAtIndex");
try {
final DirectChronicleQueue chronicle = createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
// create 100 documents
for (int i = 0; i < 100; i++) {
final int j = i;
appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
}
final ExcerptTailer tailer = chronicle.createTailer();
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++) {
tailer.index(i);
sb.setLength(0);
tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
Assert.assertEquals("value=" + i, sb.toString());
}
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testLastIndexPerChronicle.
@Test
public void testLastIndexPerChronicle() {
final File file = createTempFile("testLastIndexPerChronicle");
try {
final DirectChronicleQueue chronicle = createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
appender.writeDocument(wire -> wire.write(() -> "key").text("test"));
Assert.assertEquals(0, chronicle.lastIndex());
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class GarbageFreeMethodPublisher method onEightyByteMessage.
@Override
public void onEightyByteMessage(final EightyByteMessage message) {
final ExcerptAppender appender = outputSupplier.get();
// DebugTimestamps.operationStart(DebugTimestamps.Operation.GET_WRITING_DOCUMENT);
@NotNull DocumentContext context = appender.writingDocument();
// DebugTimestamps.operationEnd(DebugTimestamps.Operation.GET_WRITING_DOCUMENT);
try {
Wire wire = context.wire();
// DebugTimestamps.operationStart(DebugTimestamps.Operation.WRITE_EVENT);
try {
wire.write(MethodReader.HISTORY).marshallable(MessageHistory.get());
final ValueOut valueOut = wire.writeEventName("onEightyByteMessage");
valueOut.object(EightyByteMessage.class, message);
wire.padToCacheAlign();
} finally {
// DebugTimestamps.operationEnd(DebugTimestamps.Operation.WRITE_EVENT);
}
} finally {
// DebugTimestamps.operationStart(DebugTimestamps.Operation.CLOSE_CONTEXT);
try {
context.close();
} finally {
// DebugTimestamps.operationEnd(DebugTimestamps.Operation.CLOSE_CONTEXT);
}
}
}
Aggregations