use of net.openhft.chronicle.wire.Wire in project Chronicle-Queue by OpenHFT.
the class RollEOFTest method removeEOF.
private void removeEOF(Path path) throws IOException {
long blockSize = 64 << 10;
long chunkSize = OS.pageAlign(blockSize);
long overlapSize = OS.pageAlign(blockSize / 4);
final MappedBytes mappedBytes = MappedBytes.mappedBytes(path.toFile(), chunkSize, overlapSize, false);
mappedBytes.reserve(test);
try {
final Wire wire = WireType.BINARY_LIGHT.apply(mappedBytes);
final Bytes<?> bytes = wire.bytes();
bytes.readLimitToCapacity();
bytes.readSkip(4);
// move past header
try (final SingleChronicleQueueStore qs = loadStore(wire)) {
assertNotNull(qs);
long l = qs.writePosition();
long len = Wires.lengthOf(bytes.readVolatileInt(l));
long eofOffset = l + len + 4L;
bytes.writePosition(eofOffset);
bytes.writeInt(0);
}
} finally {
mappedBytes.release(test);
}
}
use of net.openhft.chronicle.wire.Wire in project Chronicle-Queue by OpenHFT.
the class ChronicleQueueIndexTest method readKeyed.
@NotNull
private List<String> readKeyed(ChronicleQueue queue, boolean includeMetaData) {
try (ExcerptTailer tailer = queue.createTailer()) {
List<String> allReads = new ArrayList<>();
for (; ; ) {
try (DocumentContext dc = tailer.readingDocument(includeMetaData)) {
if (!dc.isPresent())
return allReads;
final Wire wire = dc.wire();
final String key = wire.readEvent(String.class);
if (!key.equals("key"))
continue;
String str = wire.getValueIn().text();
allReads.add(str);
}
}
}
}
use of net.openhft.chronicle.wire.Wire in project Chronicle-Queue by OpenHFT.
the class Stackoveflow52274284Test method fails.
@Test
public void fails() throws IOException {
String basePath = OS.getTarget();
String path = Files.createTempDirectory(Paths.get(basePath), "chronicle-").toAbsolutePath().toString();
try (ChronicleQueue chronicleQueue = ChronicleQueue.singleBuilder(path).testBlockSize().build()) {
// Create Appender
ExcerptAppender appender = chronicleQueue.acquireAppender();
// Create Tailer
ExcerptTailer tailer = chronicleQueue.createTailer();
tailer.toStart();
int numberOfRecords = 10;
// Write
for (int i = 0; i <= numberOfRecords; i++) {
// System.out.println("Writing " + i);
try (final DocumentContext dc = appender.writingDocument()) {
dc.wire().write("msg").text("Hello World!");
// System.out.println("your data was store to index=" + dc.index());
} catch (Exception e) {
System.err.println("Unable to store value to chronicle");
e.printStackTrace();
}
}
// Read
for (int i = 0; i <= numberOfRecords; i++) {
// System.out.println("Reading " + i);
try (DocumentContext documentContext = tailer.readingDocument()) {
long currentOffset = documentContext.index();
// System.out.println("Current offset: " + currentOffset);
Wire wire = documentContext.wire();
if (wire != null) {
String msg = wire.read("msg").text();
// System.out.println(msg);
}
}
}
}
}
use of net.openhft.chronicle.wire.Wire in project Chronicle-Queue by OpenHFT.
the class IndexForIDTest method applyFlyweight.
private static void applyFlyweight(Facade datum, long datumSize, DocumentContext dc) {
Wire wire = dc.wire();
Bytes<?> bytes = wire.bytes();
datum.bytesStore(bytes, bytes.readPosition(), datumSize);
}
use of net.openhft.chronicle.wire.Wire in project Chronicle-Queue by OpenHFT.
the class PeekDocumentTest method testReadWrite10.
@Test
public void testReadWrite10() {
File tempDir = getTmpDir();
try {
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tempDir).build()) {
ExcerptAppender appender = queue.acquireAppender();
for (int i = 0; i < 1024; i++) {
try (DocumentContext documentContext = appender.writingDocument()) {
documentContext.wire().write("value").text("hello" + i);
}
}
ExcerptTailer tailer = queue.createTailer();
for (int i = 0; i < 1024; i++) {
assertTrue(tailer.peekDocument());
try (DocumentContext documentContext = tailer.readingDocument()) {
assertTrue(documentContext.isPresent());
assertTrue(tailer.peekDocument());
Wire wire = documentContext.wire();
long l = wire.bytes().readPosition();
try {
assertEquals("hello" + i, wire.read("value").text());
} finally {
// simulate if the message was read
if (l % 2 == 0)
wire.bytes().readPosition(l);
}
}
}
assertFalse(tailer.peekDocument());
try (DocumentContext documentContext = appender.writingDocument()) {
documentContext.wire().write("value").text("hello" + 10);
}
assertTrue(tailer.peekDocument());
}
} finally {
tempDir.deleteOnExit();
}
}
Aggregations