use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class CreateAtIndexTest method testWrittenAndReadIndexesAreTheSameOfTheFirstExcerpt.
// TODO: 2 or more threads soak test
@Test
public void testWrittenAndReadIndexesAreTheSameOfTheFirstExcerpt() throws Exception {
String tmp = OS.TARGET + "/" + getClass().getSimpleName() + "-" + System.nanoTime();
long expected;
try (SingleChronicleQueue queue = ChronicleQueueBuilder.single(tmp).testBlockSize().build()) {
ExcerptAppender appender = queue.acquireAppender();
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().write().text("some-data");
expected = dc.index();
Assert.assertTrue(expected > 0);
}
appender.lastIndexAppended();
ExcerptTailer tailer = queue.createTailer();
try (DocumentContext dc = tailer.readingDocument()) {
String text = dc.wire().read().text();
{
long actualIndex = dc.index();
Assert.assertTrue(actualIndex > 0);
Assert.assertEquals(expected, actualIndex);
}
{
long actualIndex = tailer.index();
Assert.assertTrue(actualIndex > 0);
Assert.assertEquals(expected, actualIndex);
}
}
}
}
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 LastIndexAppendedTest method doRead.
private long doRead(@NotNull ExcerptTailer tailer, int expected) {
int[] i = { 0 };
long t_index = 0;
while (true) {
try (DocumentContext dc = tailer.readingDocument()) {
if (!dc.isPresent())
break;
t_index = tailer.index();
dc.wire().read("log").marshallable(m -> {
String msg = m.read("msg").text();
assertNotNull(msg);
System.out.println("msg:" + msg);
i[0]++;
});
}
}
assertEquals(expected, i[0]);
return t_index;
}
use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class OvertakeTest method doReadBad.
private static long doReadBad(@NotNull ExcerptTailer tailer, int expected, boolean additionalClose) {
int[] i = { 0 };
long t_index = 0;
while (true) {
try (DocumentContext dc = tailer.readingDocument()) {
if (!dc.isPresent())
break;
t_index = tailer.index();
dc.wire().read("log").marshallable(m -> {
String msg = m.read("msg").text();
assertNotNull(msg);
i[0]++;
});
if (additionalClose) {
dc.close();
}
}
}
assertEquals(expected, i[0]);
return t_index;
}
Aggregations