116 lines
4.8 KiB
Java
116 lines
4.8 KiB
Java
package com.njcn;
|
||
|
||
import com.njcn.gather.tools.comtrade.comparewave.core.model.CompareWaveDTO;
|
||
import com.njcn.gather.tools.comtrade.comparewave.service.ICompareWaveService;
|
||
import org.junit.Test;
|
||
import org.junit.runner.RunWith;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.boot.test.context.SpringBootTest;
|
||
import org.springframework.test.context.junit4.SpringRunner;
|
||
|
||
import java.io.File;
|
||
import java.io.FileInputStream;
|
||
import java.io.InputStream;
|
||
|
||
|
||
/**
|
||
* 流式文件分析测试
|
||
* 测试从本地文件读取并转换为流进行分析
|
||
*/
|
||
@RunWith(SpringRunner.class)
|
||
@SpringBootTest(classes = com.njcn.gather.EntranceApplication.class)
|
||
public class AnalysisServiceStreamTest {
|
||
|
||
@Autowired
|
||
private ICompareWaveService compareWaveServiceImpl;
|
||
|
||
// 测试文件路径 - 请根据实际情况修改
|
||
private static final String SOURCE_CFG_PATH = "F:\\hatch\\wavecompare\\wave\\PQMonitor_PQM1_000001_20200430_113404_845.cfg";
|
||
private static final String SOURCE_DAT_PATH = "F:\\hatch\\wavecompare\\wave\\PQMonitor_PQM1_000001_20200430_113404_845.dat";
|
||
private static final String TARGET_CFG_PATH = "F:\\hatch\\wavecompare\\wave\\PQMonitor_PQM1_000001_20200430_113407_075.cfg";
|
||
private static final String TARGET_DAT_PATH = "F:\\hatch\\wavecompare\\wave\\PQMonitor_PQM1_000001_20200430_113407_075.dat";
|
||
|
||
// 输出路径
|
||
private static final String OUTPUT_PATH = "./test-output/";
|
||
|
||
/**
|
||
* 测试使用文件流进行电能质量分析
|
||
*/
|
||
@Test
|
||
public void testAnalyzeWithStreams() throws Exception {
|
||
System.out.println("========================================");
|
||
System.out.println("开始测试流式文件分析");
|
||
System.out.println("========================================");
|
||
|
||
// 验证文件是否存在
|
||
checkFileExists(SOURCE_CFG_PATH, "源CFG文件");
|
||
checkFileExists(SOURCE_DAT_PATH, "源DAT文件");
|
||
checkFileExists(TARGET_CFG_PATH, "目标CFG文件");
|
||
checkFileExists(TARGET_DAT_PATH, "目标DAT文件");
|
||
|
||
// 读取本地文件并创建输入流
|
||
try (InputStream sourceCfgStream = new FileInputStream(SOURCE_CFG_PATH);
|
||
InputStream sourceDatStream = new FileInputStream(SOURCE_DAT_PATH);
|
||
InputStream targetCfgStream = new FileInputStream(TARGET_CFG_PATH);
|
||
InputStream targetDatStream = new FileInputStream(TARGET_DAT_PATH)) {
|
||
|
||
System.out.println("成功创建文件输入流");
|
||
System.out.println("源CFG文件: " + SOURCE_CFG_PATH);
|
||
System.out.println("源DAT文件: " + SOURCE_DAT_PATH);
|
||
System.out.println("目标CFG文件: " + TARGET_CFG_PATH);
|
||
System.out.println("目标DAT文件: " + TARGET_DAT_PATH);
|
||
System.out.println("输出路径: " + OUTPUT_PATH);
|
||
|
||
// 创建输出目录
|
||
File outputDir = new File(OUTPUT_PATH);
|
||
if (!outputDir.exists()) {
|
||
outputDir.mkdirs();
|
||
System.out.println("创建输出目录: " + outputDir.getAbsolutePath());
|
||
}
|
||
|
||
// 执行分析,使用星型接线方式(0)
|
||
System.out.println("\n开始执行电能质量分析(星型接线)...");
|
||
long startTime = System.currentTimeMillis();
|
||
|
||
CompareWaveDTO result = compareWaveServiceImpl.analyzeAndCompareWithStreams(
|
||
sourceCfgStream,
|
||
sourceDatStream,
|
||
targetCfgStream,
|
||
targetDatStream,
|
||
// 接线方式: 0=星型接线, 1=V型接线
|
||
0
|
||
);
|
||
|
||
long endTime = System.currentTimeMillis();
|
||
long duration = endTime - startTime;
|
||
|
||
// 输出分析结果
|
||
System.out.println("========================================");
|
||
System.out.println("分析完成!");
|
||
System.out.println("总耗时: " + duration + " ms (" + String.format("%.2f", duration / 1000.0) + " 秒)");
|
||
|
||
|
||
|
||
|
||
System.out.println("========================================");
|
||
System.out.println("流式文件分析测试完成!");
|
||
System.out.println("========================================");
|
||
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 检查文件是否存在
|
||
*/
|
||
private void checkFileExists(String filePath, String description) {
|
||
File file = new File(filePath);
|
||
if (!file.exists()) {
|
||
System.err.println("警告: " + description + " 不存在: " + filePath);
|
||
System.err.println("请确保文件路径正确,或修改测试中的文件路径");
|
||
} else {
|
||
System.out.println(description + " 存在: " + filePath);
|
||
System.out.println(" 文件大小: " + file.length() + " bytes");
|
||
}
|
||
}
|
||
|
||
} |