Search in sources :

Example 6 with NativeBytesStore

use of net.openhft.chronicle.bytes.NativeBytesStore in project Chronicle-Queue by OpenHFT.

the class BytesRingBufferTest method testFlowAroundSingleThreadedWriteDifferentSizeBuffers.

@Test
public void testFlowAroundSingleThreadedWriteDifferentSizeBuffers() {
    try (NativeBytesStore<Void> nativeStore = NativeBytesStore.nativeStoreWithFixedCapacity(150)) {
        System.out.println(nativeStore.realCapacity());
        System.out.println(nativeStore.capacity());
        System.out.println(nativeStore.limit());
        assert !nativeStore.isElastic();
        Bytes<Void> bytes = nativeStore.bytes();
        System.out.println(bytes);
        for (int j = 23 + 34; j < 100; j++) {
            final BytesRingBuffer bytesRingBuffer = new BytesRingBuffer(nativeStore.bytes());
            for (int i = 0; i < 50; i++) {
                bytesRingBuffer.offer(data());
                String actual = bytesRingBuffer.take(maxSize -> input.clear()).readUTFΔ();
                assertEquals(EXPECTED, actual);
            }
        }
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) NativeBytesStore(net.openhft.chronicle.bytes.NativeBytesStore) CountDownLatch(java.util.concurrent.CountDownLatch) Bytes(net.openhft.chronicle.bytes.Bytes) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BytesRingBuffer(net.openhft.chronicle.queue.impl.ringbuffer.BytesRingBuffer) Assert.fail(org.junit.Assert.fail) org.junit(org.junit) ByteBuffer(java.nio.ByteBuffer) ExecutorService(java.util.concurrent.ExecutorService) Executors(java.util.concurrent.Executors) Assert.assertEquals(org.junit.Assert.assertEquals) BytesRingBuffer(net.openhft.chronicle.queue.impl.ringbuffer.BytesRingBuffer)

Example 7 with NativeBytesStore

use of net.openhft.chronicle.bytes.NativeBytesStore in project Chronicle-Queue by OpenHFT.

the class DirectChronicleQueueStringTest method readSome.

private void readSome(DirectChronicleQueue chronicle) {
    NativeBytesStore allocate = NativeBytesStore.nativeStoreWithFixedCapacity(EXPECTED_BYTES.length);
    final Bytes toRead = allocate.bytes();
    AtomicLong offset = new AtomicLong(chronicle.firstBytes());
    for (int i = 0; i < RUNS; i++) {
        toRead.clear();
        chronicle.readDocument(offset, toRead);
    }
}
Also used : Bytes(net.openhft.chronicle.bytes.Bytes) AtomicLong(java.util.concurrent.atomic.AtomicLong) NativeBytesStore(net.openhft.chronicle.bytes.NativeBytesStore)

Aggregations

Bytes (net.openhft.chronicle.bytes.Bytes)7 NativeBytesStore (net.openhft.chronicle.bytes.NativeBytesStore)7 BytesRingBuffer (net.openhft.chronicle.queue.impl.ringbuffer.BytesRingBuffer)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutorService (java.util.concurrent.ExecutorService)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 File (java.io.File)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 Affinity (net.openhft.affinity.Affinity)1 AffinityLock (net.openhft.affinity.AffinityLock)1 Jvm (net.openhft.chronicle.core.Jvm)1 StackSampler (net.openhft.chronicle.core.threads.StackSampler)1 Histogram (net.openhft.chronicle.core.util.Histogram)1 ChronicleQueueBuilder (net.openhft.chronicle.queue.ChronicleQueueBuilder)1