use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class NotCompleteTest method testUsingANotCompleteArrayQueue.
@Test
public void testUsingANotCompleteArrayQueue() throws InterruptedException {
BinaryLongArrayReference.startCollecting();
File tmpDir = DirectoryUtils.tempDir("testUsingANotCompleteArrayQueue");
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().rollCycle(RollCycles.TEST_DAILY).build()) {
ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().write("some").text("data");
}
Thread.sleep(100);
// System.out.println(queue.dump());
// this is what will corrupt the queue
BinaryLongArrayReference.forceAllToNotCompleteState();
}
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().timeoutMS(500).build()) {
// System.out.println(queue.dump());
ExcerptTailer tailer = queue.createTailer();
try (DocumentContext dc = tailer.readingDocument()) {
assertEquals("data", dc.wire().read(() -> "some").text());
}
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class NotCompleteTest method testSkipSafeLengthOverBlock.
@Ignore("store.writePosition() not set after we recover, but not trivial to fix. Problem only occurs rarely")
@Test
public void testSkipSafeLengthOverBlock() {
File tmpDir = DirectoryUtils.tempDir("testSkipSafeLengthOverBlock");
// 3rd time will do it
for (int i = 0; i < 8; i++) {
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().rollCycle(RollCycles.TEST_DAILY).timeoutMS(1).build()) {
ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
// start a message which won't be completed.
DocumentContext dc = appender.writingDocument();
// 2nd and subsequent times we call this will invoke recovery
dc.wire().write("some").text("data");
// don't call dc.close();
}
}
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().build()) {
ExcerptTailer tailer = queue.createTailer();
try (DocumentContext dc = tailer.readingDocument()) {
assertFalse(dc.isPresent());
}
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class NotCompleteTest method testUsingANotCompleteQueue.
/**
* tests that when flags are set to not complete we are able to recover
*/
@Test
public void testUsingANotCompleteQueue() throws InterruptedException {
BinaryLongReference.startCollecting();
File tmpDir = DirectoryUtils.tempDir("testUsingANotCompleteQueue");
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().rollCycle(RollCycles.TEST_DAILY).build()) {
ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().write("some").text("data");
}
Thread.sleep(100);
// System.out.println(queue.dump());
// this is what will corrupt the queue
BinaryLongReference.forceAllToNotCompleteState();
}
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().timeoutMS(500).build()) {
// System.out.println(queue.dump());
ExcerptTailer tailer = queue.createTailer();
try (DocumentContext dc = tailer.readingDocument()) {
assertEquals("data", dc.wire().read(() -> "some").text());
}
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class RollCycleMultiThreadTest method testRead2.
@Test
public void testRead2() throws Exception {
File path = DirectoryUtils.tempDir("testRead2");
TestTimeProvider timeProvider = new TestTimeProvider();
try (ChronicleQueue queue0 = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
final ParallelQueueObserver observer = new ParallelQueueObserver(queue0);
final ExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
ExcerptAppender appender = queue.acquireAppender();
try (final DocumentContext dc = appender.writingDocument()) {
dc.wire().write().text("Day 1 data");
}
Assert.assertEquals(1, (int) scheduledExecutorService.submit(observer).get());
// two days pass
timeProvider.add(TimeUnit.DAYS.toMillis(2));
try (final DocumentContext dc = appender.writingDocument()) {
dc.wire().write().text("Day 3 data");
}
Assert.assertEquals(2, (int) scheduledExecutorService.submit(observer).get());
System.out.println(queue.dump());
assertEquals(2, observer.documentsRead);
}
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class RollCycleMultiThreadTest method testRead1.
@Test
public void testRead1() throws Exception {
File path = DirectoryUtils.tempDir(getClass().getSimpleName());
TestTimeProvider timeProvider = new TestTimeProvider();
try (ChronicleQueue queue0 = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
ParallelQueueObserver observer = new ParallelQueueObserver(queue0);
final ExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
ExcerptAppender appender = queue.acquireAppender();
Assert.assertEquals(0, (int) scheduledExecutorService.submit(observer::call).get());
// two days pass
timeProvider.add(TimeUnit.DAYS.toMillis(2));
try (final DocumentContext dc = appender.writingDocument()) {
dc.wire().write().text("Day 3 data");
}
Assert.assertEquals(1, (int) scheduledExecutorService.submit(observer::call).get());
assertEquals(1, observer.documentsRead);
}
}
}
Aggregations