}
@SuppressWarnings("unchecked")
@Test
public void testCallbackInvokedBeforeUnitOfWorkCleanup() throws Throwable {
CommandHandlerInterceptor mockHandlerInterceptor = mock(CommandHandlerInterceptor.class);
CommandDispatchInterceptor mockDispatchInterceptor = mock(CommandDispatchInterceptor.class);
when(mockDispatchInterceptor.handle(isA(CommandMessage.class))).thenAnswer(new Parameter(0));
ExecutorService customExecutor = Executors.newCachedThreadPool();
testSubject = new DisruptorCommandBus(
inMemoryEventStore, eventBus,
new DisruptorConfiguration().setInvokerInterceptors(Arrays.asList(mockHandlerInterceptor))
.setDispatchInterceptors(Arrays.asList(mockDispatchInterceptor))
.setBufferSize(8)
.setProducerType(ProducerType.SINGLE)
.setWaitStrategy(new SleepingWaitStrategy())
.setExecutor(customExecutor)
.setInvokerThreadCount(2)
.setPublisherThreadCount(3)
);
testSubject.subscribe(StubCommand.class.getName(), stubHandler);
stubHandler.setRepository(testSubject
.createRepository(new GenericAggregateFactory<StubAggregate>(StubAggregate.class)));
final UnitOfWorkListener mockUnitOfWorkListener = mock(UnitOfWorkListener.class);
when(mockUnitOfWorkListener.onEventRegistered(isA(UnitOfWork.class), any(EventMessage.class)))
.thenAnswer(new ReturnsArgumentAt(1));
when(mockHandlerInterceptor.handle(any(CommandMessage.class),
any(UnitOfWork.class),
any(InterceptorChain.class)))
.thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {