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);
}
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();
}
}
}
Aggregations