Search in sources :

Example 26 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class TestEmptyFile method shouldHandleEmptyFile.

@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());
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 27 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class TestTailAfterRoll method doTest.

public void doTest() {
    File tmpDir = getTmpDir();
    File[] files;
    try (ChronicleQueue writeQ = ChronicleQueue.singleBuilder(tmpDir).build()) {
        ExcerptAppender appender = writeQ.acquireAppender();
        long wp;
        Wire wire;
        try (DocumentContext dc = appender.writingDocument()) {
            wire = dc.wire();
            wire.write().text("hello world");
            Bytes<?> bytes = wire.bytes();
            wp = bytes.writePosition();
        }
        File dir = new File(appender.queue().fileAbsolutePath());
        files = dir.listFiles(pathname -> pathname.getAbsolutePath().endsWith(".cq4"));
        wire.bytes().writeInt(wp, Wires.END_OF_DATA);
        appender.writeText("hello world  2");
    }
    Assert.assertEquals(1, files.length);
    File file = files[0];
    file.delete();
    try (ChronicleQueue q = ChronicleQueue.singleBuilder(tmpDir).build()) {
        ExcerptTailer excerptTailer = q.createTailer().toEnd();
        q.acquireAppender().writeText(EXPECTED);
        Assert.assertEquals(EXPECTED, excerptTailer.readText());
    }
}
Also used : ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) DocumentContext(net.openhft.chronicle.wire.DocumentContext) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Test(org.junit.Test) FlakyTestRunner(net.openhft.chronicle.core.FlakyTestRunner) Wire(net.openhft.chronicle.wire.Wire) File(java.io.File) Bytes(net.openhft.chronicle.bytes.Bytes) ChronicleQueueTestBase(net.openhft.chronicle.queue.ChronicleQueueTestBase) OS(net.openhft.chronicle.core.OS) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) Assert(org.junit.Assert) Wires(net.openhft.chronicle.wire.Wires) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) Wire(net.openhft.chronicle.wire.Wire) DocumentContext(net.openhft.chronicle.wire.DocumentContext) File(java.io.File) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer)

Example 28 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleMethodReaderTest method before.

@Before
public void before() {
    dataDir = getTmpDir().toPath();
    try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary(dataDir).sourceId(1).testBlockSize().build()) {
        final ExcerptAppender excerptAppender = queue.acquireAppender();
        final VanillaMethodWriterBuilder<All> methodWriterBuilder = excerptAppender.methodWriterBuilder(All.class);
        final All events = methodWriterBuilder.useMethodIds(useMethodIds).build();
        for (int i = 0; i < 24; ) {
            Method1Type m1 = new Method1Type();
            m1.text = "hello";
            m1.value = i;
            m1.number = i;
            events.method1(m1);
            i++;
            Method2Type m2 = new Method2Type();
            m2.text = "goodbye";
            m2.value = i;
            m2.number = i;
            events.method2(m2);
            i++;
        }
    }
    ignoreException("Overriding sourceId from existing metadata, was 0, overriding to");
}
Also used : SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) Before(org.junit.Before)

Example 29 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleWriterTest method testBytesMarshallingWithInterface.

@Test(timeout = 5000)
public void testBytesMarshallingWithInterface() throws IOException {
    ChronicleWriter chronicleWriter = chronicleWriter(MyInterface2.class.getTypeName(), cw3);
    chronicleWriter.execute();
    try (ChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build()) {
        StringBuilder sb = new StringBuilder();
        @NotNull MethodReader mr = queue.createTailer().methodReader(Mocker.intercepting(MyInterface2.class, "*", sb::append));
        Assert.assertTrue(mr.readOne());
        Assert.assertFalse(mr.readOne());
        Assert.assertEquals("*doit[!net.openhft.chronicle.queue.internal.writer.ChronicleWriterTest$DTO2 {\n" + "  age: 42,\n" + "  name: Percy\n" + "}\n" + "]", sb.toString());
    } finally {
        IOTools.deleteDirWithFiles(dir);
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) NotNull(org.jetbrains.annotations.NotNull) MethodReader(net.openhft.chronicle.bytes.MethodReader) Test(org.junit.Test)

Example 30 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleWriterTest method testWireMarshallingWithInterface.

@Test(timeout = 5000)
public void testWireMarshallingWithInterface() throws IOException {
    ChronicleWriter chronicleWriter = chronicleWriter(MyInterface.class.getTypeName(), cw2);
    chronicleWriter.execute();
    try (ChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build()) {
        StringBuilder sb = new StringBuilder();
        @NotNull MethodReader mr = queue.createTailer().methodReader(Mocker.intercepting(MyInterface.class, "*", sb::append));
        Assert.assertTrue(mr.readOne());
        Assert.assertFalse(mr.readOne());
        Assert.assertEquals("*doit[!net.openhft.chronicle.queue.internal.writer.ChronicleWriterTest$DTO {\n" + "  age: 42,\n" + "  name: Percy\n" + "}\n" + "]", sb.toString());
    } finally {
        IOTools.deleteDirWithFiles(dir);
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) NotNull(org.jetbrains.annotations.NotNull) MethodReader(net.openhft.chronicle.bytes.MethodReader) Test(org.junit.Test)

Aggregations

ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)80 Test (org.junit.Test)59 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)37 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)37 File (java.io.File)36 DocumentContext (net.openhft.chronicle.wire.DocumentContext)21 ArrayList (java.util.ArrayList)16 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)14 MethodReader (net.openhft.chronicle.bytes.MethodReader)12 List (java.util.List)11 IOException (java.io.IOException)9 MappedFile (net.openhft.chronicle.bytes.MappedFile)8 Path (java.nio.file.Path)7 Bytes (net.openhft.chronicle.bytes.Bytes)7 Collections (java.util.Collections)6 RollCycles (net.openhft.chronicle.queue.RollCycles)6 NotNull (org.jetbrains.annotations.NotNull)6 ByteBuffer (java.nio.ByteBuffer)5 MappedBytes (net.openhft.chronicle.bytes.MappedBytes)5 Histogram (net.openhft.chronicle.core.util.Histogram)5