use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchAfterEndReverse.
@Test
public void findByBinarySearchAfterEndReverse() {
final File queueDir = getTmpDir();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
int max = 10, reps = 5;
populateQueueWithTimestamps(queue, max, reps);
// this should be after the end
long tsToLookFor = getTimestampAtIndex(11);
ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).inReverseOrder().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 findByBinarySearchReverse.
@Test
public void findByBinarySearchReverse() {
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()).inReverseOrder().withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
reader.execute();
assertEquals(reps * (i + 1), capturedOutput.size() / 2);
}
}
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchSparseRepeated.
@Test
public void findByBinarySearchSparseRepeated() {
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()).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 readOnlyQueueTailerShouldObserveChangesAfterInitiallyObservedReadLimit.
@Test(timeout = 5000)
public void readOnlyQueueTailerShouldObserveChangesAfterInitiallyObservedReadLimit() throws IOException, InterruptedException, TimeoutException, ExecutionException {
DirectoryUtils.deleteDir(dataDir.toFile());
dataDir.toFile().mkdirs();
try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary(dataDir).testBlockSize().build()) {
final Say events = queue.acquireAppender().methodWriterBuilder(Say.class).build();
events.say("hello");
final long readerCapacity = getCurrentQueueFileLength(dataDir);
final RecordCounter recordCounter = new RecordCounter();
final ChronicleReader chronicleReader = basicReader().withMessageSink(recordCounter);
final ExecutorService executorService = Executors.newSingleThreadExecutor(new NamedThreadFactory("executor"));
Future<?> submit = executorService.submit(chronicleReader::execute);
final long expectedReadingDocumentCount = (readerCapacity / ONE_KILOBYTE.length) + 1;
int i;
for (i = 0; i < expectedReadingDocumentCount; i++) {
events.say(new String(ONE_KILOBYTE));
}
recordCounter.latch.countDown();
executorService.shutdown();
executorService.awaitTermination(Jvm.isDebug() ? 50 : 5, TimeUnit.SECONDS);
submit.get(1, TimeUnit.SECONDS);
// #460 read only not supported on windows.
if (!OS.isWindows())
assertEquals(expectedReadingDocumentCount, recordCounter.recordCount.get() - 1);
}
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method shouldReadQueueWithNonDefaultRollCycleWhenMetadataDeleted.
@Test(timeout = 10_000L)
public void shouldReadQueueWithNonDefaultRollCycleWhenMetadataDeleted() throws IOException {
if (!OS.isWindows())
expectException("Failback to readonly tablestore");
Path path = getTmpDir().toPath();
path.toFile().mkdirs();
try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).rollCycle(RollCycles.MINUTELY).testBlockSize().sourceId(1).build()) {
final ExcerptAppender excerptAppender = queue.acquireAppender();
final VanillaMethodWriterBuilder<Say> methodWriterBuilder = excerptAppender.methodWriterBuilder(Say.class);
final Say events = methodWriterBuilder.build();
for (int i = 0; i < TOTAL_EXCERPTS_IN_QUEUE; i++) {
events.say(i % 2 == 0 ? "hello" : "goodbye");
}
}
Files.list(path).filter(f -> f.getFileName().toString().endsWith(SingleTableStore.SUFFIX)).findFirst().ifPresent(p -> p.toFile().delete());
waitForGcCycle();
new ChronicleReader().withBasePath(path).withMessageSink(capturedOutput::add).execute();
assertFalse(capturedOutput.isEmpty());
}
Aggregations