Search in sources :

Example 11 with TestEvent

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

the class DisruptorTest method shouldSetSequenceForWorkProcessorIfAddedAfterPublish.

@Test
public void shouldSetSequenceForWorkProcessorIfAddedAfterPublish() throws Exception {
    RingBuffer<TestEvent> rb = disruptor.getRingBuffer();
    TestWorkHandler wh1 = createTestWorkHandler();
    TestWorkHandler wh2 = createTestWorkHandler();
    TestWorkHandler wh3 = createTestWorkHandler();
    rb.publish(rb.next());
    rb.publish(rb.next());
    rb.publish(rb.next());
    rb.publish(rb.next());
    rb.publish(rb.next());
    rb.publish(rb.next());
    disruptor.handleEventsWithWorkerPool(wh1, wh2, wh3);
    assertThat(disruptor.getRingBuffer().getMinimumGatingSequence(), is(5L));
}
Also used : TestWorkHandler(com.lmax.disruptor.dsl.stubs.TestWorkHandler) TestEvent(com.lmax.disruptor.support.TestEvent) Test(org.junit.Test)

Example 12 with TestEvent

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

the class DisruptorTest method shouldSupportCustomProcessorsAndHandlersAsDependencies.

@Test
public void shouldSupportCustomProcessorsAndHandlersAsDependencies() throws Exception {
    final DelayedEventHandler delayedEventHandler1 = createDelayedEventHandler();
    final DelayedEventHandler delayedEventHandler2 = createDelayedEventHandler();
    disruptor.handleEventsWith(delayedEventHandler1);
    RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
    CountDownLatch countDownLatch = new CountDownLatch(2);
    EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
    final SequenceBarrier sequenceBarrier = disruptor.after(delayedEventHandler1).asSequenceBarrier();
    final BatchEventProcessor<TestEvent> processor = new BatchEventProcessor<TestEvent>(ringBuffer, sequenceBarrier, delayedEventHandler2);
    disruptor.after(delayedEventHandler1).and(processor).handleEventsWith(handlerWithBarrier);
    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler1, delayedEventHandler2);
}
Also used : TestEvent(com.lmax.disruptor.support.TestEvent) EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) SequenceBarrier(com.lmax.disruptor.SequenceBarrier) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) CountDownLatch(java.util.concurrent.CountDownLatch) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Example 13 with TestEvent

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

the class DisruptorTest method shouldSupportHandlersAsDependenciesToCustomProcessors.

@Test
public void shouldSupportHandlersAsDependenciesToCustomProcessors() throws Exception {
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    disruptor.handleEventsWith(delayedEventHandler);
    RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
    CountDownLatch countDownLatch = new CountDownLatch(2);
    EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
    final SequenceBarrier sequenceBarrier = disruptor.after(delayedEventHandler).asSequenceBarrier();
    final BatchEventProcessor<TestEvent> processor = new BatchEventProcessor<TestEvent>(ringBuffer, sequenceBarrier, handlerWithBarrier);
    disruptor.handleEventsWith(processor);
    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
Also used : TestEvent(com.lmax.disruptor.support.TestEvent) EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) SequenceBarrier(com.lmax.disruptor.SequenceBarrier) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) CountDownLatch(java.util.concurrent.CountDownLatch) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Example 14 with TestEvent

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

the class DisruptorTest method shouldAllowSpecifyingSpecificEventProcessorsToWaitFor.

@Test
public void shouldAllowSpecifyingSpecificEventProcessorsToWaitFor() throws Exception {
    DelayedEventHandler handler1 = createDelayedEventHandler();
    DelayedEventHandler handler2 = createDelayedEventHandler();
    CountDownLatch countDownLatch = new CountDownLatch(2);
    EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
    disruptor.handleEventsWith(handler1, handler2);
    disruptor.after(handler1, handler2).handleEventsWith(handlerWithBarrier);
    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, handler1, handler2);
}
Also used : EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) TestEvent(com.lmax.disruptor.support.TestEvent) CountDownLatch(java.util.concurrent.CountDownLatch) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Example 15 with TestEvent

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

the class DisruptorTest method shouldWaitOnAllProducersJoinedByAnd.

@Test
public void shouldWaitOnAllProducersJoinedByAnd() throws Exception {
    DelayedEventHandler handler1 = createDelayedEventHandler();
    DelayedEventHandler handler2 = createDelayedEventHandler();
    CountDownLatch countDownLatch = new CountDownLatch(2);
    EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
    disruptor.handleEventsWith(handler1);
    final EventHandlerGroup<TestEvent> handler2Group = disruptor.handleEventsWith(handler2);
    disruptor.after(handler1).and(handler2Group).handleEventsWith(handlerWithBarrier);
    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, handler1, handler2);
}
Also used : EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) TestEvent(com.lmax.disruptor.support.TestEvent) CountDownLatch(java.util.concurrent.CountDownLatch) 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