| File was renamed from ruoyi-device/src/test/java/com/ruoyi/device/bts/ScriptedBtsTcpSimulator.java |
| | |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | final class ScriptedBtsTcpSimulator implements AutoCloseable |
| | | /** |
| | | * 提供可复用的 BTS TCP 脚本设备边界,用于闭环与恢复测试。 |
| | | */ |
| | | public final class ScriptedBtsTcpSimulator implements AutoCloseable |
| | | { |
| | | private static final byte[] FRAME_END = "#\r\n".getBytes(StandardCharsets.UTF_8); |
| | | |
| | |
| | | private final BlockingQueue<ScriptedAction> actions = new LinkedBlockingQueue<>(); |
| | | private final List<String> requests = new CopyOnWriteArrayList<>(); |
| | | |
| | | ScriptedBtsTcpSimulator() throws IOException |
| | | public ScriptedBtsTcpSimulator() throws IOException |
| | | { |
| | | this(true); |
| | | } |
| | |
| | | serverSocket.close(); |
| | | } |
| | | |
| | | static ScriptedBtsTcpSimulator refusingConnections() throws IOException |
| | | public static ScriptedBtsTcpSimulator refusingConnections() throws IOException |
| | | { |
| | | return new ScriptedBtsTcpSimulator(false); |
| | | } |
| | | |
| | | int port() |
| | | public int port() |
| | | { |
| | | return port; |
| | | } |
| | | |
| | | void enqueue(String response) |
| | | public void enqueue(String response) |
| | | { |
| | | actions.add(new ScriptedAction(Duration.ZERO, response.getBytes(StandardCharsets.UTF_8), false)); |
| | | } |
| | | |
| | | void enqueueDelayed(Duration delay, String response) |
| | | public void enqueueDelayed(Duration delay, String response) |
| | | { |
| | | if (delay.isNegative()) throw new IllegalArgumentException("delay must not be negative"); |
| | | actions.add(new ScriptedAction(delay, response.getBytes(StandardCharsets.UTF_8), false)); |
| | | } |
| | | |
| | | void enqueueRaw(byte[] response) |
| | | public void enqueueRaw(byte[] response) |
| | | { |
| | | actions.add(new ScriptedAction(Duration.ZERO, response.clone(), false)); |
| | | } |
| | | |
| | | void enqueueDisconnect() |
| | | public void enqueueDisconnect() |
| | | { |
| | | actions.add(new ScriptedAction(Duration.ZERO, null, true)); |
| | | } |
| | | |
| | | List<String> requests() |
| | | public List<String> requests() |
| | | { |
| | | return List.copyOf(requests); |
| | | } |