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);
}
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class QueueWireHandler method getQueue.
private ChronicleQueue getQueue(StringBuilder cspText) {
ChronicleQueue queue;
if (cid == 0) {
// cid hasn't been passed in need to map it from csp
cid = cspToCid.computeIfAbsent(cspText.toString(), s -> cidCounter.incrementAndGet());
String[] parts = cspText.toString().split("/");
String filename = "/tmp/" + parts[1] + "/" + parts[2] + ".q";
queue = fileNameToChronicle.computeIfAbsent(filename, s -> {
try {
return new ChronicleQueueBuilder(filename).build();
} catch (IOException e) {
e.printStackTrace();
}
return null;
});
cidToQueue.put(cid, queue);
} else {
// if the cid has been created then there must be a corresponding queue
queue = cidToQueue.get(cid);
assert queue != null;
}
return queue;
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testLastWrittenIndexPerAppender.
@Test
public void testLastWrittenIndexPerAppender() {
final File file = createTempFile("testLastWrittenIndexPerAppender");
try {
final ChronicleQueue chronicle = createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
appender.writeDocument(wire -> wire.write(() -> "key").text("test"));
Assert.assertEquals(0, appender.lastWrittenIndex());
} finally {
file.delete();
}
}
Aggregations