hsupu commented on a change in pull request #3442:
URL:
https://github.com/apache/incubator-dolphinscheduler/pull/3442#discussion_r467477883
##########
File path:
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/master/DependentTaskTest.java
##########
@@ -37,188 +42,379 @@
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
@RunWith(MockitoJUnitRunner.Silent.class)
public class DependentTaskTest {
private static final Logger logger =
LoggerFactory.getLogger(DependentTaskTest.class);
- private ProcessService processService;
- private ApplicationContext applicationContext;
+ /**
+ * TaskNode.runFlag : task can be run normally
+ */
+ public static final String FLOWNODE_RUN_FLAG_NORMAL = "NORMAL";
+ private ProcessService processService;
- private MasterConfig config;
+ /**
+ * the dependent task to be tested
+ * ProcessDefinition id=1
+ * Task id=task-10, name=D
+ * ProcessInstance id=100
+ * TaskInstance id=1000
+ * notice: must be initialized by setupTaskInstance() on each test case
+ */
+ private TaskInstance taskInstance;
@Before
- public void before() throws Exception{
+ public void before() throws Exception {
+ ApplicationContext applicationContext =
Mockito.mock(ApplicationContext.class);
+ SpringApplicationContext springApplicationContext = new
SpringApplicationContext();
+ springApplicationContext.setApplicationContext(applicationContext);
- config = new MasterConfig();
+ MasterConfig config = new MasterConfig();
config.setMasterTaskCommitRetryTimes(3);
config.setMasterTaskCommitInterval(1000);
+
Mockito.when(applicationContext.getBean(MasterConfig.class)).thenReturn(config);
+
processService = Mockito.mock(ProcessService.class);
- DateInterval dateInterval =DependentDateUtils.getTodayInterval(new
Date()).get(0);
- Mockito.when(processService
- .findLastRunningProcess(4, dateInterval.getStartTime(),
- dateInterval.getEndTime()))
- .thenReturn(findLastProcessInterval());
+
Mockito.when(applicationContext.getBean(ProcessService.class)).thenReturn(processService);
+ ProcessDefinition processDefinition = getProcessDefinition(1);
+ ProcessInstance processInstance = getProcessInstance(100, 1);
+ taskInstance = new TaskInstance();
+ taskInstance.setId(1000);
+ taskInstance.setProcessInstanceId(processInstance.getId());
+
taskInstance.setProcessDefinitionId(processInstance.getProcessDefinitionId());
+ // for MasterBaseTaskExecThread.call
+ Mockito.when(processService.findProcessDefineById(1))
+ .thenReturn(processDefinition);
Review comment:
You're right, I check this and updated.
##########
File path:
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/master/DependentTaskTest.java
##########
@@ -37,188 +42,379 @@
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
@RunWith(MockitoJUnitRunner.Silent.class)
public class DependentTaskTest {
private static final Logger logger =
LoggerFactory.getLogger(DependentTaskTest.class);
- private ProcessService processService;
- private ApplicationContext applicationContext;
+ /**
+ * TaskNode.runFlag : task can be run normally
+ */
+ public static final String FLOWNODE_RUN_FLAG_NORMAL = "NORMAL";
+ private ProcessService processService;
- private MasterConfig config;
+ /**
+ * the dependent task to be tested
+ * ProcessDefinition id=1
+ * Task id=task-10, name=D
+ * ProcessInstance id=100
+ * TaskInstance id=1000
+ * notice: must be initialized by setupTaskInstance() on each test case
+ */
+ private TaskInstance taskInstance;
@Before
- public void before() throws Exception{
+ public void before() throws Exception {
+ ApplicationContext applicationContext =
Mockito.mock(ApplicationContext.class);
+ SpringApplicationContext springApplicationContext = new
SpringApplicationContext();
+ springApplicationContext.setApplicationContext(applicationContext);
- config = new MasterConfig();
+ MasterConfig config = new MasterConfig();
config.setMasterTaskCommitRetryTimes(3);
config.setMasterTaskCommitInterval(1000);
+
Mockito.when(applicationContext.getBean(MasterConfig.class)).thenReturn(config);
+
processService = Mockito.mock(ProcessService.class);
- DateInterval dateInterval =DependentDateUtils.getTodayInterval(new
Date()).get(0);
- Mockito.when(processService
- .findLastRunningProcess(4, dateInterval.getStartTime(),
- dateInterval.getEndTime()))
- .thenReturn(findLastProcessInterval());
+
Mockito.when(applicationContext.getBean(ProcessService.class)).thenReturn(processService);
+ ProcessDefinition processDefinition = getProcessDefinition(1);
+ ProcessInstance processInstance = getProcessInstance(100, 1);
+ taskInstance = new TaskInstance();
+ taskInstance.setId(1000);
+ taskInstance.setProcessInstanceId(processInstance.getId());
+
taskInstance.setProcessDefinitionId(processInstance.getProcessDefinitionId());
+ // for MasterBaseTaskExecThread.call
+ Mockito.when(processService.findProcessDefineById(1))
+ .thenReturn(processDefinition);
Review comment:
You're right, I checked this and updated.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]