use of net.openhft.chronicle.wire.Wire 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.Wire 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.Wire 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.Wire in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testScanFromLastKnownIndex.
@Test
public void testScanFromLastKnownIndex() {
final File file = createTempFile("testScanFromLastKnownIndex");
try {
final SingleChronicleQueue chronicle = (SingleChronicleQueue) createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
// create 100 documents
for (int i = 0; i < 65; i++) {
final int j = i;
appender.writeDocument(wire -> wire.write("key").text("value=" + j));
}
// creates the indexes - index's 1 and 2 are created by the indexer
new Indexer(chronicle).index();
// create 100 documents
for (long i = chronicle.lastIndex() + 1; i < 200; i++) {
final long j = i;
appender.writeDocument(wire -> wire.write("key").text("value=" + j));
}
final ExcerptTailer tailer = chronicle.createTailer();
{
int expected = 150;
tailer.index(expected);
StringBuilder sb = new StringBuilder();
tailer.readDocument(wire -> wire.read("key").text(sb));
Assert.assertEquals("value=" + expected, sb.toString());
}
// read back earlier
{
int expected = 167;
tailer.index(expected);
StringBuilder sb = new StringBuilder();
tailer.readDocument(wire -> wire.read("key").text(sb));
Assert.assertEquals("value=" + expected, sb.toString());
}
} finally {
file.delete();
}
}
use of net.openhft.chronicle.wire.Wire in project Chronicle-Queue by OpenHFT.
the class StagedPerformanceMain method applyFlyweight.
private static void applyFlyweight(IFacadeAll datum, long datumSize, DocumentContext dc) {
Wire wire = dc.wire();
String event = wire.readEvent(String.class);
if (!event.equals("data"))
throw new IllegalStateException("Expected ata not " + event);
wire.consumePadding();
Bytes<?> bytes = wire.bytes();
datum.bytesStore(bytes, bytes.readPosition(), datumSize);
}
Aggregations