60 lines
2.3 KiB
Java
60 lines
2.3 KiB
Java
|
|
package com.haobang.wal;
|
||
|
|
|
||
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||
|
|
|
||
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||
|
|
import com.haobang.config.AppProperties;
|
||
|
|
import java.nio.file.Path;
|
||
|
|
import java.util.Collections;
|
||
|
|
import org.junit.jupiter.api.Test;
|
||
|
|
import org.junit.jupiter.api.io.TempDir;
|
||
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||
|
|
import org.springframework.core.env.MapPropertySource;
|
||
|
|
|
||
|
|
/** 验证 WAL 服务在真实 Spring 构造器选择和生命周期规则下可以完成装配。 */
|
||
|
|
class SyslogWalSpringWiringTest {
|
||
|
|
|
||
|
|
@TempDir Path tempDirectory;
|
||
|
|
|
||
|
|
@Test
|
||
|
|
void springSelectsTheProductionConstructor() {
|
||
|
|
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||
|
|
context
|
||
|
|
.getEnvironment()
|
||
|
|
.getPropertySources()
|
||
|
|
.addFirst(
|
||
|
|
new MapPropertySource(
|
||
|
|
"wal-wiring-test",
|
||
|
|
Collections.singletonMap("syslog.wal.directory", tempDirectory.toString())));
|
||
|
|
context.registerBean(AppProperties.class, this::walProperties);
|
||
|
|
context.registerBean(ObjectMapper.class, () -> new ObjectMapper());
|
||
|
|
context.register(SyslogWalService.class);
|
||
|
|
context.refresh();
|
||
|
|
|
||
|
|
assertNotNull(context.getBean(SyslogWalService.class));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private AppProperties walProperties() {
|
||
|
|
AppProperties properties = new AppProperties();
|
||
|
|
properties.setSyslogWalEnabled(true);
|
||
|
|
properties.setSyslogWalDirectory(tempDirectory.toString());
|
||
|
|
properties.setSyslogWalQueueCapacity(16);
|
||
|
|
properties.setSyslogWalHighWatermarkPercent(70);
|
||
|
|
properties.setSyslogWalLowWatermarkPercent(40);
|
||
|
|
properties.setSyslogWalRetryIntervalMs(5);
|
||
|
|
properties.setSyslogWalDiskRetryIntervalMs(50);
|
||
|
|
properties.setSyslogWalFlushRecords(1);
|
||
|
|
properties.setSyslogWalFlushIntervalMs(5);
|
||
|
|
properties.setSyslogWalSegmentMaxBytes(1024 * 1024);
|
||
|
|
properties.setSyslogWalRetentionDays(0);
|
||
|
|
properties.setSyslogWalShutdownTimeoutMs(5000);
|
||
|
|
properties.setSyslogWalCheckpointFlushRecords(1);
|
||
|
|
properties.setSyslogWalCheckpointFlushIntervalMs(5);
|
||
|
|
properties.setSyslogWalDiskHighWatermarkPercent(98);
|
||
|
|
properties.setSyslogWalMinFreeBytes(0);
|
||
|
|
properties.setSyslogCharset("UTF-8");
|
||
|
|
return properties;
|
||
|
|
}
|
||
|
|
}
|