Browse Source

add taskInstanceMapperTest

pull/3/MERGE
Zhou Zheng 4 years ago
parent
commit
b418b681e2
  1. 82
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java

82
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java

@ -19,23 +19,23 @@ package org.apache.dolphinscheduler.dao.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import javafx.concurrent.Task;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.TaskType;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.dao.entity.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.internal.junit.ExceptionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -55,20 +55,39 @@ public class TaskInstanceMapperTest {
@Autowired
ProcessInstanceMapper processInstanceMapper;
@Autowired
ProcessInstanceMapMapper processInstanceMapMapper;
/**
* insert
* @return TaskInstance
*/
private TaskInstance insertOne(){
//insertOne
return insertOne("us task", 1, ExecutionStatus.RUNNING_EXEUTION, TaskType.SHELL.toString());
}
/**
* construct a task instance and then insert
* @param taskName
* @param processInstanceId
* @param state
* @param taskType
* @return
*/
private TaskInstance insertOne(String taskName,
int processInstanceId,
ExecutionStatus state,
String taskType) {
TaskInstance taskInstance = new TaskInstance();
taskInstance.setFlag(Flag.YES);
taskInstance.setName("ut task");
taskInstance.setState(ExecutionStatus.RUNNING_EXEUTION);
taskInstance.setName(taskName);
taskInstance.setState(state);
taskInstance.setStartTime(new Date());
taskInstance.setEndTime(new Date());
taskInstance.setTaskJson("{}");
taskInstance.setTaskType(TaskType.SHELL.toString());
taskInstance.setProcessInstanceId(processInstanceId);
taskInstance.setTaskType(taskType);
taskInstanceMapper.insert(taskInstance);
return taskInstance;
}
@ -297,4 +316,53 @@ public class TaskInstanceMapperTest {
Assert.assertNotEquals(taskInstanceIPage.getTotal(), 0);
}
@Test
public void testQueryTaskByPIdAndStatusAndType() {
// insert three task instances with the same process instance id
List<TaskInstance> taskList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
String name = "ut task" + String.valueOf(i);
taskList.add(insertOne(name, 66, ExecutionStatus.FAILURE, TaskType.SUB_PROCESS.toString()));
}
// test query result
List<Integer> resultArray = taskInstanceMapper.queryTaskByPIdAndStatusAndType(66,
new int[]{ExecutionStatus.FAILURE.ordinal(), ExecutionStatus.KILL.ordinal(), ExecutionStatus.NEED_FAULT_TOLERANCE.ordinal()},
TaskType.SUB_PROCESS.toString());
Assert.assertEquals(3, resultArray.size());
// delete
for (int i = 0; i < 3; i++) {
taskInstanceMapper.deleteById(taskList.get(i));
}
}
@Test
public void testQueryTaskBySubProcessTaskIdAndStatusAndType() {
TaskInstance parentTask = insertOne("parent-task",66, ExecutionStatus.FAILURE, TaskType.SUB_PROCESS.toString());
ProcessInstanceMap processInstanceMap = new ProcessInstanceMap();
processInstanceMap.setParentProcessInstanceId(66);
processInstanceMap.setParentTaskInstanceId(parentTask.getId());
processInstanceMap.setProcessInstanceId(67);
processInstanceMapMapper.insert(processInstanceMap);
TaskInstance subTask1 = insertOne("sub1", 67, ExecutionStatus.SUCCESS, TaskType.SHELL.toString());
TaskInstance subTask2 = insertOne("sub2", 67, ExecutionStatus.FORCED_SUCCESS, TaskType.SHELL.toString());
// test query result
List<Integer> resultList = taskInstanceMapper.queryTaskBySubProcessTaskIdAndStatusAndType(parentTask.getId(),
new int[]{ExecutionStatus.FORCED_SUCCESS.ordinal()},
null);
Assert.assertEquals(1, resultList.size());
Assert.assertEquals(subTask2.getId(), resultList.get(0).intValue());
// delete
taskInstanceMapper.deleteById(parentTask.getId());
processInstanceMapMapper.deleteById(processInstanceMap.getId());
taskInstanceMapper.deleteById(subTask1.getId());
taskInstanceMapper.deleteById(subTask2.getId());
}
}
Loading…
Cancel
Save