| New file |
| | |
| | | package com.zy.asrs.task; |
| | | |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.common.properties.SlaveProperties; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | |
| | | class WorkMastSchedulerTest { |
| | | |
| | | private WorkMastScheduler scheduler; |
| | | |
| | | @BeforeEach |
| | | void setUp() { |
| | | scheduler = new WorkMastScheduler(); |
| | | SlaveProperties slaveProperties = new SlaveProperties(); |
| | | slaveProperties.setDoubleDeep(true); |
| | | slaveProperties.setDoubleLocs(Arrays.asList(1, 4, 5, 8, 9, 12, 13, 16, 17, 20)); |
| | | slaveProperties.setDoubleLocsLeft(Arrays.asList(1, 5, 9, 13, 17)); |
| | | slaveProperties.setDoubleLocsRight(Arrays.asList(4, 8, 12, 16, 20)); |
| | | ReflectionTestUtils.setField(scheduler, "slaveProperties", slaveProperties); |
| | | } |
| | | |
| | | @Test |
| | | void selectOutboundBatchMasts_unorderedDoubleExtension_shouldPreferShallowThenDeep() { |
| | | List<WrkMast> candidates = new ArrayList<>(); |
| | | for (int i = 0; i < 20; i++) { |
| | | candidates.add(outboundMast(1000 + i, 19, 0, "0100101")); |
| | | } |
| | | for (int i = 0; i < 5; i++) { |
| | | candidates.add(outboundMast(2000 + i, 19, 0, "0200101")); |
| | | } |
| | | |
| | | List<WrkMast> result = selectOutboundBatchMasts(candidates); |
| | | |
| | | assertEquals(25, result.size()); |
| | | for (int i = 0; i < 5; i++) { |
| | | assertEquals("0200101", result.get(i).getSourceLocNo()); |
| | | } |
| | | for (int i = 5; i < 20; i++) { |
| | | assertEquals("0100101", result.get(i).getSourceLocNo()); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void selectOutboundBatchMasts_orderedDoubleExtension_shouldKeepOutboundSeqOrder() { |
| | | List<WrkMast> candidates = Arrays.asList( |
| | | outboundMast(1002, 19, 2, "0200101"), |
| | | outboundMast(1001, 19, 1, "0100101"), |
| | | outboundMast(1003, 19, 3, "0200101") |
| | | ); |
| | | |
| | | List<WrkMast> result = selectOutboundBatchMasts(candidates); |
| | | |
| | | assertEquals(Integer.valueOf(1), result.get(0).getPltType()); |
| | | assertEquals(Integer.valueOf(2), result.get(1).getPltType()); |
| | | assertEquals(Integer.valueOf(3), result.get(2).getPltType()); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | private List<WrkMast> selectOutboundBatchMasts(List<WrkMast> candidates) { |
| | | return ReflectionTestUtils.invokeMethod(scheduler, "selectOutboundBatchMasts", candidates); |
| | | } |
| | | |
| | | private static WrkMast outboundMast(Integer wrkNo, Integer crnNo, Integer outboundSeq, String sourceLocNo) { |
| | | WrkMast mast = new WrkMast(); |
| | | mast.setWrkNo(wrkNo); |
| | | mast.setIoType(101); |
| | | mast.setCrnNo(crnNo); |
| | | mast.setPltType(outboundSeq); |
| | | mast.setSourceLocNo(sourceLocNo); |
| | | return mast; |
| | | } |
| | | } |