From 4986080e4393b5b2db9e1eb1fe0d7365648a3210 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Tue, 19 Dec 2023 16:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../line3/rep/InusedScheduleResponse.java | 1 - src/main/resources/application-dev.yml | 2 +- .../joylink/xiannccda/service/CacheTest.java | 102 ++++++++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/test/java/club/joylink/xiannccda/service/CacheTest.java diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/InusedScheduleResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/InusedScheduleResponse.java index 0c282b2..caf97f1 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/InusedScheduleResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/InusedScheduleResponse.java @@ -90,7 +90,6 @@ public class InusedScheduleResponse extends MessageResponse { planBuild.setLineId(this.lineId); planBuild.setDate(DateTimeUtil.epochSecond(this.date)); planBuild.setActionId(this.subId.val()); - planBuild.setTrainId(this.trainId); planBuilds.add(planBuild); return planBuilds; } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index a72eef8..c60a814 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -19,7 +19,7 @@ occ: lineId: 3 collectorData: false #故障测试 -mock-alert-test: false +mock-alert-test: true #加载历史模拟数据 load-mock-history-data: false #延时加载告警处理 diff --git a/src/test/java/club/joylink/xiannccda/service/CacheTest.java b/src/test/java/club/joylink/xiannccda/service/CacheTest.java new file mode 100644 index 0000000..97477fa --- /dev/null +++ b/src/test/java/club/joylink/xiannccda/service/CacheTest.java @@ -0,0 +1,102 @@ +package club.joylink.xiannccda.service; + +import club.joylink.xiannccda.ats.message.MessageData; +import club.joylink.xiannccda.ats.message.MessageId; +import club.joylink.xiannccda.ats.message.OccMessageEncoder; +import club.joylink.xiannccda.ats.message.OccMessageManage; +import club.joylink.xiannccda.entity.DeviceAreaConfig; +import club.joylink.xiannccda.mock.message.occ.MockOccServer; +import club.joylink.xiannccda.mock.message.occ.OutHandle; +import club.joylink.xiannccda.repository.impl.DeviceAreaConfigRepository; +import club.joylink.xiannccda.vo.AreaConfigVO; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class CacheTest { + + @Autowired + private DeviceAreaConfigRepository deviceAreaConfigRepository; + @Autowired + private OccMessageManage occMessageManage; + + @Autowired + private OutHandle outHandle; + + @Test + public void timeOutTest() throws InterruptedException { + for (var i = 0; i < 17; i++) { + System.out.println("----------------"); + new Thread(() -> { + List configs = deviceAreaConfigRepository.list(Wrappers.lambdaQuery(DeviceAreaConfig.class).eq(DeviceAreaConfig::getLineId, 3)); + List listVO = configs.stream().map(AreaConfigVO::new).toList(); + }).start(); + } + + TimeUnit.HOURS.sleep(1); + } + + @Test + public void test2() throws InterruptedException { +// MessageData md = MessageId.MESSAGE_POLLING.create(); +// this.occServer.write(md); +// TimeUnit.SECONDS.sleep(10); +// this.occServer.disconnect(); +/* try { + this.occMessageManage.sendMsg(3, md, true); + } catch (Exception e) { + e.printStackTrace(); + }*/ + TimeUnit.HOURS.sleep(1); + } + + @Test + public void testServer() throws InterruptedException { + this.initClient(); + TimeUnit.HOURS.sleep(1); + } + + public void initClient() { + EventLoopGroup bossGroup = new NioEventLoopGroup(); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + ServerBootstrap serverBootstrap = new ServerBootstrap(); + serverBootstrap.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline pipeline = ch.pipeline(); + pipeline.addLast(outHandle); + pipeline.addLast(new OccMessageEncoder(null)); + } + }) + .option(ChannelOption.SO_BACKLOG, 128) + .childOption(ChannelOption.SO_KEEPALIVE, true); + + try { + ChannelFuture future = serverBootstrap.bind(2603).sync(); + if (future.isSuccess()) { + +// log.info(String.format("modbus-tcp server start on port [%s]", this.modbusTcpConfig.getPort())); + } else { +// log.error("modbus-tcp server start failed", future.cause()); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } +}