package com.zy.ai.service;
|
|
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.BasStation;
|
import org.junit.jupiter.api.Test;
|
|
import java.util.Arrays;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
class FlowTopologySnapshotServiceImplTest {
|
|
@Test
|
void buildTopologyItemUsesExplicitDirectionAndTargetStation() {
|
FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
|
BasStation station = station(101, 3);
|
Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>();
|
adjacency.put(101, Arrays.asList(103, 102));
|
|
AutoTuneFlowTopologyItem item = service.buildTopologyItem(
|
station,
|
adjacency,
|
Arrays.asList(runtime(101, 1, 0, 0), runtime(102, 1, 1, 0))
|
);
|
|
assertEquals(101, item.getTargetStationId());
|
assertEquals("OUT", item.getDirection());
|
assertEquals(Arrays.asList(102, 103), item.getAdjacentStationIds());
|
assertEquals(Arrays.asList(), item.getUpstreamStationIds());
|
assertEquals(Arrays.asList(), item.getDownstreamStationIds());
|
assertEquals(Arrays.asList(101, 102, 103), item.getFlowStationIds());
|
}
|
|
@Test
|
void undirectedGraphOnlyPopulatesAdjacentAndFlowStations() {
|
FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
|
BasStation station = station(201, 4);
|
Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>();
|
adjacency.put(201, Arrays.asList(203, 202));
|
|
AutoTuneFlowTopologyItem item = service.buildTopologyItem(
|
station,
|
adjacency,
|
Arrays.asList(runtime(202, 1, 1, 0), runtime(203, 1, 0, 8001))
|
);
|
|
assertEquals(Arrays.asList(202, 203), item.getAdjacentStationIds());
|
assertEquals(Arrays.asList(), item.getUpstreamStationIds());
|
assertEquals(Arrays.asList(), item.getDownstreamStationIds());
|
assertEquals(Arrays.asList(201, 202, 203), item.getFlowStationIds());
|
assertEquals(2, item.getOccupiedCount());
|
}
|
|
@Test
|
void calculateRuntimeCountsUsesOnlyAutoingLoadingAndTaskNo() {
|
FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
|
List<AutoTuneStationRuntimeItem> runtimeItems = Arrays.asList(
|
runtime(101, 0, 0, 0),
|
runtime(102, 1, 1, 0),
|
runtime(103, 1, 0, 9001),
|
runtime(104, 0, 1, 9002)
|
);
|
|
FlowTopologySnapshotServiceImpl.RuntimeCount count = service.calculateRuntimeCount(runtimeItems);
|
|
assertEquals(3, count.getOccupiedCount());
|
assertEquals(2, count.getNonAutoingCount());
|
assertEquals(2, count.getLoadingCount());
|
assertEquals(2, count.getTaskHoldingCount());
|
}
|
|
@Test
|
void flowStationIdsAndCountsAreNotTruncatedByBufferCapacity() {
|
FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
|
BasStation station = station(101, 1);
|
Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>();
|
adjacency.put(101, Arrays.asList(104, 102, 103));
|
|
AutoTuneFlowTopologyItem item = service.buildTopologyItem(
|
station,
|
adjacency,
|
Arrays.asList(
|
runtime(101, 1, 0, 0),
|
runtime(102, 1, 1, 0),
|
runtime(103, 1, 0, 9001),
|
runtime(104, 0, 0, 0)
|
)
|
);
|
|
assertEquals(Arrays.asList(101, 102, 103, 104), item.getFlowStationIds());
|
assertEquals(2, item.getOccupiedCount());
|
assertEquals(1, item.getLoadingCount());
|
assertEquals(1, item.getTaskHoldingCount());
|
assertEquals(1, item.getNonAutoingCount());
|
assertEquals(0, item.getFreeCount());
|
}
|
|
@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) {
|
AutoTuneStationRuntimeItem item = new AutoTuneStationRuntimeItem();
|
item.setStationId(stationId);
|
item.setAutoing(autoing);
|
item.setLoading(loading);
|
item.setTaskNo(taskNo);
|
return item;
|
}
|
}
|