Search in sources :

Example 1 with TestEvent

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

the class FatalExceptionHandlerTest method shouldHandleFatalException.

@Test
public void shouldHandleFatalException() {
    final Exception causeException = new Exception();
    final TestEvent event = new TestEvent();
    ExceptionHandler<Object> exceptionHandler = new FatalExceptionHandler();
    try {
        exceptionHandler.handleEventException(causeException, 0L, event);
    } catch (RuntimeException ex) {
        Assert.assertEquals(causeException, ex.getCause());
    }
}
Also used : TestEvent(com.lmax.disruptor.support.TestEvent) Test(org.junit.Test)

Example 2 with TestEvent

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

the class IgnoreExceptionHandlerTest method shouldHandleAndIgnoreException.

@Test
public void shouldHandleAndIgnoreException() {
    final Exception ex = new Exception();
    final TestEvent event = new TestEvent();
    ExceptionHandler<Object> exceptionHandler = new IgnoreExceptionHandler();
    exceptionHandler.handleEventException(ex, 0L, event);
}
Also used : TestEvent(com.lmax.disruptor.support.TestEvent) Test(org.junit.Test)

Example 3 with TestEvent

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

Example 4 with TestEvent

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

the class DisruptorTest method shouldWaitUntilAllFirstEventProcessorsProcessEventBeforeMakingItAvailableToDependentEventProcessors.

@Test
public void shouldWaitUntilAllFirstEventProcessorsProcessEventBeforeMakingItAvailableToDependentEventProcessors() throws Exception {
    DelayedEventHandler eventHandler1 = createDelayedEventHandler();
    CountDownLatch countDownLatch = new CountDownLatch(2);
    EventHandler<TestEvent> eventHandler2 = new EventHandlerStub<TestEvent>(countDownLatch);
    disruptor.handleEventsWith(eventHandler1).then(eventHandler2);
    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, eventHandler1);
}
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 5 with TestEvent

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

the class DisruptorTest method shouldSupportCustomProcessorsAsDependencies.

@Test
public void shouldSupportCustomProcessorsAsDependencies() throws Exception {
    RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    CountDownLatch countDownLatch = new CountDownLatch(2);
    EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
    final BatchEventProcessor<TestEvent> processor = new BatchEventProcessor<TestEvent>(ringBuffer, ringBuffer.newBarrier(), delayedEventHandler);
    disruptor.handleEventsWith(processor).then(handlerWithBarrier);
    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
Also used : TestEvent(com.lmax.disruptor.support.TestEvent) EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) 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