@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfHandlerUsedWithAndIsNotAlreadyConsuming() throws Exception { final DelayedEventHandler handler1 = createDelayedEventHandler(); final DelayedEventHandler handler2 = createDelayedEventHandler(); disruptor.handleEventsWith(handler1); disruptor.after(handler1).and(handler2); }
@Test(expected = IllegalArgumentException.class) public void shouldTrackEventHandlersByIdentityNotEquality() throws Exception { EvilEqualsEventHandler handler1 = new EvilEqualsEventHandler(); EvilEqualsEventHandler handler2 = new EvilEqualsEventHandler(); disruptor.handleEventsWith(handler1); // handler2.equals(handler1) but it hasn't yet been registered so should throw exception. disruptor.after(handler2); }
@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(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); }
@Test public void shouldAllowSpecifyingSpecificEventProcessorsToWaitFor() throws Exception { DelayedEventHandler handler1 = createDelayedEventHandler(); DelayedEventHandler handler2 = createDelayedEventHandler(); CountDownLatch countDownLatch = new CountDownLatch(2); EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub(countDownLatch); disruptor.handleEventsWith(handler1, handler2); disruptor.after(handler1, handler2).handleEventsWith(handlerWithBarrier); ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, handler1, handler2); }
@Test public void shouldWaitOnAllProducersJoinedByAnd() throws Exception { DelayedEventHandler handler1 = createDelayedEventHandler(); DelayedEventHandler handler2 = createDelayedEventHandler(); CountDownLatch countDownLatch = new CountDownLatch(2); EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub(countDownLatch); disruptor.handleEventsWith(handler1, handler2); disruptor.after(handler1).and(handler2).handleEventsWith(handlerWithBarrier); ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, handler1, handler2); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfHandlerIsNotAlreadyConsuming() throws Exception { disruptor.after(createDelayedEventHandler()).handleEventsWith(createDelayedEventHandler()); }