use of net.openhft.chronicle.queue.ExcerptTailer in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testScanFromLastKnownIndex.
@Test
public void testScanFromLastKnownIndex() {
final File file = createTempFile("testScanFromLastKnownIndex");
try {
final SingleChronicleQueue chronicle = (SingleChronicleQueue) createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
// create 100 documents
for (int i = 0; i < 65; i++) {
final int j = i;
appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
}
// creates the indexes - index's 1 and 2 are created by the indexer
new Indexer(chronicle).index();
// create 100 documents
for (long i = chronicle.lastIndex() + 1; i < 200; i++) {
final long j = i;
appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
}
final ExcerptTailer tailer = chronicle.createTailer();
{
int expected = 150;
tailer.index(expected);
StringBuilder sb = new StringBuilder();
tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
Assert.assertEquals("value=" + expected, sb.toString());
}
// read back earlier
{
int expected = 167;
tailer.index(expected);
StringBuilder sb = new StringBuilder();
tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
Assert.assertEquals("value=" + expected, sb.toString());
}
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ExcerptTailer in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testReadAtIndexWithIndexesAtStart.
@Test
public void testReadAtIndexWithIndexesAtStart() {
final File file = createTempFile("testReadAtIndexWithIndexesAtStart");
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));
}
new Indexer(chronicle).index();
long index = 67;
final ExcerptTailer tailer = chronicle.createTailer();
tailer.index(index);
StringBuilder sb = new StringBuilder();
tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
Assert.assertEquals("value=" + index, sb.toString());
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ExcerptTailer in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testSingleDirect.
@Test
public void testSingleDirect() {
final File file = createTempFile("testSingleDirect");
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 j = 0; j < chronicle.lastIndex(); j++) {
sb.setLength(0);
tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
Assert.assertEquals("value=" + j, sb.toString());
}
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ExcerptTailer 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.ExcerptTailer 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();
}
}
Aggregations