@Test(expected = IllegalStateException.class) public void shouldThrowExceptionIfStartIsCalledTwice() throws Exception { executor.ignoreExecutions(); disruptor.handleEventsWith(new SleepingEventHandler()); disruptor.start(); disruptor.start(); }
@Test(expected = IllegalStateException.class) public void shouldThrowExceptionWhenAddingEventProcessorsAfterTheProducerBarrierHasBeenCreated() throws Exception { executor.ignoreExecutions(); disruptor.handleEventsWith(new SleepingEventHandler()); disruptor.start(); disruptor.handleEventsWith(new SleepingEventHandler()); }
@Test public void shouldCreateEventProcessorGroupForFirstEventProcessors() throws Exception { executor.ignoreExecutions(); final EventHandler<TestEvent> eventHandler1 = new SleepingEventHandler(); EventHandler<TestEvent> eventHandler2 = new SleepingEventHandler(); final EventHandlerGroup<TestEvent> eventHandlerGroup = disruptor.handleEventsWith(eventHandler1, eventHandler2); disruptor.start(); assertNotNull(eventHandlerGroup); assertThat(Integer.valueOf(executor.getExecutionCount()), equalTo(Integer.valueOf(2))); }
private TestEvent publishEvent() { if (ringBuffer == null) { ringBuffer = disruptor.start(); } disruptor.publishEvent( new EventTranslator<TestEvent>() { @Override public TestEvent translateTo(final TestEvent event, final long sequence) { lastPublishedEvent = event; return event; } }); return lastPublishedEvent; }
@Test public void shouldBlockProducerUntilAllEventProcessorsHaveAdvanced() throws Exception { final DelayedEventHandler delayedEventHandler = createDelayedEventHandler(); disruptor.handleEventsWith(delayedEventHandler); final RingBuffer<TestEvent> ringBuffer = disruptor.start(); final StubPublisher stubPublisher = new StubPublisher(ringBuffer); try { executor.execute(stubPublisher); assertProducerReaches(stubPublisher, 4, true); delayedEventHandler.processEvent(); delayedEventHandler.processEvent(); delayedEventHandler.processEvent(); delayedEventHandler.processEvent(); delayedEventHandler.processEvent(); assertProducerReaches(stubPublisher, 5, false); } finally { stubPublisher.halt(); } }