Search in sources :

Example 1 with SUFFIX

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue.SUFFIX in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueTest method mappedSegmentsShouldBeUnmappedAsCycleRolls.

@Test
public void mappedSegmentsShouldBeUnmappedAsCycleRolls() throws Exception {
    final Random random = new Random(0xDEADBEEF);
    final File queueFolder = DirectoryUtils.tempDir("mappedSegmentsShouldBeUnmappedAsCycleRolls");
    final AtomicLong clock = new AtomicLong(System.currentTimeMillis());
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueFolder).timeProvider(clock::get).testBlockSize().rollCycle(RollCycles.HOURLY).build()) {
        final ExcerptAppender appender = queue.acquireAppender();
        for (int i = 0; i < 20_000; i++) {
            final int batchSize = random.nextInt(10);
            appender.writeDocument(batchSize, ValueOut::int64);
            final byte payload = (byte) random.nextInt();
            for (int j = 0; j < batchSize; j++) {
                appender.writeDocument(payload, ValueOut::int8);
            }
            if (random.nextDouble() > 0.995) {
                clock.addAndGet(TimeUnit.MINUTES.toMillis(37L));
                // this give the reference processor a chance to run
                LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(15L));
            }
        }
        if (OS.isLinux())
            assertTrue("Too many mapped files: " + getMappedQueueFileCount(), getMappedQueueFileCount() < 40);
        assertTrue(Files.list(queueFolder.toPath()).filter(p -> p.toString().endsWith(SUFFIX)).count() > 10L);
    }
}
Also used : net.openhft.chronicle.bytes(net.openhft.chronicle.bytes) IntStream(java.util.stream.IntStream) SUFFIX(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue.SUFFIX) CoreMatchers.is(org.hamcrest.CoreMatchers.is) java.util(java.util) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) Assume.assumeFalse(org.junit.Assume.assumeFalse) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Jvm(net.openhft.chronicle.core.Jvm) RollingChronicleQueue(net.openhft.chronicle.queue.impl.RollingChronicleQueue) ISO_8859_1(java.nio.charset.StandardCharsets.ISO_8859_1) net.openhft.chronicle.wire(net.openhft.chronicle.wire) LogLevel(net.openhft.chronicle.core.onoes.LogLevel) StringUtils(net.openhft.chronicle.core.util.StringUtils) BiConsumer(java.util.function.BiConsumer) InternalAppender(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueExcerpts.InternalAppender) TimeProvider(net.openhft.chronicle.core.time.TimeProvider) Parameterized(org.junit.runners.Parameterized) ExceptionKey(net.openhft.chronicle.core.onoes.ExceptionKey) ALWAYS(net.openhft.chronicle.wire.MarshallableOut.Padding.ALWAYS) Files(java.nio.file.Files) java.util.concurrent(java.util.concurrent) StoreAppender(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueExcerpts.StoreAppender) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) UsedViaReflection(net.openhft.chronicle.core.annotation.UsedViaReflection) java.io(java.io) net.openhft.chronicle.queue(net.openhft.chronicle.queue) FileVisitOption(java.nio.file.FileVisitOption) Closeable.closeQuietly(net.openhft.chronicle.core.io.Closeable.closeQuietly) RollCycles(net.openhft.chronicle.queue.RollCycles) Assume.assumeTrue(org.junit.Assume.assumeTrue) org.junit(org.junit) OS(net.openhft.chronicle.core.OS) ThreadDump(net.openhft.chronicle.core.threads.ThreadDump) NotNull(org.jetbrains.annotations.NotNull) Assert(org.junit.Assert) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

java.io (java.io)1 ISO_8859_1 (java.nio.charset.StandardCharsets.ISO_8859_1)1 FileVisitOption (java.nio.file.FileVisitOption)1 Files (java.nio.file.Files)1 java.util (java.util)1 java.util.concurrent (java.util.concurrent)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LockSupport (java.util.concurrent.locks.LockSupport)1 BiConsumer (java.util.function.BiConsumer)1 Supplier (java.util.function.Supplier)1 IntStream (java.util.stream.IntStream)1 net.openhft.chronicle.bytes (net.openhft.chronicle.bytes)1 Jvm (net.openhft.chronicle.core.Jvm)1 OS (net.openhft.chronicle.core.OS)1 UsedViaReflection (net.openhft.chronicle.core.annotation.UsedViaReflection)1 Closeable.closeQuietly (net.openhft.chronicle.core.io.Closeable.closeQuietly)1 ExceptionKey (net.openhft.chronicle.core.onoes.ExceptionKey)1 LogLevel (net.openhft.chronicle.core.onoes.LogLevel)1