use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class TestDeleteQueueFile method tailerToEndFromEndWorksInFaceOfDeletedStoreFile.
@Test
public void tailerToEndFromEndWorksInFaceOfDeletedStoreFile() throws IOException {
assumeFalse(OS.isWindows());
try (QueueWithCycleDetails queueWithCycleDetails = createQueueWithNRollCycles(3, null)) {
final SingleChronicleQueue queue = queueWithCycleDetails.queue;
RollCycleDetails firstCycle = queueWithCycleDetails.rollCycles.get(0);
RollCycleDetails secondCycle = queueWithCycleDetails.rollCycles.get(1);
RollCycleDetails thirdCycle = queueWithCycleDetails.rollCycles.get(2);
ExcerptTailer tailer = queue.createTailer();
// while the queue is intact
assertEquals(Long.toHexString(firstCycle.firstIndex), Long.toHexString(tailer.toStart().index()));
assertEquals(Long.toHexString(thirdCycle.lastIndex + 1), Long.toHexString(tailer.toEnd().index()));
// delete the last store
Files.delete(Paths.get(thirdCycle.filename));
// should be at correct index
assertEquals(Long.toHexString(secondCycle.lastIndex + 1), Long.toHexString(tailer.toEnd().index()));
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class TestDeleteQueueFile method tailerToStartFromStartWorksInFaceOfDeletedStoreFile.
@Ignore("still doesn't work")
@Test
public void tailerToStartFromStartWorksInFaceOfDeletedStoreFile() throws IOException {
assumeFalse(OS.isWindows());
try (QueueWithCycleDetails queueWithCycleDetails = createQueueWithNRollCycles(3, null)) {
final SingleChronicleQueue queue = queueWithCycleDetails.queue;
RollCycleDetails firstCycle = queueWithCycleDetails.rollCycles.get(0);
RollCycleDetails secondCycle = queueWithCycleDetails.rollCycles.get(1);
RollCycleDetails thirdCycle = queueWithCycleDetails.rollCycles.get(2);
ExcerptTailer tailer = queue.createTailer();
// while the queue is intact
assertEquals(Long.toHexString(thirdCycle.lastIndex + 1), Long.toHexString(tailer.toEnd().index()));
assertEquals(Long.toHexString(firstCycle.firstIndex), Long.toHexString(tailer.toStart().index()));
// delete the first store
Files.delete(Paths.get(firstCycle.filename));
// should be at correct index
assertEquals(Long.toHexString(secondCycle.firstIndex), Long.toHexString(tailer.toStart().index()));
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue 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.impl.single.SingleChronicleQueue 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.impl.single.SingleChronicleQueue 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);
}
}
}
Aggregations