use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class TestWriteWhenCurrentCycleGotEOF method createQueueWithOnlyHeaderFile.
private void createQueueWithOnlyHeaderFile(File dir) {
SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(dir).testBlockSize().build();
queue.storeForCycle(queue.cycle(), queue.epoch(), true);
ExcerptTailer tailer = queue.acquireTailer();
try (DocumentContext dc = tailer.readingDocument()) {
assertFalse(dc.isPresent());
}
Wire wire;
ExcerptAppender excerptAppender = queue.acquireAppender();
try (DocumentContext dc = excerptAppender.writingDocument()) {
wire = dc.wire();
}
// overwrite last record with EOF
Bytes<?> bytes = wire.bytes();
bytes.writeVolatileInt(bytes.writePosition() - 5, Wires.END_OF_DATA);
bytes.writeVolatileInt(bytes.writePosition() - 1, 0);
}
use of net.openhft.chronicle.wire.DocumentContext 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.DocumentContext in project Chronicle-Queue by OpenHFT.
the class FsFullWriteTest method testAppenderFullFs.
@Ignore("flaky test")
@Test
public void testAppenderFullFs() throws Exception {
ChronicleQueue queue = SingleChronicleQueueBuilder.binary(basePath).blockSize(256 << 1000).rollCycle(RollCycles.DAILY).build();
ExcerptAppender appender = queue.acquireAppender();
byte[] payload = new byte[1024];
Random r = new Random();
r.nextBytes(payload);
final LocalDateTime now = LocalDateTime.now(Clock.systemUTC());
for (int i = 0; i < 1024 * 200; i++) {
DocumentContext dc = appender.writingDocument();
try {
Wire w = dc.wire();
w.write().dateTime(now);
w.write().bytes(payload);
} finally {
dc.close();
}
}
}
use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class DocumentOrderingTest method attemptToWriteDocument.
private Future<RecordInfo> attemptToWriteDocument(final SingleChronicleQueue queue) throws InterruptedException {
final CountDownLatch startedLatch = new CountDownLatch(1);
final Future<RecordInfo> future = executorService.submit(() -> {
final int counterValue;
startedLatch.countDown();
try (final DocumentContext documentContext = queue.acquireAppender().writingDocument()) {
counterValue = counter.getAndIncrement();
documentContext.wire().getValueOut().int32(counterValue);
}
return new RecordInfo(counterValue);
});
assertTrue("Task did not start", startedLatch.await(1, TimeUnit.MINUTES));
return future;
}
use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class NotCompleteTest method testUsingANotCompleteArrayQueue.
@Test
public void testUsingANotCompleteArrayQueue() throws InterruptedException {
BinaryLongArrayReference.startCollecting();
File tmpDir = DirectoryUtils.tempDir("testUsingANotCompleteArrayQueue");
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().rollCycle(RollCycles.TEST_DAILY).build()) {
ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().write("some").text("data");
}
Thread.sleep(100);
// System.out.println(queue.dump());
// this is what will corrupt the queue
BinaryLongArrayReference.forceAllToNotCompleteState();
}
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().timeoutMS(500).build()) {
// System.out.println(queue.dump());
ExcerptTailer tailer = queue.createTailer();
try (DocumentContext dc = tailer.readingDocument()) {
assertEquals("data", dc.wire().read(() -> "some").text());
}
}
}
Aggregations