Search in sources :

Example 6 with DelayedEventHandler

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

the class DisruptorTest method shouldThrowTimeoutExceptionIfShutdownDoesNotCompleteNormally.

@Test(expected = TimeoutException.class, timeout = 2000)
public void shouldThrowTimeoutExceptionIfShutdownDoesNotCompleteNormally() throws Exception {
    //Given
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    disruptor.handleEventsWith(delayedEventHandler);
    publishEvent();
    //When
    disruptor.shutdown(1, SECONDS);
//Then
}
Also used : DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Example 7 with DelayedEventHandler

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

the class DisruptorTest method shouldAllowChainingEventHandlersWithSuperType.

@Test
public void shouldAllowChainingEventHandlersWithSuperType() throws Exception {
    final CountDownLatch latch = new CountDownLatch(2);
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    final EventHandler<Object> objectHandler = new EventHandlerStub<Object>(latch);
    disruptor.handleEventsWith(delayedEventHandler).then(objectHandler);
    ensureTwoEventsProcessedAccordingToDependencies(latch, delayedEventHandler);
}
Also used : EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) CountDownLatch(java.util.concurrent.CountDownLatch) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Example 8 with DelayedEventHandler

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

the class DisruptorTest method shouldSupportUsingWorkerPoolAsDependency.

@Test
public void shouldSupportUsingWorkerPoolAsDependency() throws Exception {
    final TestWorkHandler workHandler1 = createTestWorkHandler();
    final TestWorkHandler workHandler2 = createTestWorkHandler();
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    disruptor.handleEventsWithWorkerPool(workHandler1, workHandler2).then(delayedEventHandler);
    publishEvent();
    publishEvent();
    assertThat(disruptor.getBarrierFor(delayedEventHandler).getCursor(), equalTo(-1L));
    workHandler2.processEvent();
    workHandler1.processEvent();
    delayedEventHandler.processEvent();
}
Also used : TestWorkHandler(com.lmax.disruptor.dsl.stubs.TestWorkHandler) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Example 9 with DelayedEventHandler

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

the class DisruptorTest method ensureTwoEventsProcessedAccordingToDependencies.

private void ensureTwoEventsProcessedAccordingToDependencies(final CountDownLatch countDownLatch, final DelayedEventHandler... dependencies) throws InterruptedException, BrokenBarrierException {
    publishEvent();
    publishEvent();
    for (DelayedEventHandler dependency : dependencies) {
        assertThatCountDownLatchEquals(countDownLatch, 2L);
        dependency.processEvent();
        dependency.processEvent();
    }
    assertThatCountDownLatchIsZero(countDownLatch);
}
Also used : DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler)

Example 10 with DelayedEventHandler

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

the class DisruptorTest method shouldSupportUsingWorkerPoolWithADependency.

@Test
public void shouldSupportUsingWorkerPoolWithADependency() throws Exception {
    final TestWorkHandler workHandler1 = createTestWorkHandler();
    final TestWorkHandler workHandler2 = createTestWorkHandler();
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    disruptor.handleEventsWith(delayedEventHandler).thenHandleEventsWithWorkerPool(workHandler1, workHandler2);
    publishEvent();
    publishEvent();
    delayedEventHandler.processEvent();
    delayedEventHandler.processEvent();
    workHandler1.processEvent();
    workHandler2.processEvent();
}
Also used : TestWorkHandler(com.lmax.disruptor.dsl.stubs.TestWorkHandler) 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