Search in sources :

Example 11 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class DumpQueueMainTest method shouldDumpDirectoryListing.

@Test
public void shouldDumpDirectoryListing() throws Exception {
    final File dataDir = DirectoryUtils.tempDir(DumpQueueMainTest.class.getSimpleName());
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(dataDir).build()) {
        final ExcerptAppender excerptAppender = queue.acquireAppender();
        excerptAppender.writeText("first");
        excerptAppender.writeText("last");
        final ByteArrayOutputStream capture = new ByteArrayOutputStream();
        DumpQueueMain.dump(dataDir, new PrintStream(capture), Long.MAX_VALUE);
        final String capturedOutput = new String(capture.toByteArray());
        assertThat(capturedOutput, containsString("listing.highestCycle"));
        assertThat(capturedOutput, containsString("listing.lowestCycle"));
        assertThat(capturedOutput, containsString("listing.exclusiveLock"));
    }
}
Also used : PrintStream(java.io.PrintStream) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 12 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class FsFullReadTest method testFullReadFs.

@Ignore("broken test")
@Test
public void testFullReadFs() throws Exception {
    SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(basePath).blockSize(256 << 1000).rollCycle(RollCycles.DAILY).build();
    ExcerptTailer tailer = queue.createTailer();
    DocumentContext dc = tailer.readingDocument();
    boolean doExit = false;
    int entries = 0;
    while (!doExit) {
        try {
            if (dc.isPresent()) {
                entries++;
                Wire w = dc.wire();
                LocalDateTime dt = w.read().dateTime();
                assertNotNull(dt);
                byte[] b = w.read().bytes();
                assertEquals(1024, b.length);
            } else {
                System.out.println("Exiting");
                doExit = true;
            }
        } finally {
            dc.close();
        }
    }
    System.out.println(String.format("Read %d entries.", entries));
    CommonStore commonStore = queue.storeForCycle(queue.cycle(), 0, false);
    File file = commonStore.file();
    queue.close();
    int dumpEntries = 0;
    try {
        MappedBytes bytes = MappedBytes.mappedBytes(file, 4 << 20);
        bytes.readLimit(bytes.realCapacity());
        WireDumper dumper = WireDumper.of(bytes);
        Bytes<ByteBuffer> buffer = Bytes.elasticByteBuffer();
        while (bytes.readRemaining() >= 4) {
            StringBuilder sb = new StringBuilder();
            boolean last = dumper.dumpOne(sb, buffer);
            assertTrue(sb.length() > 0);
            if (last)
                break;
            dumpEntries++;
        }
    } catch (IOException ioe) {
        err.println("Failed to read " + file + " " + ioe);
    }
    assertEquals(dumpEntries, entries);
}
Also used : LocalDateTime(java.time.LocalDateTime) WireDumper(net.openhft.chronicle.wire.WireDumper) IOException(java.io.IOException) Wire(net.openhft.chronicle.wire.Wire) ByteBuffer(java.nio.ByteBuffer) CommonStore(net.openhft.chronicle.queue.impl.CommonStore) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) DocumentContext(net.openhft.chronicle.wire.DocumentContext) File(java.io.File) MappedBytes(net.openhft.chronicle.bytes.MappedBytes) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class OvertakeTest method appendAndTail.

@Test
public void appendAndTail() {
    SingleChronicleQueue tailer_queue = SingleChronicleQueueBuilder.binary(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);
}
Also used : SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) Test(org.junit.Test)

Example 14 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class OvertakeTest method before.

@Before
public void before() throws Exception {
    path = OS.TARGET + "/" + getClass().getSimpleName() + "-" + System.nanoTime();
    try (SingleChronicleQueue appender_queue = SingleChronicleQueueBuilder.binary(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();
    }
}
Also used : SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Ignore(org.junit.Ignore) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) IOTools(net.openhft.chronicle.core.io.IOTools) java.util.concurrent(java.util.concurrent) After(org.junit.After) Test(org.junit.Test) OS(net.openhft.chronicle.core.OS) NotNull(org.jetbrains.annotations.NotNull) Assert(org.junit.Assert) Before(org.junit.Before) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) Before(org.junit.Before)

Example 15 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ReadWriteTest method testReadFromReadOnlyChronicle.

@Test
public void testReadFromReadOnlyChronicle() {
    try (SingleChronicleQueue out = SingleChronicleQueueBuilder.binary(chroniclePath).testBlockSize().readOnly(!OS.isWindows()).build()) {
        // check dump
        assertTrue(out.dump().length() > 1);
        // and tailer
        ExcerptTailer tailer = out.createTailer();
        assertEquals(STR1, tailer.readText());
        try (DocumentContext dc = tailer.readingDocument()) {
            assertEquals(STR2, dc.wire().bytes().readUtf8());
        // even though this is read-only we can still call dc.wire().bytes().write... which causes java.lang.InternalError
        // Fixing this in a type-safe manner would require on Read/WriteDocumentContext to return WireIn/WireOut
        }
    }
}
Also used : SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Test(org.junit.Test)

Aggregations

SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)36 Test (org.junit.Test)24 File (java.io.File)13 MethodReader (net.openhft.chronicle.bytes.MethodReader)10 DocumentContext (net.openhft.chronicle.wire.DocumentContext)10 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)7 Ignore (org.junit.Ignore)6 OS (net.openhft.chronicle.core.OS)4 IOTools (net.openhft.chronicle.core.io.IOTools)4 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)4 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)4 Path (java.nio.file.Path)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 NotNull (org.jetbrains.annotations.NotNull)3 Assert (org.junit.Assert)3 Before (org.junit.Before)3 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2