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