use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testReadAtIndexSingle.
@Test
public void testReadAtIndexSingle() {
final File file = createTempFile("testReadAtIndexSingle");
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();
tailer.index(5);
StringBuilder sb = new StringBuilder();
tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
Assert.assertEquals("value=5", sb.toString());
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testSingleWire.
// *************************************************************************
//
// *************************************************************************
@Test
public void testSingleWire() {
final File file = createTempFile("testSingleWire");
try {
final ChronicleQueue chronicle = createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
appender.writeDocument(wire -> wire.write(() -> "FirstName").text("Steve"));
appender.writeDocument(wire -> wire.write(() -> "Surname").text("Jobs"));
StringBuilder first = new StringBuilder();
StringBuilder surname = new StringBuilder();
final ExcerptTailer tailer = chronicle.createTailer();
tailer.readDocument(wire -> wire.read(() -> "FirstName").text(first));
tailer.readDocument(wire -> wire.read(() -> "Surname").text(surname));
Assert.assertEquals("Steve Jobs", first + " " + surname);
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class PublisherMain method createOutput.
private static MethodDefinition createOutput(final Path path) {
final SingleChronicleQueue queue = outputQueue(path);
final ExcerptAppender appender = queue.acquireAppender();
return new GarbageFreeMethodPublisher(() -> appender);
}
Aggregations