use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class RollCycleTest method testWriteToCorruptedFile.
@Test
public void testWriteToCorruptedFile() {
File dir = DirectoryUtils.tempDir("testWriteToCorruptedFile");
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(dir).testBlockSize().rollCycle(RollCycles.TEST_DAILY).build()) {
ExcerptAppender appender = queue.acquireAppender();
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().write().text("hello world");
}
Bytes bytes;
long pos;
try (DocumentContext dc = appender.writingDocument()) {
bytes = dc.wire().bytes();
pos = bytes.writePosition() - 4;
}
// write as not complete.
bytes.writeInt(pos, Wires.NOT_COMPLETE_UNKNOWN_LENGTH);
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().write().text("hello world 2");
}
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().write().text("hello world 3");
}
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueCloseTest method testTailAfterClose.
@Test
public void testTailAfterClose() {
final ChronicleQueue queue = SingleChronicleQueueBuilder.builder(getTmpDir(), WireType.BINARY).build();
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(w -> w.write(TestKey.test).int32(1));
queue.close();
try {
appender.writeDocument(w -> w.write(TestKey.test).int32(2));
Assert.fail();
} catch (IllegalStateException e) {
// ok
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueStoreTest method shouldNotPerformIndexingOnAppendWhenLazyIndexingIsEnabled.
@Test
public void shouldNotPerformIndexingOnAppendWhenLazyIndexingIsEnabled() throws Exception {
runTest(queue -> {
final ExcerptAppender appender = queue.acquireAppender();
appender.lazyIndexing(true);
final long[] indices = writeMessagesStoreIndices(appender, queue.createTailer());
assertExcerptsAreIndexed(queue, indices, i -> false, ScanResult.NOT_REACHED);
});
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class TestWriteWhenCurrentCycleGotEOF method shouldBeAbleToWriteIfCurrentCycleGotEOF.
@Test
public void shouldBeAbleToWriteIfCurrentCycleGotEOF() throws TimeoutException {
File tmpDir = getTmpDir();
createQueueWithOnlyHeaderFile(tmpDir);
SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir).testBlockSize().build();
ExcerptAppender appender = queue.acquireAppender();
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().write("test").text("Hello world");
}
try (DocumentContext dc = queue.acquireTailer().readingDocument()) {
assertEquals("Hello world", dc.wire().read("test").text());
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class ToEndTest method missingCyclesToEndTest.
@Test
public void missingCyclesToEndTest() throws InterruptedException {
String path = OS.TARGET + "/missingCyclesToEndTest-" + System.nanoTime();
IOTools.shallowDeleteDirWithFiles(path);
final SetTimeProvider timeProvider = new SetTimeProvider();
long now = 1470757797000L;
long timeIncMs = 1001;
timeProvider.currentTimeMillis(now);
final RollingChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).testBlockSize().rollCycle(RollCycles.TEST_SECONDLY).timeProvider(timeProvider).build();
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(wire -> wire.write(() -> "msg").int32(1));
// roll
timeProvider.currentTimeMillis(now += timeIncMs);
appender.writeDocument(wire -> wire.write(() -> "msg").int32(2));
appender.writeDocument(wire -> wire.write(() -> "msg").int32(3));
final ExcerptTailer tailer = queue.createTailer().toEnd();
try (DocumentContext dc = tailer.readingDocument()) {
if (dc.isPresent()) {
fail("Should be at the end of the queue but dc.isPresent and we read: " + String.valueOf(dc.wire().read(() -> "msg").int32()));
}
}
// append same cycle.
appender.writeDocument(wire -> wire.write(() -> "msg").int32(4));
try (DocumentContext dc = tailer.readingDocument()) {
assertTrue("Should be able to read entry in this cycle. Got NoDocumentContext.", dc.isPresent());
int i = dc.wire().read(() -> "msg").int32();
assertEquals("Should've read 4, instead we read: " + i, 4, i);
}
// read from the beginning
tailer.toStart();
for (int j = 1; j <= 4; j++) {
try (DocumentContext dc = tailer.readingDocument()) {
assertTrue(dc.isPresent());
int i = dc.wire().read(() -> "msg").int32();
assertEquals(j, i);
}
}
try (DocumentContext dc = tailer.readingDocument()) {
if (dc.isPresent()) {
fail("Should be at the end of the queue but dc.isPresent and we read: " + String.valueOf(dc.wire().read(() -> "msg").int32()));
}
}
// write another
appender.writeDocument(wire -> wire.write(() -> "msg").int32(5));
// roll 5 cycles
timeProvider.currentTimeMillis(now += timeIncMs * 5);
try (DocumentContext dc = tailer.readingDocument()) {
assertTrue(dc.isPresent());
assertEquals(5, dc.wire().read(() -> "msg").int32());
}
try (DocumentContext dc = tailer.readingDocument()) {
assertFalse(dc.isPresent());
}
}
Aggregations