use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchBeforeStartReverse.
@Test
public void findByBinarySearchBeforeStartReverse() {
final File queueDir = getTmpDir();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
int max = 10, reps = 5;
populateQueueWithTimestamps(queue, max, reps);
// this should be before the start
long tsToLookFor = getTimestampAtIndex(-1);
ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).inReverseOrder().withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
reader.execute();
assertEquals(0, capturedOutput.size());
}
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchSparseRepeatedReverse.
@Test
public void findByBinarySearchSparseRepeatedReverse() {
final File queueDir = getTmpDir();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
try (ExcerptAppender appender = queue.acquireAppender()) {
writeTimestamp(appender, getTimestampAtIndex(1));
writeTimestamp(appender, getTimestampAtIndex(2));
writeTimestamp(appender, getTimestampAtIndex(2));
appender.writeText("aaaa");
writeTimestamp(appender, getTimestampAtIndex(2));
writeTimestamp(appender, getTimestampAtIndex(2));
writeTimestamp(appender, getTimestampAtIndex(2));
writeTimestamp(appender, getTimestampAtIndex(3));
}
capturedOutput.clear();
long tsToLookFor = getTimestampAtIndex(2);
ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).inReverseOrder().withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
reader.execute();
assertEquals(7, capturedOutput.size() / 2);
}
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchApprox.
@Test
public void findByBinarySearchApprox() {
final File queueDir = getTmpDir();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
final int reps = 5;
final int max = 10;
populateQueueWithTimestamps(queue, max, reps);
for (int i = 0; i < max; i++) {
capturedOutput.clear();
long tsToLookFor = getTimestampAtIndex(i) - 1;
System.out.println("Looking for " + tsToLookFor);
ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
reader.execute();
assertEquals(reps * (max - i), capturedOutput.size() / 2);
}
}
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchSparseApproxReverse.
@Test
public void findByBinarySearchSparseApproxReverse() {
final File queueDir = getTmpDir();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
try (ExcerptAppender appender = queue.acquireAppender()) {
writeTimestamp(appender, getTimestampAtIndex(1));
writeTimestamp(appender, getTimestampAtIndex(2));
writeTimestamp(appender, getTimestampAtIndex(2));
appender.writeText("aaaa");
writeTimestamp(appender, getTimestampAtIndex(4));
writeTimestamp(appender, getTimestampAtIndex(4));
writeTimestamp(appender, getTimestampAtIndex(4));
}
capturedOutput.clear();
long tsToLookFor = getTimestampAtIndex(3);
ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).inReverseOrder().withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
reader.execute();
assertEquals(3, capturedOutput.size() / 2);
}
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method shouldNotFailOnEmptyQueue.
@Test
public void shouldNotFailOnEmptyQueue() {
Path path = getTmpDir().toPath();
path.toFile().mkdirs();
if (!OS.isWindows())
expectException("Failback to readonly tablestore");
new ChronicleReader().withBasePath(path).withMessageSink(capturedOutput::add).execute();
assertTrue(capturedOutput.isEmpty());
}
Aggregations