use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class MappedMemoryUnmappingTest method shouldUnmapMemoryAsCycleRolls.
@Test
public void shouldUnmapMemoryAsCycleRolls() throws IOException {
final AtomicLong clock = new AtomicLong(System.currentTimeMillis());
long initialQueueMappedMemory = 0L;
try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmp.newFolder()).testBlockSize().rollCycle(RollCycles.TEST_SECONDLY).timeProvider(clock::get).build()) {
for (int i = 0; i < 100; i++) {
queue.acquireAppender().writeDocument(System.nanoTime(), (d, t) -> d.int64(t));
clock.addAndGet(TimeUnit.SECONDS.toMillis(1L));
if (initialQueueMappedMemory == 0L) {
initialQueueMappedMemory = OS.memoryMapped();
}
}
}
GcControls.waitForGcCycle();
final long timeoutAt = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10L);
while (System.currentTimeMillis() < timeoutAt) {
if (OS.memoryMapped() < 2 * initialQueueMappedMemory) {
return;
}
}
fail(String.format("Mapped memory (%dB) did not fall below threshold (%dB)", OS.memoryMapped(), 2 * initialQueueMappedMemory));
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class MicroToucherTest method touchPage.
public void touchPage(Consumer<SingleChronicleQueueBuilder> configure, int pagesExpected) {
long start = System.nanoTime();
String path = OS.getTarget() + "/touchPage-" + System.nanoTime();
int pages = 0;
final SingleChronicleQueueBuilder builder = ChronicleQueue.singleBuilder(path);
configure.accept(builder);
try (ChronicleQueue q = builder.build();
final StoreAppender appender = (StoreAppender) q.acquireAppender()) {
Thread msync = new Thread(() -> {
try {
while (true) {
appender.bgMicroTouch();
Jvm.pause(25);
}
} catch (ClosedIllegalStateException expected) {
}
});
msync.setDaemon(true);
msync.start();
long lastPage = 0;
for (int i = 0; i < (1 << 20); i++) {
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().bytes().writeSkip(256);
}
long page = (appender.lastPosition + 0xFFF) & ~0xFFF;
boolean touch = page != lastPage && appender.wire().bytes().bytesStore().inside(page, 8);
lastPage = page;
if (touch != appender.microTouch())
assertEquals("i: " + i, touch, appender.microTouch());
if (touch)
pages++;
}
}
System.out.println("pages = " + pages);
// assertEquals(pagesExpected, pages);
System.out.println("Time = " + (System.nanoTime() - start) / 1000000 / 1e3);
IOTools.deleteDirWithFiles(path);
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class QueueExamples2 method main.
public static void main(String[] args) {
ChronicleQueue queue = ChronicleQueue.single("./myQueueDir");
final MethodReader methodReader = queue.createTailer().methodReader((Printer) System.out::println);
for (; ; ) {
final boolean successIfMessageRead = methodReader.readOne();
Thread.yield();
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class MessageHistoryTest method shouldAccessMessageHistoryWhenTailerIsMovedToEnd.
@Test
public void shouldAccessMessageHistoryWhenTailerIsMovedToEnd() {
try (final ChronicleQueue inputQueue = createQueue(inputQueueDir, 1);
final ChronicleQueue outputQueue = createQueue(outputQueueDir, 2)) {
generateTestData(inputQueue, outputQueue);
final ExcerptTailer tailer = outputQueue.createTailer(named ? "named" : null);
tailer.direction(TailerDirection.BACKWARD).toEnd();
final ValidatingSecond validatingSecond = new ValidatingSecond();
final MethodReader validator = tailer.methodReader(validatingSecond);
assertTrue(validator.readOne());
assertTrue(validatingSecond.messageHistoryPresent());
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class MoveToIndexTest method shouldMoveToPreviousIndexAfterDocumentIsConsumed.
@Test
public void shouldMoveToPreviousIndexAfterDocumentIsConsumed() throws IOException {
File queuePath = tmpFolder.newFolder("cq");
try (ChronicleQueue queue = ChronicleQueue.singleBuilder(queuePath).build()) {
ExcerptAppender appender = queue.acquireAppender();
for (int i = 1; i < 10; ++i) {
appender.writeText("id" + i);
}
ExcerptTailer tailer = queue.createTailer();
assertNext(tailer, "id1");
long index = tailer.index();
assertNext(tailer, "id2");
tailer.moveToIndex(index);
assertNext(tailer, "id2");
tailer.moveToIndex(index);
assertNext(tailer, "id2");
}
}
Aggregations