use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchApproxReverse.
@Test
public void findByBinarySearchApproxReverse() {
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()).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 RollEOFTest method testRollWithoutEOFDoesntBlowup.
@Test(timeout = 5000L)
public void testRollWithoutEOFDoesntBlowup() throws IOException {
assumeFalse("Read-only mode is not supported on Windows", OS.isWindows());
// expectException("Overriding roll length from existing metadata");
// expectException("Overriding roll cycle from");
final File path = getTmpDir();
try {
path.mkdirs();
final SetTimeProvider timeProvider = new SetTimeProvider();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, -1);
timeProvider.currentTimeMillis(cal.getTimeInMillis());
createQueueAndWriteData(timeProvider, path);
assertEquals(1, getNumberOfQueueFiles(path));
// adjust time
timeProvider.currentTimeMillis(System.currentTimeMillis());
createQueueAndWriteData(timeProvider, path);
assertEquals(2, getNumberOfQueueFiles(path));
Optional<Path> firstQueueFile = Files.list(path.toPath()).filter(p -> p.toString().endsWith(SUFFIX)).sorted().findFirst();
assertTrue(firstQueueFile.isPresent());
// remove EOF from first file
removeEOF(firstQueueFile.get());
List<String> l = new LinkedList<>();
new ChronicleReader().withMessageSink(l::add).withBasePath(path.toPath()).execute();
// 2 entries per message
assertEquals(4, l.size());
} finally {
IOTools.deleteDirWithFiles(path, 20);
}
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class RollEOFTest method testRollWritesEOF.
@Test(timeout = 5000L)
public void testRollWritesEOF() throws IOException {
assumeFalse("Read-only mode is not supported on Windows", OS.isWindows());
// expectException("Overriding roll length from existing metadata");
// expectException("Overriding roll cycle from");
final File path = getTmpDir();
try {
path.mkdirs();
final SetTimeProvider timeProvider = new SetTimeProvider();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, -1);
timeProvider.currentTimeMillis(cal.getTimeInMillis());
createQueueAndWriteData(timeProvider, path);
assertEquals(1, getNumberOfQueueFiles(path));
// adjust time
timeProvider.currentTimeMillis(System.currentTimeMillis());
createQueueAndWriteData(timeProvider, path);
assertEquals(2, getNumberOfQueueFiles(path));
List<String> l = new LinkedList<>();
new ChronicleReader().withMessageSink(l::add).withBasePath(path.toPath()).execute();
// 2 entries per message
assertEquals(4, l.size());
} finally {
IOTools.deleteDirWithFiles(path, 20);
}
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderMain method run.
protected void run(@NotNull String[] args) {
final Options options = options();
final CommandLine commandLine = parseCommandLine(args, options);
final ChronicleReader chronicleReader = chronicleReader();
configureReader(chronicleReader, commandLine);
chronicleReader.execute();
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method shouldReadQueueWithNonDefaultRollCycle.
@Test(timeout = 10_000L)
public void shouldReadQueueWithNonDefaultRollCycle() {
expectException("Overriding roll length from existing metadata");
// expectException("Overriding roll cycle from");
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");
}
}
new ChronicleReader().withBasePath(path).withMessageSink(capturedOutput::add).execute();
assertFalse(capturedOutput.isEmpty());
}
Aggregations