use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchWithDeletedRollCyles.
@Test
public void findByBinarySearchWithDeletedRollCyles() {
final File queueDir = getTmpDir();
final SetTimeProvider timeProvider = new SetTimeProvider();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).timeProvider(timeProvider).rollCycle(RollCycles.TEST_SECONDLY).build()) {
for (int i = 0; i < 5; i++) {
int entries = 10, reps = 5;
populateQueueWithTimestamps(queue, entries, reps, i);
timeProvider.advanceMillis(3_000);
}
}
// Just make sure Windows has closed all the files before we try to delete
BackgroundResourceReleaser.releasePendingResources();
// delete the 4th roll cycle
assertTrue("Couldn't delete cycle, test is broken", queueDir.toPath().resolve("19700101-000009T.cq4").toFile().delete());
// this should be before the start
// third index in 3rd roll cycle, should be ({reps=5} * 8) + ({remaining_cycles=1} * ({reps=5} * {entries=10})) = 90 in output
long tsToLookFor = getTimestampAtIndex(22);
System.out.println(tsToLookFor);
ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
reader.execute();
assertEquals(90 * 2, capturedOutput.size());
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchSparseApprox.
@Test
public void findByBinarySearchSparseApprox() {
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()).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 findByBinarySearch.
@Test
public void findByBinarySearch() {
final File queueDir = getTmpDir();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
int max = 10, reps = 5;
populateQueueWithTimestamps(queue, max, reps);
for (int i = 0; i < max; i++) {
capturedOutput.clear();
long tsToLookFor = getTimestampAtIndex(i);
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 findByBinarySearchBeforeStart.
@Test
public void findByBinarySearchBeforeStart() {
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()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
reader.execute();
assertEquals(max * reps, capturedOutput.size() / 2);
}
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method reverseOrderShouldIgnoreOptionsThatDontMakeSense.
@Test
public void reverseOrderShouldIgnoreOptionsThatDontMakeSense() {
addCountToEndOfQueue();
new ChronicleReader().withBasePath(dataDir).withMessageSink(capturedOutput::add).inReverseOrder().suppressDisplayIndex().tail().historyRecords(// Ignored
10).execute();
final List<String> firstFourElements = capturedOutput.stream().limit(4).collect(Collectors.toList());
assertEquals(Arrays.asList("\"4\"\n", "\"3\"\n", "\"2\"\n", "\"1\"\n"), firstFourElements);
}
Aggregations