diff --git a/bootstrap-all/src/test/java/com/lingniu/ingest/bootstrap/RawArchiveEndToEndTest.java b/bootstrap-all/src/test/java/com/lingniu/ingest/bootstrap/RawArchiveEndToEndTest.java new file mode 100644 index 00000000..59f04ffe --- /dev/null +++ b/bootstrap-all/src/test/java/com/lingniu/ingest/bootstrap/RawArchiveEndToEndTest.java @@ -0,0 +1,174 @@ +package com.lingniu.ingest.bootstrap; + +import com.lingniu.ingest.codec.BccChecksum; +import com.lingniu.ingest.protocol.gb32960.inbound.Gb32960NettyServer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; + +import java.io.ByteArrayOutputStream; +import java.net.Socket; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.Instant; +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * 端到端验证原始报文冷存链路: + * + *
+ * TCP → Gb32960 Netty → Dispatcher 发 RawArchive 事件 + * → Disruptor 虚拟线程 → ArchiveEventSink.publish + * → LocalArchiveStore.put → 文件系统落盘 + *+ * + *
与 {@link IngestEndToEndTest} 互补:前者验证业务事件路径;这里验证 raw archive
+ * 路径。两个测试跑在独立 Spring 上下文里(archive 是否启用的配置不同)。
+ */
+@SpringBootTest(
+ classes = IngestApplication.class,
+ webEnvironment = SpringBootTest.WebEnvironment.NONE,
+ properties = {
+ "lingniu.ingest.gb32960.enabled=true",
+ "lingniu.ingest.gb32960.port=0",
+ "lingniu.ingest.jt808.enabled=false",
+ "lingniu.ingest.jt1078.enabled=false",
+ "lingniu.ingest.jsatl12.enabled=false",
+ "lingniu.ingest.mqtt.enabled=false",
+ "lingniu.ingest.xinda-push.enabled=false",
+ "lingniu.ingest.command-gateway.enabled=false",
+ "lingniu.ingest.sink.mq.enabled=false",
+ // 启用 archive sink,路径由 @DynamicPropertySource 注入
+ "lingniu.ingest.sink.archive.enabled=true",
+ "lingniu.ingest.sink.archive.type=local"
+ })
+class RawArchiveEndToEndTest {
+
+ @TempDir
+ static Path archiveRoot;
+
+ @DynamicPropertySource
+ static void properties(DynamicPropertyRegistry registry) {
+ registry.add("lingniu.ingest.sink.archive.path", archiveRoot::toString);
+ }
+
+ @Autowired
+ private Gb32960NettyServer server;
+
+ @Test
+ void gb32960FrameIsArchivedToDisk() throws Exception {
+ int port = server.getBoundPort();
+ assertThat(port).isGreaterThan(0);
+
+ String vin = "LTEST0000ARCH0001";
+ byte[] frame = buildRealtimeFrame(vin);
+
+ try (Socket socket = new Socket("127.0.0.1", port)) {
+ socket.getOutputStream().write(frame);
+ socket.getOutputStream().flush();
+ }
+
+ // 预期落盘目录: