@NotNull public static String dump(@NotNull String directoryFilePath) { return ChronicleQueue.singleBuilder(directoryFilePath).build().dump(); }
@NotNull private static ChronicleQueue createQueue(String path) { return ChronicleQueue.singleBuilder(path) .blockSize(1 << 30) .pauserSupplier(Pauser::timedBusy) .build(); }
private SingleChronicleQueue createQueue() { return ChronicleQueue.singleBuilder( DirectoryUtils.tempDir(TailerPollingEmptyQueueTest.class.getName())). testBlockSize(). build(); } }
public EventLoopServiceWrapper(@NotNull ServiceWrapperBuilder<O> builder) { this.priority = builder.priority(); outputQueue = ChronicleQueue.singleBuilder(builder.outputPath()) .sourceId(builder.outputSourceId()) .checkInterrupts(false) .build(); serviceOut = outputQueue.acquireAppender() .methodWriterBuilder(builder.outClass()) .recordHistory(builder.outputSourceId() != 0) .get(); serviceImpl = builder.getServiceFunctions().stream() .map(f -> f.apply(serviceOut)) .toArray(); List<String> paths = builder.inputPath(); serviceIn = new MethodReader[paths.size()]; inputQueues = new ChronicleQueue[paths.size()]; for (int i = 0; i < paths.size(); i++) { inputQueues[i] = ChronicleQueue.singleBuilder(paths.get(i)) .sourceId(builder.inputSourceId()) .build(); serviceIn[i] = inputQueues[i].createTailer() .afterLastWritten(outputQueue) .methodReader(serviceImpl); } eventLoop = builder.eventLoop(); eventLoop.addHandler(this); createdEventLoop = builder.createdEventLoop(); if (createdEventLoop) eventLoop.start(); }
@Test public void threadingTest() throws Exception { System.out.println("Continue appending"); ExecutorService execService = Executors.newFixedThreadPool(2); SynchronousQueue<Long> sync = new SynchronousQueue<>(); long t_index; MyAppender myapp = new MyAppender(sync); Future<Long> f = execService.submit(myapp); ChronicleQueue tailer_queue = ChronicleQueue.singleBuilder(path) .testBlockSize() .buffered(false) .build(); t_index = 0; MyTailer mytailer = new MyTailer(tailer_queue, t_index, sync); Future<Long> f2 = execService.submit(mytailer); t_index = f2.get(10, TimeUnit.SECONDS); a_index = f.get(10, TimeUnit.SECONDS); assertTrue(a_index == t_index); }
@Test public void shouldDetermineQueueDirectoryFromQueueFile() { final Path path = Paths.get(OS.USER_DIR, TEST_QUEUE_FILE); try (final ChronicleQueue queue = ChronicleQueue.singleBuilder(path) .testBlockSize() .build()) { assertThat(queue.createTailer().readingDocument().isPresent(), is(false)); } finally { IOTools.deleteDirWithFiles(path.toFile(), 20); } }
private SingleChronicleQueueBuilder builder(final File dir, final long timeoutMS) { return ChronicleQueue.singleBuilder(dir). testBlockSize().rollCycle(ROLL_CYCLE). timeProvider(clock::get).timeoutMS(timeoutMS); }
private ChronicleQueue createQueue(final File queueDir, final int sourceId) { return ChronicleQueue.singleBuilder(queueDir).sourceId(sourceId). timeProvider(clock::get). testBlockSize().build(); }
@Test public void testDtoAbstractMarshallable() { File tmp = DirectoryUtils.tempDir("abstractBytesMarshalTest"); DtoAbstractMarshallable dto = new DtoAbstractMarshallable(); dto.age = 45; dto.name.append("rob"); try (ChronicleQueue q = ChronicleQueue.singleBuilder(tmp).build()) { try (DocumentContext dc = q.acquireAppender().writingDocument()) { dc.wire().write("who").object(dto); } try (DocumentContext dc = q.createTailer().readingDocument()) { String yaml = dc.toString(); System.out.println(yaml); DtoAbstractMarshallable who = (DtoAbstractMarshallable) dc.wire().read("who").object(); System.out.println(who); Assert.assertTrue(yaml.contains(who.toString())); } } }
private void runTest(final ThrowingConsumer<RollingChronicleQueue, Exception> testMethod) throws Exception { try (final RollingChronicleQueue queue = ChronicleQueue.singleBuilder(tmpDir.newFolder()). testBlockSize().timeProvider(clock::get). rollCycle(ROLL_CYCLE).indexSpacing(INDEX_SPACING). build()) { testMethod.accept(queue); } } }
@Before public void before() { path = OS.TARGET + "/" + getClass().getSimpleName() + "-" + System.nanoTime(); try (ChronicleQueue appender_queue = ChronicleQueue.singleBuilder(path) .testBlockSize() .buffered(false) .build()) { ExcerptAppender appender = appender_queue.acquireAppender(); for (int i = 0; i < messages; i++) { final long l = i; appender.writeDocument(wireOut -> wireOut.write("log").marshallable(m -> { m.write("msg").text("hello world ola multi-verse"); m.write("ts").int64(l); } )); } a_index = appender.lastIndexAppended(); } }
@Before public void setup() { chroniclePath = new File(OS.TARGET, "read_only"); try (ChronicleQueue readWrite = ChronicleQueue.singleBuilder(chroniclePath) .readOnly(false) .testBlockSize() .build()) { final ExcerptAppender appender = readWrite.acquireAppender(); appender.writeText(STR1); try (DocumentContext dc = appender.writingDocument()) { dc.wire().bytes().writeUtf8(STR2); } } }
@Test public void shouldIndicateNoProcessIdWhenDocumentIsComplete() throws IOException { try (final RollingChronicleQueue queue = ChronicleQueue.singleBuilder(getTmpDir()). testBlockSize(). build()) { final QueueInspector inspector = new QueueInspector(queue); final ExcerptAppender appender = queue.acquireAppender(); appender.writeDocument(37L, ValueOut::int64); try (final DocumentContext ctx = appender.writingDocument()) { ctx.wire().write("foo").int32(17L); } final int writingThreadId = inspector.getWritingThreadId(); assertThat(writingThreadId, is(not(OS.getProcessId()))); assertThat(QueueInspector.isValidThreadId(writingThreadId), is(false)); } }
@Test public void test() { File file = getTmpDir(); try (ChronicleQueue queue = ChronicleQueue.singleBuilder(file) .testBlockSize() .rollCycle(TEST_DAILY).build()) { SomeListener someListener = queue.acquireAppender().methodWriter(SomeListener.class); SomeManager someManager = new SomeManager(); MethodReader reader = queue.createTailer().methodReader(someManager); LOG.debug("Writing to queue"); someListener.methodWithOneParam(1); someListener.methodWithoutParams(); LOG.debug("Reading from queue"); assertTrue(reader.readOne()); assertTrue(reader.readOne()); assertFalse(reader.readOne()); assertTrue(someManager.methodWithOneParamInvoked); // one param method was invoked assertTrue(someManager.methodWithoutParamsInvoked); // no params method was NOT invoked LOG.warn(queue.dump()); } }
@Test(expected = TimeoutException.class) public void shouldHandleEmptyFile() { Assume.assumeFalse(OS.isWindows()); try (final ChronicleQueue queue = ChronicleQueue.singleBuilder(tmpDir) .testBlockSize() .timeoutMS(100) .readOnly(true) .build()) { ExcerptTailer tailer = queue.createTailer(); assertFalse(tailer.readingDocument().isPresent()); } } }
@Test public void testDtoBytesMarshallable() { File tmp = DirectoryUtils.tempDir("abstractBytesMarshalTest"); DtoBytesMarshallable dto = new DtoBytesMarshallable(); dto.age = 45; dto.name.append("rob"); try (ChronicleQueue q = ChronicleQueue.singleBuilder(tmp).build()) { try (DocumentContext dc = q.acquireAppender().writingDocument()) { dc.wire().write("who").object(dto); } try (DocumentContext dc = q.createTailer().readingDocument()) { DtoBytesMarshallable who = (DtoBytesMarshallable) dc.wire().read("who").object(); Assert.assertEquals("!net.openhft.chronicle.queue.DtoBytesMarshallableTest$DtoBytesMarshallable {\n" + " name: rob,\n" + " age: 45\n" + "}\n", who.toString()); } } }
@Test public void appendAndTail() { ChronicleQueue tailer_queue = ChronicleQueue.singleBuilder(path) .testBlockSize() .buffered(false) .build(); ExcerptTailer tailer = tailer_queue.createTailer(); tailer = tailer.toStart(); long t_index; t_index = doReadBad(tailer, messages, false); assertEquals(a_index, t_index); tailer = tailer_queue.createTailer(); tailer = tailer.toStart(); t_index = doReadBad(tailer, messages, true); assertEquals(a_index, t_index); }
@Test public void testTail() { File basePath = getTmpDir(); try (ChronicleQueue queue = ChronicleQueue.singleBuilder(basePath) .testBlockSize() .build()) { checkNoFiles(basePath); ExcerptTailer tailer = queue.createTailer(); checkNoFiles(basePath); tailer.toStart(); checkNoFiles(basePath); assertFalse(tailer.readDocument(d -> { })); checkNoFiles(basePath); } }
@Test public void shouldDetermineWritingProcessIdWhenDocumentIsNotComplete() throws IOException { try (final RollingChronicleQueue queue = ChronicleQueue.singleBuilder(getTmpDir()). testBlockSize(). build()) { final QueueInspector inspector = new QueueInspector(queue); final ExcerptAppender appender = queue.acquireAppender(); appender.writeDocument(37L, ValueOut::int64); try (final DocumentContext ctx = appender.writingDocument()) { ctx.wire().write("foo").int32(17L); final int writingThreadId = inspector.getWritingThreadId(); // commentedVanillaMsgSequenceHandler out as fails on Mac OS // assertThat(writingThreadId, is(Affinity.getThreadId())); // we no longer write header before the document is closed // assertThat(QueueInspector.isValidThreadId(writingThreadId), is(true)); } } }
@Test public void shouldMoveToPreviousIndexAfterDocumentIsConsumed() throws Exception { File queuePath = tmpFolder.newFolder("cq"); try (ChronicleQueue queue = ChronicleQueue.singleBuilder(queuePath).build()) { ExcerptAppender appender = queue.acquireAppender(); for (int i = 1; i < 10; ++i) { appender.writeText("id" + i); } ExcerptTailer tailer = queue.createTailer(); assertNext(tailer, "id1"); long index = tailer.index(); assertNext(tailer, "id2"); tailer.moveToIndex(index); assertNext(tailer, "id2"); tailer.moveToIndex(index); assertNext(tailer, "id2"); } }