test(mq-starter): driver autoconfig 加 @AutoConfigureBefore 注解契约护栏
Rocket / RedisStream driver autoconfig 各加一个护栏测试,断言 @AutoConfigureBefore(MqCoreAutoConfiguration) 注解存在——防止重构误删导致 core 在 driver 前装配、MqTemplate/MqListenerRegistry 不装配的回归(最终 review I1)。 以注解契约守护、不 refresh context(规避本模块 spring 版本不一致:rocketmq-spring 2.2.3 与父 pom spring-boot 2.3.12 的 spring-core 缺 ApplicationStartup);真实装配 结果由 cn-data-platform MqSliceWiringTest 在正确 spring 版本下覆盖。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.njcn.mq.driver.redis;
|
||||
|
||||
import com.njcn.mq.autoconfig.MqCoreAutoConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* 装配顺序回归护栏(mq-starter 自身)。
|
||||
*
|
||||
* <p>{@link RedisStreamMqDriverAutoConfiguration} 必须声明
|
||||
* {@code @AutoConfigureBefore(MqCoreAutoConfiguration.class)}:否则真实 Spring Boot 按类名字母序
|
||||
* 处理 autoconfig,{@code com.njcn.mq.autoconfig.*}(core) 先于 {@code com.njcn.mq.driver.*}(driver),
|
||||
* core 的 {@code @ConditionalOnBean(MqDriver)} 在 driver bean 注册前求值失败,
|
||||
* {@code MqTemplate} / {@code MqListenerRegistry} 不装配。
|
||||
*
|
||||
* <p>以注解契约守护,真实装配结果由 cn-data-platform 的 {@code MqSliceWiringTest}
|
||||
* (真实 autoconfig 顺序)覆盖。删掉 @AutoConfigureBefore 本测试即 RED。
|
||||
*/
|
||||
class RedisStreamMqDriverWiringTest {
|
||||
|
||||
@Test
|
||||
void declaresAutoConfigureBeforeCore() {
|
||||
AutoConfigureBefore ann = RedisStreamMqDriverAutoConfiguration.class.getAnnotation(AutoConfigureBefore.class);
|
||||
assertThat(ann)
|
||||
.as("RedisStreamMqDriverAutoConfiguration 必须声明 @AutoConfigureBefore,使 driver 先于 core 装配")
|
||||
.isNotNull();
|
||||
assertThat(ann.value())
|
||||
.as("@AutoConfigureBefore 必须指向 MqCoreAutoConfiguration")
|
||||
.contains(MqCoreAutoConfiguration.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user