#
Junjie
2 天以前 90402710d962aa357062ecb94649e0f277c1dfb3
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.zy.core.utils;
 
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.WrkMast;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.model.protocol.StationTaskBufferItem;
import com.zy.core.thread.StationThread;
import com.zy.core.utils.station.StationRerouteProcessor;
import com.zy.core.utils.station.model.RerouteCommandPlan;
import com.zy.core.utils.station.model.RerouteContext;
import com.zy.core.utils.station.model.RerouteDecision;
import com.zy.core.utils.station.model.RerouteExecutionResult;
import com.zy.core.utils.station.model.RerouteSceneType;
import org.junit.jupiter.api.Test;
 
import java.util.Collections;
import java.util.List;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
class StationRerouteProcessorTest {
 
    @Test
    void rerouteProcessor_noLongerKeepsDispatcherFallbackHelper() {
        assertThrows(NoSuchMethodException.class,
                () -> StationRerouteProcessor.class.getDeclaredMethod("getStationCommandDispatcher"));
    }
 
    @Test
    void buildCommandPlan_usesRunBlockCommandBuilderForRunBlockScene() {
        StationRerouteProcessor processor = new StationRerouteProcessor();
        StationThread stationThread = mock(StationThread.class);
        StationCommand command = new StationCommand();
        command.setTaskNo(100);
        command.setStationId(10);
        command.setTargetStaNo(20);
        when(stationThread.getRunBlockRerouteCommand(100, 10, 20, 0, 0.25d)).thenReturn(command);
 
        RerouteContext context = RerouteContext.create(
                RerouteSceneType.RUN_BLOCK_REROUTE,
                buildBasDevp(1),
                stationThread,
                buildStationProtocol(10, 100, 10),
                buildWrkMast(100, 99),
                Collections.emptyList(),
                0.25d,
                "checkStationRunBlock_reroute"
        ).withRunBlockCommand()
                .withCancelSessionBeforeDispatch()
                .withResetSegmentCommandsBeforeDispatch();
 
        RerouteCommandPlan plan = processor.buildRerouteCommandPlan(
                context,
                RerouteDecision.proceed(20)
        );
 
        verify(stationThread).getRunBlockRerouteCommand(100, 10, 20, 0, 0.25d);
        assertSame(command, plan.command());
    }
 
    @Test
    void executePlan_skipsWhenCurrentTaskStillExistsInBuffer() {
        StationRerouteProcessor processor = new StationRerouteProcessor();
        StationCommand command = new StationCommand();
        command.setTaskNo(100);
        command.setStationId(10);
        command.setTargetStaNo(20);
 
        StationTaskBufferItem bufferItem = new StationTaskBufferItem();
        bufferItem.setTaskNo(100);
 
        RerouteContext context = RerouteContext.create(
                RerouteSceneType.OUT_ORDER,
                buildBasDevp(1),
                mock(StationThread.class),
                buildStationProtocol(10, 100, 10, Collections.singletonList(bufferItem)),
                buildWrkMast(100, 20),
                List.of(10, 20),
                0.0d,
                "checkStationOutOrder"
        );
 
        RerouteExecutionResult result = processor.executeReroutePlan(
                context,
                RerouteCommandPlan.dispatch(
                        command,
                        RerouteDecision.proceed(20),
                        "checkStationOutOrder"
                )
        );
 
        assertTrue(result.skipped());
        assertEquals("buffer-has-current-task", result.skipReason());
    }
 
    private static BasDevp buildBasDevp(int devpNo) {
        BasDevp basDevp = new BasDevp();
        basDevp.setDevpNo(devpNo);
        return basDevp;
    }
 
    private static WrkMast buildWrkMast(int wrkNo, int targetStationId) {
        WrkMast wrkMast = new WrkMast();
        wrkMast.setWrkNo(wrkNo);
        wrkMast.setStaNo(targetStationId);
        return wrkMast;
    }
 
    private static StationProtocol buildStationProtocol(int stationId,
                                                        int taskNo,
                                                        int targetStationId) {
        return buildStationProtocol(stationId, taskNo, targetStationId, Collections.emptyList());
    }
 
    private static StationProtocol buildStationProtocol(int stationId,
                                                        int taskNo,
                                                        int targetStationId,
                                                        List<StationTaskBufferItem> taskBufferItems) {
        StationProtocol stationProtocol = new StationProtocol();
        stationProtocol.setStationId(stationId);
        stationProtocol.setTaskNo(taskNo);
        stationProtocol.setTargetStaNo(targetStationId);
        stationProtocol.setTaskBufferItems(taskBufferItems);
        return stationProtocol;
    }
}