yeg
2026-09-05 bd50f1b756c1da2dbf92f6541407ad40f455e24a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.battery.device.simulator;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.time.Duration;
import java.time.ZoneId;
import org.junit.jupiter.api.Test;
import com.battery.device.model.DeviceWorkStatus;
import com.battery.device.bts.BtsDeviceAdapter;
import com.battery.device.bts.BtsTcpTransport;
import com.battery.device.bts.BtsXmlCodec;
import com.battery.device.simulator.InMemoryBtsSimulatorStateStore;
 
/** Ticket13:开发检测柜历史合同与实时快照保持两条独立路径。 */
class BtsDevelopmentSimulatorHistoryContractTest
{
    @Test
    void workingObservationProducesPagedHistoryWithoutControlCommand() throws Exception
    {
        try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0, new InMemoryBtsSimulatorStateStore()))
        {
            simulator.updateChannel(1, 1, true, DeviceWorkStatus.WORKING);
            try (BtsDeviceAdapter adapter = new BtsDeviceAdapter("dev-sim",
                    new BtsTcpTransport("127.0.0.1", simulator.port(), Duration.ofSeconds(2), Duration.ofSeconds(2)),
                    new BtsXmlCodec("dev-sim", ZoneId.of("Asia/Hong_Kong"))))
            {
                var channel = adapter.discoverChannels().stream().filter(item -> item.identity().chlid() == 1).findFirst().orElseThrow();
                adapter.inquire(java.util.Set.of(channel.identity()));
                var availability = adapter.inquireHistory(java.util.Set.of(channel.identity())).get(0);
                assertFalse(availability.btsTestId().isBlank());
                var page = adapter.downloadHistory(channel.identity(), availability.btsTestId(), 1, 1);
                assertEquals(1, page.samples().size());
                assertEquals(1, page.samples().get(0).sequenceId());
            }
        }
    }
 
    @Test
    void historySurvivesSimulatorRestartForResume() throws Exception
    {
        InMemoryBtsSimulatorStateStore store = new InMemoryBtsSimulatorStateStore();
        try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0, store))
        {
            simulator.updateChannel(1, 1, true, DeviceWorkStatus.WORKING);
            try (BtsDeviceAdapter adapter = new BtsDeviceAdapter("dev-sim",
                    new BtsTcpTransport("127.0.0.1", simulator.port(), Duration.ofSeconds(2), Duration.ofSeconds(2)),
                    new BtsXmlCodec("dev-sim", ZoneId.of("Asia/Hong_Kong"))))
            {
                adapter.inquire(java.util.Set.of(adapter.discoverChannels().get(0).identity()));
            }
        }
        try (BtsDevelopmentSimulator restarted = new BtsDevelopmentSimulator(0, store);
                BtsDeviceAdapter adapter = new BtsDeviceAdapter("dev-sim",
                        new BtsTcpTransport("127.0.0.1", restarted.port(), Duration.ofSeconds(2), Duration.ofSeconds(2)),
                        new BtsXmlCodec("dev-sim", ZoneId.of("Asia/Hong_Kong"))))
        {
            var channel = adapter.discoverChannels().get(0);
            assertEquals(1, adapter.inquireHistory(java.util.Set.of(channel.identity())).get(0).availableRecordCount());
        }
    }
}