use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueueExcerpts.StoreAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method writeBytesAndIndexFiveTimesWithOverwriteTest.
@Test
public void writeBytesAndIndexFiveTimesWithOverwriteTest() {
try (final SingleChronicleQueue sourceQueue = builder(DirectoryUtils.tempDir("to-be-deleted"), wireType).testBlockSize().build()) {
for (int i = 0; i < 5; i++) {
ExcerptAppender excerptAppender = sourceQueue.acquireAppender();
try (DocumentContext dc = excerptAppender.writingDocument()) {
dc.wire().write("hello").text("world" + i);
}
}
ExcerptTailer tailer = sourceQueue.createTailer();
try (final SingleChronicleQueue queue = builder(DirectoryUtils.tempDir("to-be-deleted"), wireType).testBlockSize().build()) {
ExcerptAppender appender0 = queue.acquireAppender();
if (!(appender0 instanceof InternalAppender))
return;
InternalAppender appender = (InternalAppender) appender0;
if (!(appender instanceof StoreAppender))
return;
List<BytesWithIndex> bytesWithIndies = new ArrayList<>();
try {
for (int i = 0; i < 5; i++) {
bytesWithIndies.add(bytes(tailer));
}
for (int i = 0; i < 4; i++) {
BytesWithIndex b = bytesWithIndies.get(i);
appender.writeBytes(b.index, b.bytes);
}
for (int i = 0; i < 4; i++) {
BytesWithIndex b = bytesWithIndies.get(i);
appender.writeBytes(b.index, b.bytes);
}
BytesWithIndex b = bytesWithIndies.get(4);
appender.writeBytes(b.index, b.bytes);
((StoreAppender) appender).checkWritePositionHeaderNumber();
appender0.writeText("hello");
} finally {
closeQuietly(bytesWithIndies);
}
System.out.println(queue.dump());
Assert.assertTrue(queue.dump().contains("--- !!data #binary\n" + "hello: world0\n" + "# position: 1041, header: 1\n" + "--- !!data #binary\n" + "hello: world1\n" + "# position: 1058, header: 2\n" + "--- !!data #binary\n" + "hello: world2\n" + "# position: 1075, header: 3\n" + "--- !!data #binary\n" + "hello: world3\n" + "# position: 1092, header: 4\n" + "--- !!data #binary\n" + "hello: world4\n" + "# position: 1109, header: 5\n" + "--- !!data\n" + "hello\n"));
}
}
}
Aggregations