use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class IndexTest method shouldShortCircuitIndexLookupWhenNewIndexIsCloseToPreviousIndex.
@Test
public void shouldShortCircuitIndexLookupWhenNewIndexIsCloseToPreviousIndex() throws Exception {
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(getTmpDir()).testBlockSize().wireType(this.wireType).build()) {
final ExcerptAppender appender = queue.acquireAppender();
final int messageCount = INDEXING_LINEAR_SCAN_THRESHOLD + 5;
final long[] indices = new long[messageCount];
for (int i = 0; i < messageCount; i++) {
try (final DocumentContext ctx = appender.writingDocument()) {
ctx.wire().write("event").int32(i);
indices[i] = ctx.index();
}
}
final SingleChronicleQueueExcerpts.StoreTailer tailer = (SingleChronicleQueueExcerpts.StoreTailer) queue.createTailer();
tailer.moveToIndex(indices[0]);
assertThat(tailer.index(), is(indices[0]));
assertThat(tailer.getIndexMoveCount(), is(1));
tailer.moveToIndex(indices[0]);
assertThat(tailer.index(), is(indices[0]));
assertThat(tailer.getIndexMoveCount(), is(1));
tailer.moveToIndex(indices[2]);
assertThat(tailer.index(), is(indices[2]));
assertThat(tailer.getIndexMoveCount(), is(1));
tailer.moveToIndex(indices[INDEXING_LINEAR_SCAN_THRESHOLD + 2]);
assertThat(tailer.index(), is(indices[INDEXING_LINEAR_SCAN_THRESHOLD + 2]));
assertThat(tailer.getIndexMoveCount(), is(2));
// document that moving backwards requires an index scan
tailer.moveToIndex(indices[INDEXING_LINEAR_SCAN_THRESHOLD - 1]);
assertThat(tailer.index(), is(indices[INDEXING_LINEAR_SCAN_THRESHOLD - 1]));
assertThat(tailer.getIndexMoveCount(), is(3));
}
}
use of net.openhft.chronicle.wire.DocumentContext 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.wire.DocumentContext 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.wire.DocumentContext 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.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class PretoucherTest method shouldHandleCycleRoll.
@Test
public void shouldHandleCycleRoll() throws Exception {
try (final SingleChronicleQueue queue = createQueue(path, clock::get)) {
final Pretoucher pretoucher = new Pretoucher(queue, chunkListener, capturedCycles::add);
range(0, 10).forEach(i -> {
try (final DocumentContext ctx = queue.acquireAppender().writingDocument()) {
ctx.wire().write().int32(i);
pretoucher.execute();
ctx.wire().write().bytes(new byte[1024]);
}
pretoucher.execute();
clock.addAndGet(TimeUnit.SECONDS.toMillis(5L));
});
assertThat(capturedCycles.size(), is(10));
assertThat(chunkListener.chunkMap.isEmpty(), is(false));
}
}
Aggregations