Package com.jamieallen.sdisruptor.support

Examples of com.jamieallen.sdisruptor.support.TestConsumer


    {
        final int ringBufferSize = 4;
        final CountDownLatch latch = new CountDownLatch(ringBufferSize);
        final AtomicBoolean producerComplete = new AtomicBoolean(false);
        final RingBuffer<StubEntry> ringBuffer = new RingBuffer<StubEntry>(StubEntry.ENTRY_FACTORY, ringBufferSize, null, null);
        final TestConsumer consumer = new TestConsumer(ringBuffer.createConsumerBarrier(new Consumer[0]));
        final TestConsumer[] consumers = new TestConsumer[] { consumer };
        ringBuffer.consumersToTrack_(consumers);

        Thread thread = new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                for (int i = 0; i <= ringBufferSize; i++)
                {
                    StubEntry entry = ringBuffer.nextEntry();
                    entry.setValue(i);
                    ringBuffer.commit(entry);
                    latch.countDown();
                }

                producerComplete.set(true);
            }
        });
        thread.start();

        latch.await();
        assertThat(Long.valueOf(ringBuffer.cursor()), is(Long.valueOf(ringBufferSize - 1)));
        assertFalse(producerComplete.get());

        consumer.run();
        thread.join();

        assertTrue(producerComplete.get());
    }
View Full Code Here

TOP

Related Classes of com.jamieallen.sdisruptor.support.TestConsumer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.