Search in sources :

Example 16 with TestEvent

use of com.lmax.disruptor.support.TestEvent 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 TestEvent

use of com.lmax.disruptor.support.TestEvent 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

TestEvent (com.lmax.disruptor.support.TestEvent)17 Test (org.junit.Test)16 CountDownLatch (java.util.concurrent.CountDownLatch)10 EventHandlerStub (com.lmax.disruptor.dsl.stubs.EventHandlerStub)9 DelayedEventHandler (com.lmax.disruptor.dsl.stubs.DelayedEventHandler)8 BatchEventProcessor (com.lmax.disruptor.BatchEventProcessor)7 Sequence (com.lmax.disruptor.Sequence)3 SleepingEventHandler (com.lmax.disruptor.dsl.stubs.SleepingEventHandler)3 EventProcessor (com.lmax.disruptor.EventProcessor)2 SequenceBarrier (com.lmax.disruptor.SequenceBarrier)2 RingBuffer (com.lmax.disruptor.RingBuffer)1 TimeoutException (com.lmax.disruptor.TimeoutException)1 StubPublisher (com.lmax.disruptor.dsl.stubs.StubPublisher)1 TestWorkHandler (com.lmax.disruptor.dsl.stubs.TestWorkHandler)1 DummyEventProcessor (com.lmax.disruptor.support.DummyEventProcessor)1 DummySequenceBarrier (com.lmax.disruptor.support.DummySequenceBarrier)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 Before (org.junit.Before)1