Search in sources :

Example 1 with DummyEventProcessor

use of com.lmax.disruptor.support.DummyEventProcessor in project disruptor by LMAX-Exchange.

the class SequenceBarrierTest method shouldWaitForWorkCompleteWhereAllWorkersAreBlockedOnRingBuffer.

@Test
public void shouldWaitForWorkCompleteWhereAllWorkersAreBlockedOnRingBuffer() throws Exception {
    long expectedNumberMessages = 10;
    fillRingBuffer(expectedNumberMessages);
    final DummyEventProcessor[] workers = new DummyEventProcessor[3];
    for (int i = 0, size = workers.length; i < size; i++) {
        workers[i] = new DummyEventProcessor();
        workers[i].setSequence(expectedNumberMessages - 1);
    }
    final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier(Util.getSequencesFor(workers));
    Runnable runnable = new Runnable() {

        public void run() {
            long sequence = ringBuffer.next();
            StubEvent event = ringBuffer.get(sequence);
            event.setValue((int) sequence);
            ringBuffer.publish(sequence);
            for (DummyEventProcessor stubWorker : workers) {
                stubWorker.setSequence(sequence);
            }
        }
    };
    new Thread(runnable).start();
    long expectedWorkSequence = expectedNumberMessages;
    long completedWorkSequence = sequenceBarrier.waitFor(expectedNumberMessages);
    assertTrue(completedWorkSequence >= expectedWorkSequence);
}
Also used : DummyEventProcessor(com.lmax.disruptor.support.DummyEventProcessor) StubEvent(com.lmax.disruptor.support.StubEvent) Test(org.junit.Test)

Example 2 with DummyEventProcessor

use of com.lmax.disruptor.support.DummyEventProcessor in project disruptor by LMAX-Exchange.

the class SequenceBarrierTest method shouldWaitForWorkCompleteWhereCompleteWorkThresholdIsBehind.

@Test
public void shouldWaitForWorkCompleteWhereCompleteWorkThresholdIsBehind() throws Exception {
    long expectedNumberMessages = 10;
    fillRingBuffer(expectedNumberMessages);
    final DummyEventProcessor[] eventProcessors = new DummyEventProcessor[3];
    for (int i = 0, size = eventProcessors.length; i < size; i++) {
        eventProcessors[i] = new DummyEventProcessor();
        eventProcessors[i].setSequence(expectedNumberMessages - 2);
    }
    final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier(Util.getSequencesFor(eventProcessors));
    Runnable runnable = new Runnable() {

        public void run() {
            for (DummyEventProcessor stubWorker : eventProcessors) {
                stubWorker.setSequence(stubWorker.getSequence().get() + 1L);
            }
        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
    thread.join();
    long expectedWorkSequence = expectedNumberMessages - 1;
    long completedWorkSequence = sequenceBarrier.waitFor(expectedWorkSequence);
    assertTrue(completedWorkSequence >= expectedWorkSequence);
}
Also used : DummyEventProcessor(com.lmax.disruptor.support.DummyEventProcessor) Test(org.junit.Test)

Example 3 with DummyEventProcessor

use of com.lmax.disruptor.support.DummyEventProcessor in project disruptor by LMAX-Exchange.

the class ConsumerRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    consumerRepository = new ConsumerRepository<TestEvent>();
    eventProcessor1 = new DummyEventProcessor(new Sequence());
    eventProcessor2 = new DummyEventProcessor(new Sequence());
    eventProcessor1.run();
    eventProcessor2.run();
    handler1 = new SleepingEventHandler();
    handler2 = new SleepingEventHandler();
    barrier1 = new DummySequenceBarrier();
    barrier2 = new DummySequenceBarrier();
}
Also used : SleepingEventHandler(com.lmax.disruptor.dsl.stubs.SleepingEventHandler) DummyEventProcessor(com.lmax.disruptor.support.DummyEventProcessor) DummySequenceBarrier(com.lmax.disruptor.support.DummySequenceBarrier) TestEvent(com.lmax.disruptor.support.TestEvent) Sequence(com.lmax.disruptor.Sequence) Before(org.junit.Before)

Aggregations

DummyEventProcessor (com.lmax.disruptor.support.DummyEventProcessor)3 Test (org.junit.Test)2 Sequence (com.lmax.disruptor.Sequence)1 SleepingEventHandler (com.lmax.disruptor.dsl.stubs.SleepingEventHandler)1 DummySequenceBarrier (com.lmax.disruptor.support.DummySequenceBarrier)1 StubEvent (com.lmax.disruptor.support.StubEvent)1 TestEvent (com.lmax.disruptor.support.TestEvent)1 Before (org.junit.Before)1