diff --git a/common-web/src/main/java/com/baiyue/common/web/EventDeliveryObservationAutoConfiguration.java b/common-web/src/main/java/com/baiyue/common/web/EventDeliveryObservationAutoConfiguration.java index 473a4a3a4..efa4c05f8 100644 --- a/common-web/src/main/java/com/baiyue/common/web/EventDeliveryObservationAutoConfiguration.java +++ b/common-web/src/main/java/com/baiyue/common/web/EventDeliveryObservationAutoConfiguration.java @@ -5,7 +5,6 @@ import com.baiyue.common.core.outbox.EventDeliveryProducer; import io.micrometer.core.instrument.MeterRegistry; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.context.annotation.Bean; @@ -14,7 +13,6 @@ import org.springframework.transaction.PlatformTransactionManager; @AutoConfiguration(after = {JdbcTemplateAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class}) @ConditionalOnBean(EventDeliveryProducer.class) -@ConditionalOnProperty(prefix = "baiyue.event-delivery", name = "observation-enabled", havingValue = "true") public class EventDeliveryObservationAutoConfiguration { @Bean EventDeliveryJournal eventDeliveryJournal(JdbcTemplate jdbc, PlatformTransactionManager manager) { diff --git a/common-web/src/test/java/com/baiyue/common/web/EventDeliveryObservationAutoConfigurationTest.java b/common-web/src/test/java/com/baiyue/common/web/EventDeliveryObservationAutoConfigurationTest.java index b772fb46e..19a1a9674 100644 --- a/common-web/src/test/java/com/baiyue/common/web/EventDeliveryObservationAutoConfigurationTest.java +++ b/common-web/src/test/java/com/baiyue/common/web/EventDeliveryObservationAutoConfigurationTest.java @@ -11,14 +11,12 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.beans.factory.annotation.Autowired; import static org.assertj.core.api.Assertions.*; class EventDeliveryObservationAutoConfigurationTest { @Test void configuresMandatoryAuditAndMetricsForServiceLocalJdbc() { var jdbc = new JdbcTemplate(new DriverManagerDataSource("jdbc:h2:mem:auto", "sa", "")); new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(EventDeliveryObservationAutoConfiguration.class)) - .withPropertyValues("baiyue.event-delivery.observation-enabled=true") .withBean(EventDeliveryProducer.class, () -> new EventDeliveryProducer() { }) .withBean(JdbcTemplate.class, () -> jdbc) .withBean(PlatformTransactionManager.class, () -> new DataSourceTransactionManager(jdbc.getDataSource())) @@ -30,7 +28,6 @@ class EventDeliveryObservationAutoConfigurationTest { } @Test void otherJdbcServicesDoNotAcquireTransactionOrMetricsRequirements() { new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(EventDeliveryObservationAutoConfiguration.class)) - .withPropertyValues("baiyue.event-delivery.observation-enabled=true") .withBean(JdbcTemplate.class, () -> new JdbcTemplate(new DriverManagerDataSource("jdbc:h2:mem:other", "sa", ""))) .run(context -> { assertThat(context).hasNotFailed(); @@ -41,28 +38,13 @@ class EventDeliveryObservationAutoConfigurationTest { @Test void producerWithoutMeterRegistryFailsInsteadOfSilentlyDisablingObservation() { var jdbc = new JdbcTemplate(new DriverManagerDataSource("jdbc:h2:mem:noRegistry", "sa", "")); new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(EventDeliveryObservationAutoConfiguration.class)) - .withPropertyValues("baiyue.event-delivery.observation-enabled=true") .withBean(EventDeliveryProducer.class, () -> new EventDeliveryProducer() { }) .withBean(JdbcTemplate.class, () -> jdbc) .withBean(PlatformTransactionManager.class, () -> new DataSourceTransactionManager(jdbc.getDataSource())) .run(context -> assertThat(context).hasFailed()); } - static class RequiredProducer implements EventDeliveryProducer { - @Autowired EventDeliveryJournal journal; - @Autowired EventDeliveryMetrics metrics; - } - @Test void producerMissingTheExplicitObservationSwitchCannotStart() { - var jdbc = new JdbcTemplate(new DriverManagerDataSource("jdbc:h2:mem:noSwitch", "sa", "")); - new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(EventDeliveryObservationAutoConfiguration.class)) - .withBean(RequiredProducer.class, RequiredProducer::new) - .withBean(JdbcTemplate.class, () -> jdbc) - .withBean(PlatformTransactionManager.class, () -> new DataSourceTransactionManager(jdbc.getDataSource())) - .withBean(MeterRegistry.class, SimpleMeterRegistry::new) - .run(context -> assertThat(context).hasFailed()); - } @Test void missingTransactionManagerFailsRatherThanInstallingNonTransactionalFallback() { new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(EventDeliveryObservationAutoConfiguration.class)) - .withPropertyValues("baiyue.event-delivery.observation-enabled=true") .withBean(EventDeliveryProducer.class, () -> new EventDeliveryProducer() { }) .withBean(JdbcTemplate.class, () -> new JdbcTemplate(new DriverManagerDataSource("jdbc:h2:mem:missing", "sa", ""))) .withBean(MeterRegistry.class, SimpleMeterRegistry::new) diff --git a/config/nacos/test/finance-service.yml b/config/nacos/test/finance-service.yml index bbc4da782..dca977209 100644 --- a/config/nacos/test/finance-service.yml +++ b/config/nacos/test/finance-service.yml @@ -7,7 +7,6 @@ spring: baiyue.clients.warehouse.url: ${WAREHOUSE_SERVICE_URL:} baiyue.finance.recharge.qr-code-url: ${FINANCE_RECHARGE_QR_CODE_URL:} baiyue.finance.wallet.default-credit-limit: ${FINANCE_WALLET_DEFAULT_CREDIT_LIMIT:0.00} -baiyue.event-delivery.observation-enabled: true baiyue.event-delivery.operations-token: ${EVENT_OPERATIONS_TOKEN:} baiyue.event-delivery.connect-timeout-ms: ${EVENT_CONNECT_TIMEOUT_MS:3000} baiyue.event-delivery.read-timeout-ms: ${EVENT_READ_TIMEOUT_MS:15000} diff --git a/config/nacos/test/firstleg-service.yml b/config/nacos/test/firstleg-service.yml index ca18c236b..c677a2da4 100644 --- a/config/nacos/test/firstleg-service.yml +++ b/config/nacos/test/firstleg-service.yml @@ -78,7 +78,6 @@ firstleg: subject-id: ${MEASUREMENT_DEVICE_PROVIDER_SUBJECT_ID:0} warehouse-bindings: CN-YW-01: ${MEASUREMENT_DEVICE_PROVIDER_WAREHOUSE_ID:0} -baiyue.event-delivery.observation-enabled: true baiyue.event-delivery.operations-token: ${EVENT_OPERATIONS_TOKEN:} baiyue.event-delivery.connect-timeout-ms: ${EVENT_CONNECT_TIMEOUT_MS:3000} baiyue.event-delivery.read-timeout-ms: ${EVENT_READ_TIMEOUT_MS:15000} diff --git a/config/nacos/test/lastleg-service.yml b/config/nacos/test/lastleg-service.yml index b555e61c4..f5da05865 100644 --- a/config/nacos/test/lastleg-service.yml +++ b/config/nacos/test/lastleg-service.yml @@ -50,7 +50,6 @@ baiyue: firstleg: outbox-relay: fixed-delay-ms: ${FIRSTLEG_OUTBOX_RELAY_FIXED_DELAY_MS:5000} -baiyue.event-delivery.observation-enabled: true baiyue.event-delivery.operations-token: ${EVENT_OPERATIONS_TOKEN:} baiyue.event-delivery.connect-timeout-ms: ${EVENT_CONNECT_TIMEOUT_MS:3000} baiyue.event-delivery.read-timeout-ms: ${EVENT_READ_TIMEOUT_MS:15000}