Search in sources :

Example 11 with EventHandlerStub

use of com.lmax.disruptor.dsl.stubs.EventHandlerStub in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldHonourDependenciesForCustomProcessors.

@Test
public void shouldHonourDependenciesForCustomProcessors() throws Exception {
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    disruptor.handleEventsWith(delayedEventHandler).then(new EventProcessorFactory<TestEvent>() {

        @Override
        public EventProcessor createEventProcessor(final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences) {
            assertSame("Should have had a barrier sequence", 1, barrierSequences.length);
            return new BatchEventProcessor<TestEvent>(disruptor.getRingBuffer(), ringBuffer.newBarrier(barrierSequences), eventHandler);
        }
    });
    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
Also used : EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) TestEvent(com.lmax.disruptor.support.TestEvent) EventProcessor(com.lmax.disruptor.EventProcessor) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) Sequence(com.lmax.disruptor.Sequence) CountDownLatch(java.util.concurrent.CountDownLatch) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Aggregations

EventHandlerStub (com.lmax.disruptor.dsl.stubs.EventHandlerStub)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 Test (org.junit.Test)11 TestEvent (com.lmax.disruptor.support.TestEvent)9 DelayedEventHandler (com.lmax.disruptor.dsl.stubs.DelayedEventHandler)8 BatchEventProcessor (com.lmax.disruptor.BatchEventProcessor)5 EventProcessor (com.lmax.disruptor.EventProcessor)2 Sequence (com.lmax.disruptor.Sequence)2 SequenceBarrier (com.lmax.disruptor.SequenceBarrier)2