|
|
|
@ -17,8 +17,6 @@
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.dao.mapper; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.CommandType; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.Flag; |
|
|
|
@ -40,13 +38,15 @@ import org.springframework.test.annotation.Rollback;
|
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
|
|
|
|
@RunWith(SpringRunner.class) |
|
|
|
|
@SpringBootTest |
|
|
|
|
@Transactional |
|
|
|
|
@Rollback(true) |
|
|
|
|
public class TaskInstanceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
TaskInstanceMapper taskInstanceMapper; |
|
|
|
|
|
|
|
|
@ -64,21 +64,32 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
* |
|
|
|
|
* @return TaskInstance |
|
|
|
|
*/ |
|
|
|
|
private TaskInstance insertOne() { |
|
|
|
|
private TaskInstance insertTaskInstance(int processInstanceId) { |
|
|
|
|
//insertOne
|
|
|
|
|
return insertOne("us task", 1, ExecutionStatus.RUNNING_EXECUTION, TaskType.SHELL.toString()); |
|
|
|
|
return insertTaskInstance("us task", processInstanceId, ExecutionStatus.RUNNING_EXECUTION, TaskType.SHELL.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* construct a task instance and then insert |
|
|
|
|
* insert |
|
|
|
|
* |
|
|
|
|
* @param taskName |
|
|
|
|
* @param processInstanceId |
|
|
|
|
* @param state |
|
|
|
|
* @param taskType |
|
|
|
|
* @return |
|
|
|
|
* @return ProcessInstance |
|
|
|
|
*/ |
|
|
|
|
private ProcessInstance insertProcessInstance() { |
|
|
|
|
ProcessInstance processInstance = new ProcessInstance(); |
|
|
|
|
processInstance.setId(1); |
|
|
|
|
processInstance.setName("taskName"); |
|
|
|
|
processInstance.setState(ExecutionStatus.RUNNING_EXECUTION); |
|
|
|
|
processInstance.setStartTime(new Date()); |
|
|
|
|
processInstance.setEndTime(new Date()); |
|
|
|
|
processInstance.setProcessDefinitionCode(1L); |
|
|
|
|
processInstanceMapper.insert(processInstance); |
|
|
|
|
return processInstanceMapper.queryByProcessDefineCode(1L,1).get(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* construct a task instance and then insert |
|
|
|
|
*/ |
|
|
|
|
private TaskInstance insertOne(String taskName, int processInstanceId, ExecutionStatus state, String taskType) { |
|
|
|
|
private TaskInstance insertTaskInstance(String taskName, int processInstanceId, ExecutionStatus state, String taskType) { |
|
|
|
|
TaskInstance taskInstance = new TaskInstance(); |
|
|
|
|
taskInstance.setFlag(Flag.YES); |
|
|
|
|
taskInstance.setName(taskName); |
|
|
|
@ -88,6 +99,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
taskInstance.setTaskJson("{}"); |
|
|
|
|
taskInstance.setProcessInstanceId(processInstanceId); |
|
|
|
|
taskInstance.setTaskType(taskType); |
|
|
|
|
taskInstance.setProcessDefinitionCode(1L); |
|
|
|
|
taskInstanceMapper.insert(taskInstance); |
|
|
|
|
return taskInstance; |
|
|
|
|
} |
|
|
|
@ -97,8 +109,11 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testUpdate() { |
|
|
|
|
//insertOne
|
|
|
|
|
TaskInstance taskInstance = insertOne(); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance taskInstance = insertTaskInstance(processInstance.getId()); |
|
|
|
|
// update
|
|
|
|
|
int update = taskInstanceMapper.updateById(taskInstance); |
|
|
|
|
Assert.assertEquals(1, update); |
|
|
|
@ -110,7 +125,12 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testDelete() { |
|
|
|
|
TaskInstance taskInstance = insertOne(); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance taskInstance = insertTaskInstance(processInstance.getId()); |
|
|
|
|
|
|
|
|
|
int delete = taskInstanceMapper.deleteById(taskInstance.getId()); |
|
|
|
|
Assert.assertEquals(1, delete); |
|
|
|
|
} |
|
|
|
@ -120,7 +140,11 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testQuery() { |
|
|
|
|
TaskInstance taskInstance = insertOne(); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance taskInstance = insertTaskInstance(processInstance.getId()); |
|
|
|
|
//query
|
|
|
|
|
List<TaskInstance> taskInstances = taskInstanceMapper.selectList(null); |
|
|
|
|
taskInstanceMapper.deleteById(taskInstance.getId()); |
|
|
|
@ -132,8 +156,12 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testQueryTaskByProcessIdAndState() { |
|
|
|
|
TaskInstance task = insertOne(); |
|
|
|
|
task.setProcessInstanceId(110); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance task = insertTaskInstance(processInstance.getId()); |
|
|
|
|
task.setProcessInstanceId(processInstance.getId()); |
|
|
|
|
taskInstanceMapper.updateById(task); |
|
|
|
|
List<Integer> taskInstances = taskInstanceMapper.queryTaskByProcessIdAndState( |
|
|
|
|
task.getProcessInstanceId(), |
|
|
|
@ -148,10 +176,14 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testFindValidTaskListByProcessId() { |
|
|
|
|
TaskInstance task = insertOne(); |
|
|
|
|
TaskInstance task2 = insertOne(); |
|
|
|
|
task.setProcessInstanceId(110); |
|
|
|
|
task2.setProcessInstanceId(110); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance task = insertTaskInstance(processInstance.getId()); |
|
|
|
|
TaskInstance task2 = insertTaskInstance(processInstance.getId()); |
|
|
|
|
task.setProcessInstanceId(processInstance.getId()); |
|
|
|
|
task2.setProcessInstanceId(processInstance.getId()); |
|
|
|
|
taskInstanceMapper.updateById(task); |
|
|
|
|
taskInstanceMapper.updateById(task2); |
|
|
|
|
|
|
|
|
@ -176,7 +208,11 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testQueryByHostAndStatus() { |
|
|
|
|
TaskInstance task = insertOne(); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance task = insertTaskInstance(processInstance.getId()); |
|
|
|
|
task.setHost("111.111.11.11"); |
|
|
|
|
taskInstanceMapper.updateById(task); |
|
|
|
|
|
|
|
|
@ -192,7 +228,11 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testSetFailoverByHostAndStateArray() { |
|
|
|
|
TaskInstance task = insertOne(); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance task = insertTaskInstance(processInstance.getId()); |
|
|
|
|
task.setHost("111.111.11.11"); |
|
|
|
|
taskInstanceMapper.updateById(task); |
|
|
|
|
|
|
|
|
@ -210,7 +250,11 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testQueryByInstanceIdAndName() { |
|
|
|
|
TaskInstance task = insertOne(); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance task = insertTaskInstance(processInstance.getId()); |
|
|
|
|
task.setHost("111.111.11.11"); |
|
|
|
|
taskInstanceMapper.updateById(task); |
|
|
|
|
|
|
|
|
@ -227,20 +271,26 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testCountTask() { |
|
|
|
|
TaskInstance task = insertOne(); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance task = insertTaskInstance(processInstance.getId()); |
|
|
|
|
ProcessDefinition definition = new ProcessDefinition(); |
|
|
|
|
definition.setCode(1L); |
|
|
|
|
definition.setProjectCode(1111L); |
|
|
|
|
definition.setCreateTime(new Date()); |
|
|
|
|
definition.setUpdateTime(new Date()); |
|
|
|
|
processDefinitionMapper.insert(definition); |
|
|
|
|
task.setProcessDefinitionId(definition.getId()); |
|
|
|
|
taskInstanceMapper.updateById(task); |
|
|
|
|
|
|
|
|
|
int countTask = taskInstanceMapper.countTask( |
|
|
|
|
new Integer[0], |
|
|
|
|
new Long[0], |
|
|
|
|
new int[0] |
|
|
|
|
); |
|
|
|
|
int countTask2 = taskInstanceMapper.countTask( |
|
|
|
|
new Integer[]{definition.getProjectId()}, |
|
|
|
|
new Long[]{definition.getProjectCode()}, |
|
|
|
|
new int[]{task.getId()} |
|
|
|
|
); |
|
|
|
|
taskInstanceMapper.deleteById(task.getId()); |
|
|
|
@ -257,12 +307,17 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testCountTaskInstanceStateByUser() { |
|
|
|
|
|
|
|
|
|
TaskInstance task = insertOne(); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance task = insertTaskInstance(processInstance.getId()); |
|
|
|
|
ProcessDefinition definition = new ProcessDefinition(); |
|
|
|
|
definition.setCode(1111L); |
|
|
|
|
definition.setProjectId(1111); |
|
|
|
|
definition.setProjectCode(1111L); |
|
|
|
|
|
|
|
|
|
definition.setCreateTime(new Date()); |
|
|
|
|
definition.setUpdateTime(new Date()); |
|
|
|
|
processDefinitionMapper.insert(definition); |
|
|
|
|
task.setProcessDefinitionId(definition.getId()); |
|
|
|
|
taskInstanceMapper.updateById(task); |
|
|
|
@ -282,21 +337,19 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testQueryTaskInstanceListPaging() { |
|
|
|
|
TaskInstance task = insertOne(); |
|
|
|
|
|
|
|
|
|
ProcessDefinition definition = new ProcessDefinition(); |
|
|
|
|
definition.setCode(1L); |
|
|
|
|
definition.setProjectId(1111); |
|
|
|
|
definition.setProjectCode(1111L); |
|
|
|
|
definition.setCreateTime(new Date()); |
|
|
|
|
definition.setUpdateTime(new Date()); |
|
|
|
|
processDefinitionMapper.insert(definition); |
|
|
|
|
|
|
|
|
|
ProcessInstance processInstance = new ProcessInstance(); |
|
|
|
|
processInstance.setProcessDefinitionId(definition.getId()); |
|
|
|
|
processInstance.setState(ExecutionStatus.RUNNING_EXECUTION); |
|
|
|
|
processInstance.setName("ut process"); |
|
|
|
|
processInstance.setStartTime(new Date()); |
|
|
|
|
processInstance.setEndTime(new Date()); |
|
|
|
|
processInstance.setCommandType(CommandType.START_PROCESS); |
|
|
|
|
processInstanceMapper.insert(processInstance); |
|
|
|
|
// insert ProcessInstance
|
|
|
|
|
ProcessInstance processInstance = insertProcessInstance(); |
|
|
|
|
|
|
|
|
|
// insert taskInstance
|
|
|
|
|
TaskInstance task = insertTaskInstance(processInstance.getId()); |
|
|
|
|
|
|
|
|
|
task.setProcessDefinitionId(definition.getId()); |
|
|
|
|
task.setProcessInstanceId(processInstance.getId()); |
|
|
|
@ -305,7 +358,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
Page<TaskInstance> page = new Page(1, 3); |
|
|
|
|
IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging( |
|
|
|
|
page, |
|
|
|
|
definition.getProjectId(), |
|
|
|
|
definition.getProjectCode(), |
|
|
|
|
task.getProcessInstanceId(), |
|
|
|
|
"", |
|
|
|
|
"", |
|
|
|
|