@Test public void testDisruptorCommandBusRepositoryNotAvailableOutsideOfInvokerThread() { DisruptorCommandBus commandBus = new DisruptorCommandBus(eventStore, eventBus); Repository<Aggregate> repository = commandBus.createRepository(new GenericAggregateFactory<Aggregate>(Aggregate.class)); AggregateAnnotationCommandHandler<Aggregate> handler = new AggregateAnnotationCommandHandler<Aggregate>(Aggregate.class, repository); AggregateAnnotationCommandHandler.subscribe(handler, commandBus); DefaultCommandGateway gateway = new DefaultCommandGateway(commandBus); // Create the aggregate String aggregateId = "" + System.currentTimeMillis(); gateway.sendAndWait(new CreateCommandAndEvent(aggregateId)); // Load the aggretate from the repository -- from "worker" thread UnitOfWork uow = DefaultUnitOfWork.startAndGet(); try { Aggregate aggregate = repository.load(aggregateId); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { assertTrue(e.getMessage().contains("DisruptorCommandBus")); } finally { uow.rollback(); } }