fix:简单存储与测试代码
This commit is contained in:
@@ -16,13 +16,17 @@ import org.nl.iot.core.driver.protocol.opcda.OpcDaProtocolDriverImpl;
|
||||
import org.nl.iot.core.driver.protocol.opcua.OpcUaProtocolDriverImpl;
|
||||
import org.nl.iot.core.driver.protocol.plcs7.PlcS7ProtocolDriverImpl;
|
||||
import org.nl.iot.core.driver.service.DriverCustomService;
|
||||
import org.nl.iot.core.cache.CacheRefreshController;
|
||||
import org.nl.iot.core.schedule.AutoReadAllSignalTaskRunner;
|
||||
import org.nl.iot.modular.iot.entity.IotConfig;
|
||||
import org.nl.iot.modular.iot.entity.IotConnect;
|
||||
import org.nl.common.pojo.CommonResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -2101,4 +2105,72 @@ public class ApiTest {
|
||||
|
||||
System.out.println("\n========== 协议驱动工厂测试完成 ==========");
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private AutoReadAllSignalTaskRunner autoReadAllSignalTaskRunner;
|
||||
|
||||
@Autowired
|
||||
private CacheRefreshController cacheRefreshController;
|
||||
|
||||
@Test
|
||||
public void ApiTest01() {
|
||||
try {
|
||||
System.out.println("========== 开始测试 AutoReadAllSignalTaskRunner ==========");
|
||||
|
||||
// 1. 执行 AutoReadAllSignalTaskRunner 的 action 方法
|
||||
System.out.println("执行 AutoReadAllSignalTaskRunner.action() 方法...");
|
||||
autoReadAllSignalTaskRunner.action(null);
|
||||
System.out.println("action() 方法执行完成");
|
||||
|
||||
// 2. 等待一小段时间确保数据已写入缓存
|
||||
Thread.sleep(1000);
|
||||
|
||||
// 3. 调用 getAllCacheData() 获取缓存数据
|
||||
System.out.println("\n调用 getAllCacheData() 获取缓存数据...");
|
||||
CommonResult<Map<String, Object>> result = cacheRefreshController.getAllCacheData();
|
||||
|
||||
// 4. 输出结果
|
||||
System.out.println("\n========== 测试结果 ==========");
|
||||
System.out.println("返回状态码: " + result.getCode());
|
||||
System.out.println("返回消息: " + result.getMsg());
|
||||
|
||||
if (result.getData() != null) {
|
||||
Map<String, Object> data = result.getData();
|
||||
System.out.println("\n缓存数据内容:");
|
||||
System.out.println(" - deviceInfoCacheCount: " +
|
||||
(data.get("deviceInfoCacheCount") != null ?
|
||||
((Map<?, ?>)data.get("deviceInfoCacheCount")).size() : 0));
|
||||
System.out.println(" - signalValueCacheCount: " +
|
||||
(data.get("signalValueCacheCount") != null ?
|
||||
((Map<?, ?>)data.get("signalValueCacheCount")).size() : 0));
|
||||
|
||||
// 详细输出设备信息缓存
|
||||
if (data.get("deviceInfoCacheCount") != null) {
|
||||
System.out.println("\n设备信息缓存详情:");
|
||||
Map<?, ?> deviceCache = (Map<?, ?>) data.get("deviceInfoCacheCount");
|
||||
deviceCache.forEach((key, value) -> {
|
||||
System.out.println(" 设备Key: " + key);
|
||||
});
|
||||
}
|
||||
|
||||
// 详细输出信号值缓存
|
||||
if (data.get("signalValueCacheCount") != null) {
|
||||
System.out.println("\n信号值缓存详情:");
|
||||
Map<?, ?> signalCache = (Map<?, ?>) data.get("signalValueCacheCount");
|
||||
signalCache.forEach((key, value) -> {
|
||||
System.out.println(" 信号Key: " + key + " -> 值: " + value);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
System.out.println("返回数据为空");
|
||||
}
|
||||
|
||||
System.out.println("\n========== 测试完成 ==========");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("测试失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user