Search in sources :

Example 1 with WireDumper

use of net.openhft.chronicle.wire.WireDumper 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 2 with WireDumper

use of net.openhft.chronicle.wire.WireDumper in project Chronicle-Queue by OpenHFT.

the class DumpQueueMain method dumpFile.

private static void dumpFile(@NotNull File file, @NotNull PrintStream out, long upperLimit) {
    if (file.getName().endsWith(SingleChronicleQueue.SUFFIX)) {
        Bytes<ByteBuffer> buffer = Bytes.elasticByteBuffer();
        try {
            MappedBytes bytes = MappedBytes.mappedBytes(file, 4 << 20, OS.pageSize(), !OS.isWindows());
            bytes.readLimit(bytes.realCapacity());
            StringBuilder sb = new StringBuilder();
            WireDumper dumper = WireDumper.of(bytes);
            while (bytes.readRemaining() >= 4) {
                sb.setLength(0);
                boolean last = dumper.dumpOne(sb, buffer);
                if (sb.indexOf("\nindex2index:") != -1 || sb.indexOf("\nindex:") != -1) {
                    // truncate trailing zeros
                    if (sb.indexOf(", 0\n]\n") == sb.length() - 6) {
                        int i = indexOfLastZero(sb);
                        if (i < sb.length())
                            sb.setLength(i - 5);
                        sb.append(" # truncated trailing zeros\n]");
                    }
                }
                out.println(sb);
                if (last)
                    break;
                if (bytes.readPosition() > upperLimit) {
                    out.println("# limit reached.");
                    return;
                }
            }
        } catch (IOException ioe) {
            err.println("Failed to read " + file + " " + ioe);
        } finally {
            buffer.release();
        }
    }
}
Also used : WireDumper(net.openhft.chronicle.wire.WireDumper) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) MappedBytes(net.openhft.chronicle.bytes.MappedBytes)

Aggregations

IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 MappedBytes (net.openhft.chronicle.bytes.MappedBytes)2 WireDumper (net.openhft.chronicle.wire.WireDumper)2 File (java.io.File)1 LocalDateTime (java.time.LocalDateTime)1 CommonStore (net.openhft.chronicle.queue.impl.CommonStore)1 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)1 DocumentContext (net.openhft.chronicle.wire.DocumentContext)1 Wire (net.openhft.chronicle.wire.Wire)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1