优化
This commit is contained in:
-2
@@ -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) {
|
||||
|
||||
-18
@@ -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)
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user