mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
fix(ActionExecutor): correct logic in ActionExecutor when actionChain is empty, which will skip execution
This commit is contained in:
@@ -18,7 +18,6 @@ import work.slhaf.partner.module.modules.action.dispatcher.executor.entity.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Phaser;
|
||||
@@ -72,6 +71,12 @@ public class ActionExecutor extends AgentRunningSubModule<ActionExecutorInput, V
|
||||
if (actionData.getStatus() != ActionData.ActionStatus.PREPARE) {
|
||||
return;
|
||||
}
|
||||
val actionChain = actionData.getActionChain();
|
||||
if (actionChain.isEmpty()) {
|
||||
actionData.setStatus(ActionStatus.FAILED);
|
||||
actionData.setResult("行动链为空");
|
||||
return;
|
||||
}
|
||||
// 注册执行中行动
|
||||
val phaser = new Phaser();
|
||||
val phaserRecord = actionCapability.putPhaserRecord(phaser, actionData);
|
||||
@@ -79,7 +84,6 @@ public class ActionExecutor extends AgentRunningSubModule<ActionExecutorInput, V
|
||||
|
||||
// 开始执行
|
||||
val stageCursor = new Object() {
|
||||
final Map<Integer, List<MetaAction>> actionChain = actionData.getActionChain();
|
||||
int stageCount;
|
||||
boolean executingStageUpdated;
|
||||
boolean stageCountUpdated;
|
||||
@@ -118,7 +122,6 @@ public class ActionExecutor extends AgentRunningSubModule<ActionExecutorInput, V
|
||||
|
||||
stageCursor.init();
|
||||
do {
|
||||
val actionChain = actionData.getActionChain();
|
||||
val metaActions = actionChain.get(actionData.getExecutingStage());
|
||||
|
||||
val listeningRecord = executeAndListening(metaActions, phaserRecord, userId);
|
||||
|
||||
@@ -346,8 +346,9 @@ class ActionExecutorTest {
|
||||
@Tag("known-issue")
|
||||
@Test
|
||||
void execute_emptyActionChain_shouldFail() {
|
||||
ExecutorService directExecutor = new DirectExecutorService();
|
||||
stubExecutors(directExecutor, directExecutor);
|
||||
ExecutorService platformExecutor = Executors.newCachedThreadPool();
|
||||
ExecutorService virtualExecutor = Executors.newCachedThreadPool();
|
||||
stubExecutors(platformExecutor, virtualExecutor);
|
||||
|
||||
ImmediateActionData actionData = buildActionData(new HashMap<>());
|
||||
ActionExecutorInput input = buildInput("u1", actionData);
|
||||
@@ -355,7 +356,10 @@ class ActionExecutorTest {
|
||||
actionExecutor.init();
|
||||
actionExecutor.execute(input);
|
||||
|
||||
verify(actionCapability, never()).removePhaserRecord(any(Phaser.class));
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private void stubExecutors(ExecutorService platformExecutor, ExecutorService virtualExecutor) {
|
||||
|
||||
Reference in New Issue
Block a user