| | |
| | | import com.zy.ai.domain.autotune.AutoTuneFlowTopologyItem; |
| | | import com.zy.ai.domain.autotune.AutoTuneStationRuntimeItem; |
| | | import com.zy.ai.service.impl.FlowTopologySnapshotServiceImpl; |
| | | import com.zy.asrs.entity.StationFlowCapacity; |
| | | import com.zy.asrs.entity.BasStation; |
| | | import org.junit.jupiter.api.Test; |
| | | |
| | | import java.util.Arrays; |
| | |
| | | import java.util.Map; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| | | |
| | | class FlowTopologySnapshotServiceImplTest { |
| | | |
| | | @Test |
| | | void buildTopologyItemUsesExplicitDirectionAndTargetStation() { |
| | | FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl(); |
| | | StationFlowCapacity capacity = capacity(101, "OUT", 3); |
| | | BasStation station = station(101, 3); |
| | | Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>(); |
| | | adjacency.put(101, Arrays.asList(103, 102)); |
| | | |
| | | AutoTuneFlowTopologyItem item = service.buildTopologyItem( |
| | | capacity, |
| | | station, |
| | | adjacency, |
| | | Arrays.asList(runtime(101, 1, 0, 0), runtime(102, 1, 1, 0)) |
| | | ); |
| | |
| | | @Test |
| | | void undirectedGraphOnlyPopulatesAdjacentAndFlowStations() { |
| | | FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl(); |
| | | StationFlowCapacity capacity = capacity(201, "IN", 4); |
| | | BasStation station = station(201, 4); |
| | | Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>(); |
| | | adjacency.put(201, Arrays.asList(203, 202)); |
| | | |
| | | AutoTuneFlowTopologyItem item = service.buildTopologyItem( |
| | | capacity, |
| | | station, |
| | | adjacency, |
| | | Arrays.asList(runtime(202, 1, 1, 0), runtime(203, 1, 0, 8001)) |
| | | ); |
| | |
| | | } |
| | | |
| | | @Test |
| | | void findCapacityUsesStationIdAndDirectionCode() { |
| | | FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl(); |
| | | List<StationFlowCapacity> capacities = Arrays.asList( |
| | | capacity(101, "IN", 2), |
| | | capacity(101, "OUT", 4), |
| | | capacity(102, "OUT", 8) |
| | | ); |
| | | |
| | | StationFlowCapacity result = service.findCapacity(capacities, 101, "OUT"); |
| | | |
| | | assertNotNull(result); |
| | | assertEquals(4, result.getBufferCapacity()); |
| | | assertEquals("OUT", result.getDirectionCode()); |
| | | } |
| | | |
| | | @Test |
| | | void flowStationIdsAndCountsAreNotTruncatedByBufferCapacity() { |
| | | FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl(); |
| | | StationFlowCapacity capacity = capacity(101, "OUT", 1); |
| | | BasStation station = station(101, 1); |
| | | Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>(); |
| | | adjacency.put(101, Arrays.asList(104, 102, 103)); |
| | | |
| | | AutoTuneFlowTopologyItem item = service.buildTopologyItem( |
| | | capacity, |
| | | station, |
| | | adjacency, |
| | | Arrays.asList( |
| | | runtime(101, 1, 0, 0), |
| | |
| | | assertEquals(0, item.getFreeCount()); |
| | | } |
| | | |
| | | private StationFlowCapacity capacity(Integer stationId, String directionCode, Integer bufferCapacity) { |
| | | StationFlowCapacity capacity = new StationFlowCapacity(); |
| | | capacity.setStationId(stationId); |
| | | capacity.setDirectionCode(directionCode); |
| | | capacity.setBufferCapacity(bufferCapacity); |
| | | return capacity; |
| | | @Test |
| | | void missingOutBufferCapacityKeepsFreeCountUnknown() { |
| | | FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl(); |
| | | BasStation station = station(101, null); |
| | | |
| | | AutoTuneFlowTopologyItem item = service.buildTopologyItem( |
| | | station, |
| | | new LinkedHashMap<>(), |
| | | Arrays.asList(runtime(101, 1, 1, 0)) |
| | | ); |
| | | |
| | | assertEquals(null, item.getBufferCapacity()); |
| | | assertEquals(null, item.getFreeCount()); |
| | | assertEquals(1, item.getOccupiedCount()); |
| | | } |
| | | |
| | | private BasStation station(Integer stationId, Integer outBufferCapacity) { |
| | | BasStation station = new BasStation(); |
| | | station.setStationId(stationId); |
| | | station.setOutBufferCapacity(outBufferCapacity); |
| | | return station; |
| | | } |
| | | |
| | | private AutoTuneStationRuntimeItem runtime(Integer stationId, Integer autoing, Integer loading, Integer taskNo) { |