From fdd0586a34e0eb02fbd9616d147d579cf4f2eb5f Mon Sep 17 00:00:00 2001 From: loong10k <20489781+loong10k@users.noreply.github.com> Date: Wed, 18 Nov 2026 06:52:17 +0800 Subject: [PATCH] fix: restore Disruptor startup and routing on Boot 2.6 --- .github/workflows/ci-main-boot26.yml | 46 ++++++++++++ README.md | 4 +- README.zh-CN.md | 4 +- docs/handler-chain.md | 29 ++++++++ pom.xml | 7 +- .../boot/DisruptorAutoConfiguration.java | 50 ++++++------- .../spring/boot/DisruptorProperties.java | 2 +- .../boot/RingBufferAutoConfiguration.java | 10 +-- .../context/DisruptorApplicationContext.java | 4 +- .../context/DisruptorEventAwareProcessor.java | 12 ++-- .../event/EventPublicationInterceptor.java | 6 +- .../spring/boot/DemoApplicationTests.java | 44 +++++++++--- .../spring/boot/DisruptorPublisherTests.java | 34 +++++++++ .../spring/boot/DisruptorRoutingTests.java | 71 +++++++++++++++++++ 14 files changed, 263 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/ci-main-boot26.yml create mode 100644 docs/handler-chain.md create mode 100644 src/test/java/org/apache/rocketmq/spring/boot/DisruptorPublisherTests.java create mode 100644 src/test/java/org/apache/rocketmq/spring/boot/DisruptorRoutingTests.java diff --git a/.github/workflows/ci-main-boot26.yml b/.github/workflows/ci-main-boot26.yml new file mode 100644 index 0000000..67c05e5 --- /dev/null +++ b/.github/workflows/ci-main-boot26.yml @@ -0,0 +1,46 @@ +name: CI main Boot 2.6 + +on: + workflow_dispatch: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: read + +jobs: + verify: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout starter + uses: actions/checkout@v4 + with: + path: starter + - name: Set up JDK 8 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '8' + cache: maven + - name: Checkout matching Disruptor extension + uses: actions/checkout@v4 + with: + repository: easy-4-java/disruptor-extension + ref: e9f81a75c8b4c8316dde4e4f852a092bffe59179 + path: disruptor-extension-source + - name: Install matching extension snapshot + working-directory: disruptor-extension-source + run: mvn -B --no-transfer-progress clean install + - name: Verify Boot 2.6 starter + working-directory: starter + run: mvn -B --no-transfer-progress clean verify + - name: Upload test reports + if: always() + uses: actions/upload-artifact@v4 + with: + name: boot26-test-reports + path: starter/target/surefire-reports + if-no-files-found: ignore diff --git a/README.md b/README.md index c1c3e09..c5d52b3 100644 --- a/README.md +++ b/README.md @@ -124,11 +124,13 @@ Then inject the auto-configured bean in your code: private WaitStrategy waitStrategy; ``` +For one-to-one handler routing on the Spring Boot 2.6 line, see the [handler chain example](docs/handler-chain.md). + ## 7. Configuration Reference ### 7.1 Config Prefix -`disruptor` +`spring.disruptor` ### 7.2 Configuration Items diff --git a/README.zh-CN.md b/README.zh-CN.md index 853bcc5..9289d41 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -124,11 +124,13 @@ public class Application { private WaitStrategy waitStrategy; ``` +Spring Boot 2.6 版本线的一对一处理器路由配置见[责任链示例](docs/handler-chain.md)。 + ## 7. 配置参考 ### 7.1 配置前缀 -`disruptor` +`spring.disruptor` ### 7.2 配置项 diff --git a/docs/handler-chain.md b/docs/handler-chain.md new file mode 100644 index 0000000..a19af31 --- /dev/null +++ b/docs/handler-chain.md @@ -0,0 +1,29 @@ +# Disruptor 责任链的一对一匹配(Spring Boot 2.6.x) + +`DisruptorEvent` 使用 `namespace/topic/tag` 生成路由;`namespace` 为空时,路由以 `/topic/tag` 开头。每条路由可以只指定一个 Spring Bean 名称,因此一个事件只进入对应的处理器。配置前缀是 `spring.disruptor`。 + +```yaml +spring: + disruptor: + enabled: true + handler-definitions: + - order: 0 + definition-map: + /orders/created: createdHandler + /orders/cancelled: cancelledHandler +``` + +```java +@Component("createdHandler") +@EventRule("/orders/created") +public class CreatedHandler implements DisruptorHandler { + @Override + public void doHandler(DisruptorEvent event, HandlerChain chain) { + // 处理订单创建事件 + } +} +``` + +发布事件时,设置 `topic=orders`、`tag=created`,其路由即 `/orders/created`。`cancelledHandler` 不会处理该事件。两个处理器的定义与上例相同,只需替换 Bean 名称、`@EventRule` 路由和业务逻辑。若设置了 `namespace`,路由规则也必须包含对应的命名空间前缀。 + +`DisruptorRoutingTests.routesEachOrderEventToItsConfiguredHandler` 使用真实分发器验证两条路由分别只调用各自的处理器。多个处理器串联时,`definition-map` 的值用逗号分隔 Bean 名称,例如 `createdHandler,auditHandler`,并由处理器按责任链协议继续调用 `chain.doHandler(event)`。 diff --git a/pom.xml b/pom.xml index a65a6aa..4df490c 100644 --- a/pom.xml +++ b/pom.xml @@ -162,9 +162,6 @@ maven-surefire-plugin ${maven-surefire-plugin.version} - - true - true @@ -175,7 +172,9 @@ **/*Test.java + **/*Tests.java + true **/TestBean.java @@ -361,7 +360,7 @@ 1.8 4.1 3.4.3 - 1.0.1.20260630-SNAPSHOT + 1.0.x.20260630-SNAPSHOT 3.0 1.6 3.1.1 diff --git a/src/main/java/com/lmax/disruptor/spring/boot/DisruptorAutoConfiguration.java b/src/main/java/com/lmax/disruptor/spring/boot/DisruptorAutoConfiguration.java index 35a144d..29f68a1 100644 --- a/src/main/java/com/lmax/disruptor/spring/boot/DisruptorAutoConfiguration.java +++ b/src/main/java/com/lmax/disruptor/spring/boot/DisruptorAutoConfiguration.java @@ -1,7 +1,7 @@ package com.lmax.disruptor.spring.boot; import java.util.ArrayList; -import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -11,6 +11,7 @@ import java.util.concurrent.ThreadFactory; import com.lmax.disruptor.*; +import com.lmax.disruptor.DisruptorTemplate; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,33 +26,32 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.OrderComparator; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import com.lmax.disruptor.dsl.Disruptor; import com.lmax.disruptor.dsl.EventHandlerGroup; import com.lmax.disruptor.dsl.ProducerType; -import com.lmax.disruptor.spring.boot.annotation.EventRule; -import com.lmax.disruptor.spring.boot.config.EventHandlerDefinition; -import com.lmax.disruptor.spring.boot.config.Ini; +import com.lmax.disruptor.annotation.EventRule; +import com.lmax.disruptor.config.EventHandlerDefinition; +import com.lmax.disruptor.config.Ini; import com.lmax.disruptor.spring.boot.context.DisruptorEventAwareProcessor; import com.lmax.disruptor.spring.boot.event.DisruptorApplicationEvent; -import com.lmax.disruptor.spring.boot.event.DisruptorEvent; -import com.lmax.disruptor.spring.boot.event.factory.DisruptorBindEventFactory; -import com.lmax.disruptor.spring.boot.event.factory.DisruptorEventThreadFactory; -import com.lmax.disruptor.spring.boot.event.handler.DisruptorEventDispatcher; -import com.lmax.disruptor.spring.boot.event.handler.DisruptorHandler; -import com.lmax.disruptor.spring.boot.event.handler.Nameable; -import com.lmax.disruptor.spring.boot.event.handler.chain.HandlerChainManager; -import com.lmax.disruptor.spring.boot.event.handler.chain.def.DefaultHandlerChainManager; -import com.lmax.disruptor.spring.boot.event.handler.chain.def.PathMatchingHandlerChainResolver; -import com.lmax.disruptor.spring.boot.event.translator.DisruptorEventOneArgTranslator; -import com.lmax.disruptor.spring.boot.event.translator.DisruptorEventThreeArgTranslator; -import com.lmax.disruptor.spring.boot.event.translator.DisruptorEventTwoArgTranslator; -import com.lmax.disruptor.spring.boot.hooks.DisruptorShutdownHook; -import com.lmax.disruptor.spring.boot.util.StringUtils; -import com.lmax.disruptor.spring.boot.util.WaitStrategys; +import com.lmax.disruptor.event.DisruptorEvent; +import com.lmax.disruptor.event.DisruptorEventFactory; +import com.lmax.disruptor.event.factory.DisruptorEventThreadFactory; +import com.lmax.disruptor.event.handler.DisruptorEventDispatcher; +import com.lmax.disruptor.event.handler.DisruptorHandler; +import com.lmax.disruptor.event.handler.Nameable; +import com.lmax.disruptor.event.handler.chain.HandlerChainManager; +import com.lmax.disruptor.event.handler.chain.def.DefaultHandlerChainManager; +import com.lmax.disruptor.event.handler.chain.def.PathMatchingHandlerChainResolver; +import com.lmax.disruptor.event.translator.DisruptorEventOneArgTranslator; +import com.lmax.disruptor.event.translator.DisruptorEventThreeArgTranslator; +import com.lmax.disruptor.event.translator.DisruptorEventTwoArgTranslator; +import com.lmax.disruptor.hooks.DisruptorShutdownHook; +import org.springframework.util.StringUtils; +import com.lmax.disruptor.util.WaitStrategys; import org.springframework.util.CollectionUtils; @@ -89,7 +89,7 @@ public ThreadFactory threadFactory() { @Bean @ConditionalOnMissingBean public EventFactory eventFactory() { - return new DisruptorBindEventFactory(); + return new DisruptorEventFactory(); } /* @@ -158,7 +158,7 @@ public List disruptorEventHandlers(DisruptorProperties } } // 进行排序 - Collections.sort(disruptorEventHandlers, new OrderComparator()); + disruptorEventHandlers.sort(Comparator.comparingInt(DisruptorEventDispatcher::getOrder)); return disruptorEventHandlers; } @@ -169,7 +169,7 @@ public List disruptorEventHandlers(DisruptorProperties protected DisruptorEventDispatcher createDisruptorEventHandler(EventHandlerDefinition handlerDefinition, Map> eventHandlers) { - if (StringUtils.isNotEmpty(handlerDefinition.getDefinitions())) { + if (StringUtils.hasLength(handlerDefinition.getDefinitions())) { handlerChainDefinitionMap.putAll(this.parseHandlerChainDefinitions(handlerDefinition.getDefinitions())); } else if (!CollectionUtils.isEmpty(handlerDefinition.getDefinitionMap())) { handlerChainDefinitionMap.putAll(handlerDefinition.getDefinitionMap()); @@ -262,7 +262,7 @@ public Disruptor disruptor( if (!ObjectUtils.isEmpty(disruptorEventHandlers)) { // 进行排序 - Collections.sort(disruptorEventHandlers, new OrderComparator()); + disruptorEventHandlers.sort(Comparator.comparingInt(DisruptorEventDispatcher::getOrder)); // 使用disruptor创建消费者组 EventHandlerGroup handlerGroup = null; @@ -310,7 +310,7 @@ public EventTranslatorThreeArg threeArgE } @Bean - public DisruptorTemplate disruptorTemplate(Disruptor disruptor, DisruptorEventOneArgTranslator oneArgEventTranslator) { + public DisruptorTemplate disruptorTemplate(Disruptor disruptor, EventTranslatorOneArg oneArgEventTranslator) { return new DisruptorTemplate(disruptor, oneArgEventTranslator); } diff --git a/src/main/java/com/lmax/disruptor/spring/boot/DisruptorProperties.java b/src/main/java/com/lmax/disruptor/spring/boot/DisruptorProperties.java index 3979519..2c1b4fb 100644 --- a/src/main/java/com/lmax/disruptor/spring/boot/DisruptorProperties.java +++ b/src/main/java/com/lmax/disruptor/spring/boot/DisruptorProperties.java @@ -5,7 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; -import com.lmax.disruptor.spring.boot.config.EventHandlerDefinition; +import com.lmax.disruptor.config.EventHandlerDefinition; @ConfigurationProperties(DisruptorProperties.PREFIX) public class DisruptorProperties { diff --git a/src/main/java/com/lmax/disruptor/spring/boot/RingBufferAutoConfiguration.java b/src/main/java/com/lmax/disruptor/spring/boot/RingBufferAutoConfiguration.java index 0faa19d..29fc101 100644 --- a/src/main/java/com/lmax/disruptor/spring/boot/RingBufferAutoConfiguration.java +++ b/src/main/java/com/lmax/disruptor/spring/boot/RingBufferAutoConfiguration.java @@ -20,10 +20,10 @@ import com.lmax.disruptor.SequenceBarrier; import com.lmax.disruptor.WaitStrategy; import com.lmax.disruptor.dsl.Disruptor; -import com.lmax.disruptor.spring.boot.event.DisruptorEvent; -import com.lmax.disruptor.spring.boot.event.factory.DisruptorBindEventFactory; -import com.lmax.disruptor.spring.boot.event.handler.DisruptorEventDispatcher; -import com.lmax.disruptor.spring.boot.util.WaitStrategys; +import com.lmax.disruptor.event.DisruptorEvent; +import com.lmax.disruptor.event.DisruptorEventFactory; +import com.lmax.disruptor.event.handler.DisruptorEventDispatcher; +import com.lmax.disruptor.util.WaitStrategys; @Configuration @ConditionalOnClass({ Disruptor.class }) @@ -47,7 +47,7 @@ public WaitStrategy waitStrategy() { @Bean @ConditionalOnMissingBean public EventFactory eventFactory() { - return new DisruptorBindEventFactory(); + return new DisruptorEventFactory(); } /** diff --git a/src/main/java/com/lmax/disruptor/spring/boot/context/DisruptorApplicationContext.java b/src/main/java/com/lmax/disruptor/spring/boot/context/DisruptorApplicationContext.java index ead7b9b..63a05ca 100644 --- a/src/main/java/com/lmax/disruptor/spring/boot/context/DisruptorApplicationContext.java +++ b/src/main/java/com/lmax/disruptor/spring/boot/context/DisruptorApplicationContext.java @@ -20,9 +20,9 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import com.lmax.disruptor.spring.boot.event.DisruptorEventPublisher; +import com.lmax.disruptor.event.DisruptorEventPublisher; import com.lmax.disruptor.spring.boot.event.DisruptorApplicationEvent; -import com.lmax.disruptor.spring.boot.event.DisruptorEvent; +import com.lmax.disruptor.event.DisruptorEvent; public class DisruptorApplicationContext implements ApplicationContextAware, DisruptorEventPublisher { diff --git a/src/main/java/com/lmax/disruptor/spring/boot/context/DisruptorEventAwareProcessor.java b/src/main/java/com/lmax/disruptor/spring/boot/context/DisruptorEventAwareProcessor.java index e25b07a..e90a9b5 100644 --- a/src/main/java/com/lmax/disruptor/spring/boot/context/DisruptorEventAwareProcessor.java +++ b/src/main/java/com/lmax/disruptor/spring/boot/context/DisruptorEventAwareProcessor.java @@ -20,7 +20,6 @@ import java.security.PrivilegedAction; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.Aware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -28,7 +27,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import com.lmax.disruptor.spring.boot.event.DisruptorEventPublisherAware; +import com.lmax.disruptor.event.DisruptorEventPublisherAware; public class DisruptorEventAwareProcessor implements ApplicationContextAware ,BeanPostProcessor, InitializingBean { @@ -95,12 +94,9 @@ public Object run() { } protected void invokeAwareInterfaces(Object bean) { - if (bean instanceof Aware) { - //扩展 DisruptorEventPublisherAware - if (bean instanceof DisruptorEventPublisherAware) { - DisruptorEventPublisherAware awareBean = (DisruptorEventPublisherAware) bean; - awareBean.setDisruptorEventPublisher( this.disruptorContext ); - } + if (bean instanceof DisruptorEventPublisherAware) { + DisruptorEventPublisherAware awareBean = (DisruptorEventPublisherAware) bean; + awareBean.setDisruptorEventPublisher(this.disruptorContext); } } diff --git a/src/main/java/com/lmax/disruptor/spring/boot/context/event/EventPublicationInterceptor.java b/src/main/java/com/lmax/disruptor/spring/boot/context/event/EventPublicationInterceptor.java index f50195b..b741729 100644 --- a/src/main/java/com/lmax/disruptor/spring/boot/context/event/EventPublicationInterceptor.java +++ b/src/main/java/com/lmax/disruptor/spring/boot/context/event/EventPublicationInterceptor.java @@ -18,13 +18,13 @@ import java.lang.reflect.Constructor; -import com.lmax.disruptor.spring.boot.event.DisruptorEventPublisher; -import com.lmax.disruptor.spring.boot.event.DisruptorEventPublisherAware; +import com.lmax.disruptor.event.DisruptorEventPublisher; +import com.lmax.disruptor.event.DisruptorEventPublisherAware; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.beans.factory.InitializingBean; -import com.lmax.disruptor.spring.boot.event.DisruptorEvent; +import com.lmax.disruptor.event.DisruptorEvent; public class EventPublicationInterceptor implements MethodInterceptor, DisruptorEventPublisherAware, InitializingBean { diff --git a/src/test/java/org/apache/rocketmq/spring/boot/DemoApplicationTests.java b/src/test/java/org/apache/rocketmq/spring/boot/DemoApplicationTests.java index 7d81927..105f0d5 100644 --- a/src/test/java/org/apache/rocketmq/spring/boot/DemoApplicationTests.java +++ b/src/test/java/org/apache/rocketmq/spring/boot/DemoApplicationTests.java @@ -1,18 +1,42 @@ package org.apache.rocketmq.spring.boot; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.lmax.disruptor.dsl.Disruptor; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; -@Configuration -@RunWith(SpringRunner.class) -@SpringBootTest +import java.util.concurrent.Executor; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@SpringBootTest(classes = DemoApplicationTests.TestApplication.class, + properties = {"spring.disruptor.enabled=true", "spring.config.name=disruptor-test"}) public class DemoApplicationTests { - @Test - public void contextLoads() { - } + @Autowired + private ApplicationContext applicationContext; + + @Test + public void contextLoadsWithTwoExecutors() { + assertNotNull(applicationContext.getBean(Disruptor.class)); + } + + @SpringBootConfiguration + @EnableAutoConfiguration + static class TestApplication { + + @Bean("applicationTaskExecutor") + Executor applicationTaskExecutor() { + return Runnable::run; + } + @Bean("taskScheduler") + Executor taskScheduler() { + return Runnable::run; + } + } } diff --git a/src/test/java/org/apache/rocketmq/spring/boot/DisruptorPublisherTests.java b/src/test/java/org/apache/rocketmq/spring/boot/DisruptorPublisherTests.java new file mode 100644 index 0000000..a8ca58f --- /dev/null +++ b/src/test/java/org/apache/rocketmq/spring/boot/DisruptorPublisherTests.java @@ -0,0 +1,34 @@ +package org.apache.rocketmq.spring.boot; + +import com.lmax.disruptor.event.DisruptorEventPublisher; +import com.lmax.disruptor.event.DisruptorEventPublisherAware; +import com.lmax.disruptor.spring.boot.context.DisruptorEventAwareProcessor; +import org.junit.jupiter.api.Test; +import org.springframework.context.ApplicationContext; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.mockito.Mockito.mock; + +class DisruptorPublisherTests { + + @Test + void injectsPublisherIntoAwareBean() throws Exception { + DisruptorEventAwareProcessor processor = new DisruptorEventAwareProcessor(); + processor.setApplicationContext(mock(ApplicationContext.class)); + processor.afterPropertiesSet(); + PublisherAwareBean bean = new PublisherAwareBean(); + + assertSame(bean, processor.postProcessBeforeInitialization(bean, "publisherAwareBean")); + assertNotNull(bean.publisher); + } + + static class PublisherAwareBean implements DisruptorEventPublisherAware { + private DisruptorEventPublisher publisher; + + @Override + public void setDisruptorEventPublisher(DisruptorEventPublisher publisher) { + this.publisher = publisher; + } + } +} diff --git a/src/test/java/org/apache/rocketmq/spring/boot/DisruptorRoutingTests.java b/src/test/java/org/apache/rocketmq/spring/boot/DisruptorRoutingTests.java new file mode 100644 index 0000000..dd07a3d --- /dev/null +++ b/src/test/java/org/apache/rocketmq/spring/boot/DisruptorRoutingTests.java @@ -0,0 +1,71 @@ +package org.apache.rocketmq.spring.boot; + +import com.lmax.disruptor.config.EventHandlerDefinition; +import com.lmax.disruptor.event.DisruptorEvent; +import com.lmax.disruptor.event.handler.DisruptorEventDispatcher; +import com.lmax.disruptor.event.handler.DisruptorHandler; +import com.lmax.disruptor.spring.boot.DisruptorAutoConfiguration; +import com.lmax.disruptor.spring.boot.DisruptorProperties; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class DisruptorRoutingTests { + + @Test + void routesEachOrderEventToItsConfiguredHandler() throws Exception { + DisruptorAutoConfiguration configuration = new DisruptorAutoConfiguration(); + AtomicInteger createdCalls = new AtomicInteger(); + AtomicInteger cancelledCalls = new AtomicInteger(); + Map> handlers = new HashMap<>(); + handlers.put("createdHandler", (event, chain) -> createdCalls.incrementAndGet()); + handlers.put("cancelledHandler", (event, chain) -> cancelledCalls.incrementAndGet()); + + EventHandlerDefinition definition = new EventHandlerDefinition(); + Map routes = new LinkedHashMap<>(); + routes.put("/orders/created", "createdHandler"); + routes.put("/orders/cancelled", "cancelledHandler"); + definition.setDefinitionMap(routes); + DisruptorProperties properties = new DisruptorProperties(); + properties.setHandlerDefinitions(Collections.singletonList(definition)); + DisruptorEventDispatcher dispatcher = configuration.disruptorEventHandlers(properties, handlers).get(0); + + DisruptorEvent created = new DisruptorEvent("source"); + created.setTopic("orders"); + created.setTag("created"); + dispatcher.onEvent(created, 0, true); + assertEquals(1, createdCalls.get()); + assertEquals(0, cancelledCalls.get()); + + DisruptorEvent cancelled = new DisruptorEvent("source"); + cancelled.setTopic("orders"); + cancelled.setTag("cancelled"); + dispatcher.onEvent(cancelled, 1, true); + assertEquals(1, createdCalls.get()); + assertEquals(1, cancelledCalls.get()); + } + + @Test + void ordersDispatchersByConfiguredOrder() { + DisruptorAutoConfiguration configuration = new DisruptorAutoConfiguration(); + EventHandlerDefinition later = new EventHandlerDefinition(); + later.setOrder(2); + EventHandlerDefinition earlier = new EventHandlerDefinition(); + earlier.setOrder(1); + DisruptorProperties properties = new DisruptorProperties(); + properties.setHandlerDefinitions(Arrays.asList(later, earlier)); + + List dispatchers = configuration.disruptorEventHandlers( + properties, Collections.emptyMap()); + assertEquals(1, dispatchers.get(0).getOrder()); + assertEquals(2, dispatchers.get(1).getOrder()); + } +}