Search in sources :

Example 1 with SingleChronicleQueueBuilder

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

the class StageMain method outputQueue.

@NotNull
private static SingleChronicleQueue outputQueue(final Path path, final int index) {
    final SingleChronicleQueueBuilder builder = ChronicleQueue.singleBuilder(path);
    builder.rollTime(RollTimeCalculator.getNextRollWindow(), ZoneId.of("UTC"));
    if (index != UNSET_SOURCE) {
        builder.sourceId(index);
    }
    return builder.rollCycle(RollCycles.HOURLY).build();
}
Also used : SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SingleChronicleQueueBuilder

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

the class ChunkCountTest method chunks.

@Test
public void chunks() {
    final SingleChronicleQueueBuilder builder = SingleChronicleQueueBuilder.binary(IOTools.createTempFile("chunks")).blockSize(64 << 10).rollCycle(RollCycles.DAILY);
    try (SingleChronicleQueue queue = builder.build();
        ExcerptAppender appender = queue.acquireAppender()) {
        assertEquals(0, queue.chunkCount());
        appender.writeText("Hello");
        assertEquals(1, queue.chunkCount());
        for (int i = 0; i < 100; i++) {
            long pos;
            try (DocumentContext dc = appender.writingDocument()) {
                pos = dc.wire().bytes().writePosition();
                dc.wire().bytes().writeSkip(16000);
            }
            final long expected = builder.useSparseFiles() ? 1 : 1 + (pos >> 18);
            assertEquals("i: " + i, expected, queue.chunkCount());
        }
    }
}
Also used : SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Test(org.junit.Test)

Example 3 with SingleChronicleQueueBuilder

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

the class RollCycleDefaultingTest method nonRollCycleDefaultsToDaily.

@Test
public void nonRollCycleDefaultsToDaily() {
    expectException("Configured default rollcycle is not a subclass of RollCycle");
    String configuredCycle = String.class.getName();
    System.setProperty(QueueSystemProperties.DEFAULT_ROLL_CYCLE_PROPERTY, configuredCycle);
    SingleChronicleQueueBuilder builder = SingleChronicleQueueBuilder.binary("test");
    assertEquals(RollCycles.DEFAULT, builder.rollCycle());
}
Also used : SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) Test(org.junit.Test)

Example 4 with SingleChronicleQueueBuilder

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

the class RollCycleDefaultingTest method unknownClassDefaultsToDaily.

@Test
public void unknownClassDefaultsToDaily() {
    expectException("Default roll cycle class: foobarblah was not found");
    String configuredCycle = "foobarblah";
    System.setProperty(QueueSystemProperties.DEFAULT_ROLL_CYCLE_PROPERTY, configuredCycle);
    SingleChronicleQueueBuilder builder = SingleChronicleQueueBuilder.binary("test");
    assertEquals(RollCycles.DEFAULT, builder.rollCycle());
}
Also used : SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) Test(org.junit.Test)

Example 5 with SingleChronicleQueueBuilder

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

the class ChronicleAppenderCycleTest method useAppender.

private AtomicReference<Throwable> useAppender(Path path, Consumer<ExcerptAppender> tester, CountDownLatch done) {
    AtomicReference<Throwable> refThr = new AtomicReference<>();
    Thread thread = new Thread(() -> {
        try {
            SingleChronicleQueueBuilder builder = createBuilder(path);
            try (SingleChronicleQueue queue = builder.build()) {
                try (ExcerptAppender appender = queue.acquireAppender()) {
                    tester.accept(appender);
                }
            }
        } catch (Throwable e) {
            refThr.set(e);
            e.printStackTrace();
        } finally {
            done.countDown();
        }
    });
    thread.setDaemon(true);
    thread.start();
    return refThr;
}
Also used : SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)14 Test (org.junit.Test)9 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)4 File (java.io.File)3 SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)3 ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)2 DocumentContext (net.openhft.chronicle.wire.DocumentContext)2 NotNull (org.jetbrains.annotations.NotNull)2 Ignore (org.junit.Ignore)2 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1