return null; }).when(mockTransactionManager).executeInTransaction(any(Runnable.class)); eventBus = EmbeddedEventStore.builder().storageEngine(new InMemoryEventStorageEngine()).build(); sleepInstructions = new ArrayList<>(); TrackingEventProcessor.Builder eventProcessorBuilder =
@Override public Configurer configureEmbeddedEventStore(Function<Configuration, EventStorageEngine> storageEngineBuilder) { return configureEventStore(c -> { MessageMonitor<Message<?>> monitor = messageMonitorFactoryComponent.get().apply(EmbeddedEventStore.class, "eventStore"); EmbeddedEventStore eventStore = EmbeddedEventStore.builder() .storageEngine(storageEngineBuilder.apply(c)) .messageMonitor(monitor) .build(); c.onShutdown(eventStore::shutDown); return eventStore; }); }
/** * Instantiate a Builder to be able to create an {@link EmbeddedEventStore}. * <p> * The following configurable fields have defaults: * <ul> * <li>The {@link MessageMonitor} is defaulted to a {@link NoOpMessageMonitor}.</li> * <li>The {@code cachedEvents} is defaulted to {@code 10000}.</li> * <li>The {@code fetchDelay} is defaulted to {@code 1000}.</li> * <li>The {@code cleanupDelay} is defaulted to {@code 10000}.</li> * <li>The {@link TimeUnit} is defaulted to {@link TimeUnit#MILLISECONDS}.</li> * <li>The {@link ThreadFactory} is defaulted to {@link AxonThreadFactory} with {@link ThreadGroup} {@link * EmbeddedEventStore#THREAD_GROUP}.</li> * <li>The {@code optimizeEventConsumption} is defaulted to {@code true}.</li> * </ul> * The {@link EventStorageEngine} is a <b>hard requirement</b> and as such should be provided. * * @return a Builder to be able to create a {@link EmbeddedEventStore} */ public static Builder builder() { return new Builder(); }
@Override public Configurer configureEmbeddedEventStore(Function<Configuration, EventStorageEngine> storageEngineBuilder) { return configureEventStore(c -> { MessageMonitor<Message<?>> monitor = messageMonitorFactoryComponent.get().apply(EmbeddedEventStore.class, "eventStore"); EmbeddedEventStore eventStore = EmbeddedEventStore.builder() .storageEngine(storageEngineBuilder.apply(c)) .messageMonitor(monitor) .build(); c.onShutdown(eventStore::shutDown); return eventStore; }); }
@Qualifier("eventStore") @Bean(name = "eventBus") @ConditionalOnMissingBean(EventBus.class) @ConditionalOnBean(EventStorageEngine.class) public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) { return EmbeddedEventStore.builder() .storageEngine(storageEngine) .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore")) .build(); }
Thread[] writerThreads = storeEvents(threadCount, eventsPerThread, inverseRollbackRate); EmbeddedEventStore embeddedEventStore = EmbeddedEventStore.builder() .storageEngine(testSubject) .cachedEvents(20) .fetchDelay(100) .cleanupDelay(1000) .build(); TrackingEventStream readEvents = embeddedEventStore.openStream(null); int counter = 0;
protected AbstractEventStoreBenchmark(EventStorageEngine storageEngine, int threadCount, int batchSize, int batchCount) { this.eventStore = EmbeddedEventStore.builder() .storageEngine(this.storageEngine = storageEngine) .build(); this.threadCount = threadCount; this.batchSize = batchSize;
@Before public void setUp() { aggregateIdentifier = UUID.randomUUID().toString(); commandBus = SimpleCommandBus.builder().build(); eventStore = spy(EmbeddedEventStore.builder().storageEngine(new InMemoryEventStorageEngine()).build()); eventStore.publish(new GenericDomainEventMessage<>("test", aggregateIdentifier, 0, new AggregateCreatedEvent(aggregateIdentifier), null)); reset(eventStore); reportErrorCallback = (commandMessage, commandResultMessage) -> { if (commandResultMessage.isExceptional()) { Throwable cause = commandResultMessage.exceptionResult(); throw new RuntimeException("Failure", cause); } }; expectErrorCallback = (commandMessage, commandResultMessage) -> { if (commandResultMessage.isExceptional()) { Throwable cause = commandResultMessage.exceptionResult(); assertEquals("Mock exception", cause.getMessage()); } else { fail("Expected this command to fail"); } }; }
/** * Instantiate a Builder to be able to create an {@link EmbeddedEventStore}. * <p> * The following configurable fields have defaults: * <ul> * <li>The {@link MessageMonitor} is defaulted to a {@link NoOpMessageMonitor}.</li> * <li>The {@code cachedEvents} is defaulted to {@code 10000}.</li> * <li>The {@code fetchDelay} is defaulted to {@code 1000}.</li> * <li>The {@code cleanupDelay} is defaulted to {@code 10000}.</li> * <li>The {@link TimeUnit} is defaulted to {@link TimeUnit#MILLISECONDS}.</li> * <li>The {@link ThreadFactory} is defaulted to {@link AxonThreadFactory} with {@link ThreadGroup} {@link * EmbeddedEventStore#THREAD_GROUP}.</li> * <li>The {@code optimizeEventConsumption} is defaulted to {@code true}.</li> * </ul> * The {@link EventStorageEngine} is a <b>hard requirement</b> and as such should be provided. * * @return a Builder to be able to create a {@link EmbeddedEventStore} */ public static Builder builder() { return new Builder(); }
@Test(timeout = 10000) public void testInsertConcurrentlyAndReadUsingBlockingStreams() throws Exception { int threadCount = 10, eventsPerThread = 100, inverseRollbackRate = 2, rollbacksPerThread = (eventsPerThread + inverseRollbackRate - 1) / inverseRollbackRate; int expectedEventCount = threadCount * eventsPerThread - rollbacksPerThread * threadCount; Thread[] writerThreads = storeEvents(threadCount, eventsPerThread, inverseRollbackRate); EmbeddedEventStore embeddedEventStore = EmbeddedEventStore.builder().storageEngine(testSubject).build(); TrackingEventStream readEvents = embeddedEventStore.openStream(null); int counter = 0; while (counter < expectedEventCount) { if (readEvents.hasNextAvailable()) { counter++; } } for (Thread thread : writerThreads) { thread.join(); } assertEquals("The actually read list of events is shorted than the expected value", expectedEventCount, counter); }
@Before public void setUp() { tokenStore = spy(new InMemoryTokenStore()); mockHandler = mock(EventMessageHandler.class); when(mockHandler.canHandle(any())).thenReturn(true); eventHandlerInvoker = SimpleEventHandlerInvoker.builder() .eventHandlers(singletonList(mockHandler)) .sequencingPolicy(event -> { if (event instanceof DomainEventMessage) { return ((DomainEventMessage) event) .getSequenceNumber(); } return event.getIdentifier(); }) .build(); eventBus = EmbeddedEventStore.builder().storageEngine(new InMemoryEventStorageEngine()).build(); // A processor config, with a policy which guarantees segmenting by using the sequence number. configureProcessor(TrackingEventProcessorConfiguration.forParallelProcessing(2)); }
@SuppressWarnings("unchecked") @Before public void setUp() { eventStore = spy(EmbeddedEventStore.builder().storageEngine(new InMemoryEventStorageEngine()).build()); Repository<MyAggregate> myAggregateRepository = EventSourcingRepository.builder(MyAggregate.class) .eventStore(eventStore) .build(); CommandBus commandBus = SimpleCommandBus.builder().build(); commandGateway = DefaultCommandGateway.builder().commandBus(commandBus).build(); AggregateAnnotationCommandHandler<MyAggregate> myAggregateCommandHandler = AggregateAnnotationCommandHandler.<MyAggregate>builder() .aggregateType(MyAggregate.class) .repository(myAggregateRepository) .build(); myAggregateCommandHandler.subscribe(commandBus); }
@Before public void setUp() { EventStore eventStore = spy(EmbeddedEventStore.builder() .storageEngine(new InMemoryEventStorageEngine()) .build()); Configurer configurer = DefaultConfigurer.defaultConfiguration(); configurer.eventProcessing() .usingSubscribingEventProcessors() .registerSaga(MySaga.class); configuration = configurer.configureEventStore(c -> eventStore) .configureAggregate(MyAggregate.class) .registerComponent(DeadlineManager.class, this::buildDeadlineManager) .start(); published = new CopyOnWriteArrayList<>(); configuration.eventBus().subscribe(msgs -> msgs.forEach(msg -> published.add(msg.getPayload()))); }
@Before public void setUp() { mockHandler = mock(EventMessageHandler.class); eventHandlerInvoker = SimpleEventHandlerInvoker.builder().eventHandlers(mockHandler).build(); eventBus = EmbeddedEventStore.builder().storageEngine(new InMemoryEventStorageEngine()).build(); testSubject = SubscribingEventProcessor.builder() .name("test") .eventHandlerInvoker(eventHandlerInvoker) .messageSource(eventBus) .build(); }
@Before public void setUp() { this.commandBus = SimpleCommandBus.builder().build(); eventStore = spy(EmbeddedEventStore.builder().storageEngine(new InMemoryEventStorageEngine()).build()); EventSourcingRepository<StubAggregate> repository = EventSourcingRepository.builder(StubAggregate.class) .eventStore(eventStore) .build(); StubAggregateCommandHandler target = new StubAggregateCommandHandler(); target.setRepository(repository); target.setEventBus(eventStore); new AnnotationCommandHandlerAdapter<>(target).subscribe(commandBus); }
@Qualifier("eventStore") @Bean(name = "eventBus") @ConditionalOnMissingBean(EventBus.class) @ConditionalOnBean(EventStorageEngine.class) public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) { return EmbeddedEventStore.builder() .storageEngine(storageEngine) .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore")) .build(); }