use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class QueueInspectorTest method shouldIndicateNoProcessIdWhenDocumentIsComplete.
@Test
public void shouldIndicateNoProcessIdWhenDocumentIsComplete() 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(not(OS.getProcessId())));
assertThat(QueueInspector.isValidThreadId(writingThreadId), is(false));
}
}
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 RollAtEndOfCycleTest method shouldAppendToExistingQueueFile.
@Test
public void shouldAppendToExistingQueueFile() throws Exception {
try (final SingleChronicleQueue queue = createQueue()) {
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(1, (w, i) -> {
w.int32(i);
});
final ExcerptTailer tailer = queue.createTailer();
try (final DocumentContext context = tailer.readingDocument()) {
assertTrue(context.isPresent());
}
assertQueueFileCount(queue.path.toPath(), 1);
assertFalse(tailer.readingDocument().isPresent());
appender.writeDocument(2, (w, i) -> {
w.int32(i);
});
assertQueueFileCount(queue.path.toPath(), 1);
try (final DocumentContext context = tailer.readingDocument()) {
assertTrue(context.isPresent());
}
}
}
use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class RollAtEndOfCycleTest method shouldRollAndAppendToNewFile.
@Test
public void shouldRollAndAppendToNewFile() throws Exception {
try (final SingleChronicleQueue queue = createQueue()) {
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(1, (w, i) -> {
w.int32(i);
});
final ExcerptTailer tailer = queue.createTailer();
try (final DocumentContext context = tailer.readingDocument()) {
assertTrue(context.isPresent());
}
assertQueueFileCount(queue.path.toPath(), 1);
clock.addAndGet(TimeUnit.SECONDS.toMillis(2));
assertFalse(tailer.readingDocument().isPresent());
appender.writeDocument(2, (w, i) -> {
w.int32(i);
});
assertQueueFileCount(queue.path.toPath(), 2);
try (final DocumentContext context = tailer.readingDocument()) {
assertTrue(context.isPresent());
}
final ExcerptTailer newTailer = queue.createTailer();
int totalCount = 0;
while (true) {
final DocumentContext context = newTailer.readingDocument();
if (context.isPresent() && context.isData()) {
assertTrue(context.wire().read().int32() != 0);
totalCount++;
} else if (!context.isPresent()) {
break;
}
}
assertThat(totalCount, is(2));
}
}
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));
}
Aggregations