fix(ft546): serialize shuttle reader lifecycle
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user