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