Search in sources :

Example 16 with DelayedEventHandler

use of com.lmax.disruptor.dsl.stubs.DelayedEventHandler 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)

Example 17 with DelayedEventHandler

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

the class DisruptorTest method shouldBlockProducerUntilAllEventProcessorsHaveAdvanced.

@Test
public void shouldBlockProducerUntilAllEventProcessorsHaveAdvanced() throws Exception {
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    disruptor.handleEventsWith(delayedEventHandler);
    final RingBuffer<TestEvent> ringBuffer = disruptor.start();
    delayedEventHandler.awaitStart();
    final StubPublisher stubPublisher = new StubPublisher(ringBuffer);
    try {
        executor.newThread(stubPublisher).start();
        assertProducerReaches(stubPublisher, 4, true);
        delayedEventHandler.processEvent();
        delayedEventHandler.processEvent();
        delayedEventHandler.processEvent();
        delayedEventHandler.processEvent();
        delayedEventHandler.processEvent();
        assertProducerReaches(stubPublisher, 5, false);
    } finally {
        stubPublisher.halt();
    }
}
Also used : TestEvent(com.lmax.disruptor.support.TestEvent) StubPublisher(com.lmax.disruptor.dsl.stubs.StubPublisher) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Aggregations

DelayedEventHandler (com.lmax.disruptor.dsl.stubs.DelayedEventHandler)17 Test (org.junit.Test)14 EventHandlerStub (com.lmax.disruptor.dsl.stubs.EventHandlerStub)8 TestEvent (com.lmax.disruptor.support.TestEvent)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 TestWorkHandler (com.lmax.disruptor.dsl.stubs.TestWorkHandler)5 BatchEventProcessor (com.lmax.disruptor.BatchEventProcessor)4 SequenceBarrier (com.lmax.disruptor.SequenceBarrier)2 EventProcessor (com.lmax.disruptor.EventProcessor)1 Sequence (com.lmax.disruptor.Sequence)1 StubPublisher (com.lmax.disruptor.dsl.stubs.StubPublisher)1 After (org.junit.After)1