use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class QueueInspectorTest method shouldDetermineWritingProcessIdWhenDocumentIsNotComplete.
@Test
public void shouldDetermineWritingProcessIdWhenDocumentIsNotComplete() throws IOException {
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir.newFolder()).testBlockSize().build()) {
final QueueInspector inspector = new QueueInspector(queue);
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(37L, ValueOut::int64);
try (final DocumentContext ctx = appender.writingDocument()) {
ctx.wire().write("foo").int32(17L);
final int writingThreadId = inspector.getWritingThreadId();
assertThat(writingThreadId, is(Affinity.getThreadId()));
assertThat(QueueInspector.isValidThreadId(writingThreadId), is(true));
}
}
}
use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class RollCycleRetrieverTest method shouldRetrieveCorrectRollCycleFromExistingQueueFile.
@Test
public void shouldRetrieveCorrectRollCycleFromExistingQueueFile() throws Exception {
final File queuePath = tempDir(RollCycleRetrieverTest.class.getSimpleName() + System.nanoTime());
final SingleChronicleQueueBuilder builder = builder(queuePath, WIRE_TYPE).testBlockSize().rollCycle(ROLL_CYCLE);
try (final SingleChronicleQueue queue = builder.build()) {
final ExcerptAppender appender = queue.acquireAppender();
try (final DocumentContext context = appender.writingDocument()) {
context.wire().write("foo").text("bar");
}
}
assertThat(getRollCycle(queuePath.toPath(), WIRE_TYPE, builder.blockSize()).isPresent(), is(true));
assertThat(getRollCycle(queuePath.toPath(), WIRE_TYPE, builder.blockSize()).get(), is(ROLL_CYCLE));
}
use of net.openhft.chronicle.wire.DocumentContext 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.wire.DocumentContext 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.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class RollEOFTest method createQueueAndWriteData.
private void createQueueAndWriteData(MutableTimeProvider timeProvider) {
final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).testBlockSize().rollCycle(RollCycles.TEST_DAILY).timeProvider(timeProvider).build();
ExcerptAppender excerptAppender = queue.acquireAppender();
try (DocumentContext dc = excerptAppender.writingDocument(false)) {
dc.wire().write(() -> "test").int64(0);
}
}
Aggregations