fix(ft546): serialize shuttle reader lifecycle

This commit is contained in:
zgw
2026-08-11 12:10:24 +08:00
parent 46302c0de1
commit edafe7af94
3 changed files with 151 additions and 18 deletions

View File

@@ -1,9 +1,11 @@
package com.ruoyi.project.ft546.device;
import com.ruoyi.common.domain.PlcConnectInfo;
import com.ruoyi.common.domain.CustomThread;
import com.ruoyi.device.srgv.domain.DeviceSrgv;
import com.ruoyi.project.ft546.config.Ft546DeviceProfile;
import com.ruoyi.project.ft546.device.shuttle.Ft546SrgvRuntimeFactory;
import com.ruoyi.schedule.ScheduleThread;
import com.ruoyi.schedule.plcRead.srgv.PlcSrgvRead;
import org.junit.jupiter.api.Test;
@@ -14,6 +16,7 @@ import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -55,6 +58,29 @@ class Ft546DeviceRuntimeRegistryTest {
() -> new Ft546SrgvRuntimeFactory().create(device, profile));
}
@Test
void factoryRejectsMissingDeviceWithTheDeclaredValidationError() {
assertThrows(IllegalArgumentException.class,
() -> new Ft546SrgvRuntimeFactory().create(null));
}
@Test
void startingFactReadersTwiceIsIdempotent() {
ScheduleThread schedule = new ScheduleThread();
schedule.plcSsjReadCustomThread = noOpThread();
schedule.plcTsjReadCustomThread = noOpThread();
schedule.plcCdzReadCustomThread = noOpThread();
schedule.startAllThread();
assertDoesNotThrow(schedule::startAllThread);
}
@Test
void stoppingBeforeInitializationIsANoOp() {
assertDoesNotThrow(() -> new ScheduleThread().stopAllThread());
}
@Test
void schedulingAndLegacySendPathsDoNotSelectThreeFixedReaders()
throws Exception {
@@ -75,6 +101,10 @@ class Ft546DeviceRuntimeRegistryTest {
new PlcConnectInfo(device.getIp(), device.getPort()));
}
private static <T> CustomThread<T> noOpThread() {
return new CustomThread<T>(new Thread(() -> { }), null);
}
private static DeviceSrgv device(String id) {
DeviceSrgv device = new DeviceSrgv();
device.setDeviceId(Integer.valueOf(id));