use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method assertTimesAreInZone.
private void assertTimesAreInZone(File queueDir, ZoneId zoneId, List<Long> timestamps) {
ChronicleReader reader = new ChronicleReader().asMethodReader(SayWhen.class.getName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
reader.execute();
MicroTimestampLongConverter mtlc = new MicroTimestampLongConverter(zoneId.toString());
int i = 0;
while (!capturedOutput.isEmpty()) {
final String actualValue = capturedOutput.poll();
if (actualValue.contains("sayWhen")) {
final String expectedTimestamp = mtlc.asString(timestamps.get(i++));
assertTrue(String.format("%s contains %s", actualValue, expectedTimestamp), actualValue.contains(expectedTimestamp));
}
}
assertEquals("Didn't check all the timestamps", timestamps.size(), i);
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method findByBinarySearchAfterEnd.
@Test
public void findByBinarySearchAfterEnd() {
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()).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 shouldReadQueueInReverse.
@Test(timeout = 10_000L)
public void shouldReadQueueInReverse() {
addCountToEndOfQueue();
new ChronicleReader().withBasePath(dataDir).withMessageSink(capturedOutput::add).inReverseOrder().suppressDisplayIndex().execute();
final List<String> firstFourElements = capturedOutput.stream().limit(4).collect(Collectors.toList());
assertEquals(Arrays.asList("\"4\"\n", "\"3\"\n", "\"2\"\n", "\"1\"\n"), firstFourElements);
}
use of net.openhft.chronicle.queue.reader.ChronicleReader in project Chronicle-Queue by OpenHFT.
the class RollEOFTest method testRollWithoutEOF.
@Test(timeout = 5000L)
public void testRollWithoutEOF() throws IOException {
// 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, -3);
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()).withReadOnly(false).execute();
// 2 entries per message
assertEquals(4, l.size());
} finally {
IOTools.deleteDirWithFiles(path, 20);
}
}
Aggregations