use of net.openhft.chronicle.queue.ExcerptTailer 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());
}
}
}
use of net.openhft.chronicle.queue.ExcerptTailer in project Chronicle-Queue by OpenHFT.
the class NotCompleteTest method testSkipSafeLengthOverBlock.
@Ignore("store.writePosition() not set after we recover, but not trivial to fix. Problem only occurs rarely")
@Test
public void testSkipSafeLengthOverBlock() {
File tmpDir = DirectoryUtils.tempDir("testSkipSafeLengthOverBlock");
// 3rd time will do it
for (int i = 0; i < 8; i++) {
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().rollCycle(RollCycles.TEST_DAILY).timeoutMS(1).build()) {
ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
// start a message which won't be completed.
DocumentContext dc = appender.writingDocument();
// 2nd and subsequent times we call this will invoke recovery
dc.wire().write("some").text("data");
// don't call dc.close();
}
}
try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().build()) {
ExcerptTailer tailer = queue.createTailer();
try (DocumentContext dc = tailer.readingDocument()) {
assertFalse(dc.isPresent());
}
}
}
use of net.openhft.chronicle.queue.ExcerptTailer in project Chronicle-Queue by OpenHFT.
the class NotCompleteTest method testUsingANotCompleteQueue.
/**
* tests that when flags are set to not complete we are able to recover
*/
@Test
public void testUsingANotCompleteQueue() throws InterruptedException {
BinaryLongReference.startCollecting();
File tmpDir = DirectoryUtils.tempDir("testUsingANotCompleteQueue");
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
BinaryLongReference.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());
}
}
}
use of net.openhft.chronicle.queue.ExcerptTailer in project Chronicle-Queue by OpenHFT.
the class QueueWireHandler method onEvent.
@SuppressWarnings("UnusedReturnValue")
void onEvent() throws IOException {
// Be careful not to use Wires.acquireStringBuilder() as we
// need to store the value
inWire.readDocument(w -> {
w.read(CoreFields.csp).text(cspText).read(CoreFields.tid).int64(x -> tid = x).read(CoreFields.cid).int64(x -> cid = x);
queue = getQueue(cspText);
}, dataWireIn -> {
ValueIn vin = inWire.readEventName(eventName);
try {
// writes out the tid
outWire.writeDocument(true, wire -> outWire.write(CoreFields.tid).int64(tid));
if (EventId.lastWrittenIndex.contentEquals(eventName)) {
writeData(wireOut -> wireOut.write(CoreFields.reply).int64(queue.lastWrittenIndex()));
} else if (EventId.createAppender.contentEquals(eventName)) {
// only need one appender per queue
queueToAppender.computeIfAbsent(queue, s -> {
try {
return queue.createAppender();
} catch (IOException e) {
e.printStackTrace();
}
return null;
});
outWire.writeDocument(false, wireOut -> {
QueueAppenderResponse qar = new QueueAppenderResponse();
qar.setCid(cid);
qar.setCsp(cspText);
wireOut.write(CoreFields.reply).typedMarshallable(qar);
});
} else if (EventId.submit.contentEquals(eventName)) {
ExcerptAppender appender = queueToAppender.get(queue);
appender.writeDocument(wo -> wo.bytes().write(vin.bytes()));
outWire.writeDocument(false, wire -> wire.write(EventId.index).int64(appender.lastWrittenIndex()));
} else if (EventId.createTailer.contentEquals(eventName)) {
// only need one appender per queue
queueToTailer.computeIfAbsent(queue, s -> {
try {
return queue.createTailer();
} catch (IOException e) {
e.printStackTrace();
}
return null;
});
outWire.writeDocument(false, wireOut -> {
QueueTailerResponse qar = new QueueTailerResponse();
qar.setCid(cid);
qar.setCsp(cspText);
wireOut.write(CoreFields.reply).typedMarshallable(qar);
});
} else if (EventId.hasNext.contentEquals(eventName)) {
ExcerptTailer tailer = queueToTailer.get(queue);
vin.marshallable((ReadMarshallable) rm -> {
long index = rm.read(() -> "index").int64();
sendBackMessage(tailer, index);
});
}
} finally {
if (EventGroup.IS_DEBUG) {
long len = outWire.bytes().position() - SIZE_OF_SIZE;
if (len == 0) {
System.out.println("--------------------------------------------\n" + "server writes:\n\n<EMPTY>");
} else {
System.out.println("--------------------------------------------\n" + "server writes:\n\n" + Wires.fromSizePrefixedBlobs(outWire.bytes(), SIZE_OF_SIZE, len));
}
}
}
});
}
use of net.openhft.chronicle.queue.ExcerptTailer in project Chronicle-Queue by OpenHFT.
the class Indexer method index.
/**
* Scans through every excerpts and records every 64th addressForRead in the index2index'
*
* @
*/
public synchronized void index() {
final ExcerptTailer tailer = chronicle.createTailer();
for (long i = 0; i <= chronicle.lastIndex(); i++) {
final long index = i;
tailer.readDocument(wireIn -> {
long address = wireIn.bytes().position() - 4;
recordAddress(index, address);
wireIn.bytes().skip(wireIn.bytes().remaining());
});
}
}
Aggregations