Browse Source

[Feature][jsonsplit]fix TaskInstanceMapperTest (#5010)

* fix TaskInstanceMapperTest
pull/3/MERGE
Simon 4 years ago committed by GitHub
parent
commit
40bcb2e818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
  2. 9
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java
  3. 4
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java
  4. 8
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
  5. 143
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java

@ -118,7 +118,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst
int executorId = usersService.getUserIdByName(executorName); int executorId = usersService.getUserIdByName(executorName);
IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging( IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(
page, project.getId(), processInstanceId, processInstanceName, searchVal, taskName, executorId, statusArray, host, start, end page, project.getCode(), processInstanceId, processInstanceName, searchVal, taskName, executorId, statusArray, host, start, end
); );
Set<String> exclusionSet = new HashSet<>(); Set<String> exclusionSet = new HashSet<>();
exclusionSet.add(Constants.CLASS); exclusionSet.add(Constants.CLASS);

9
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java

@ -117,7 +117,7 @@ public class TaskInstanceServiceTest {
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser);
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId());
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getId()), eq(1), eq(""), eq(""), eq(""), when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""),
eq(0), Mockito.any(), eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); eq(0), Mockito.any(), eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn);
when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser);
when(processService.findProcessInstanceDetailById(taskInstance.getProcessInstanceId())).thenReturn(processInstance); when(processService.findProcessInstanceDetailById(taskInstance.getProcessInstanceId())).thenReturn(processInstance);
@ -127,7 +127,7 @@ public class TaskInstanceServiceTest {
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
//executor name empty //executor name empty
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getId()), eq(1), eq(""), eq(""), eq(""), when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""),
eq(0), Mockito.any(), eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); eq(0), Mockito.any(), eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn);
Map<String, Object> executorEmptyRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", Map<String, Object> executorEmptyRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "",
"", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); "", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20);
@ -141,14 +141,14 @@ public class TaskInstanceServiceTest {
Assert.assertEquals(Status.SUCCESS, executorNullRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, executorNullRes.get(Constants.STATUS));
//start/end date null //start/end date null
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getId()), eq(1), eq(""), eq(""), eq(""), when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""),
eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn); eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn);
Map<String, Object> executorNullDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", Map<String, Object> executorNullDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "",
"", null, null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); "", null, null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20);
Assert.assertEquals(Status.SUCCESS, executorNullDateRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, executorNullDateRes.get(Constants.STATUS));
//start date error format //start date error format
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getId()), eq(1), eq(""), eq(""), eq(""), when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""),
eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn); eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn);
Map<String, Object> executorErrorStartDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", Map<String, Object> executorErrorStartDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "",
"", "error date", null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); "", "error date", null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20);
@ -179,6 +179,7 @@ public class TaskInstanceServiceTest {
*/ */
private Project getProject(String projectName) { private Project getProject(String projectName) {
Project project = new Project(); Project project = new Project();
project.setCode(1L);
project.setId(1); project.setId(1);
project.setName(projectName); project.setName(projectName);
project.setUserId(1); project.setUserId(1);

4
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java

@ -52,7 +52,7 @@ public interface TaskInstanceMapper extends BaseMapper<TaskInstance> {
@Param("name") String name); @Param("name") String name);
Integer countTask( Integer countTask(
@Param("projectIds") Integer[] projectIds, @Param("projectCodes") Long[] projectCodes,
@Param("taskIds") int[] taskIds); @Param("taskIds") int[] taskIds);
List<ExecuteStatusCount> countTaskInstanceStateByUser( List<ExecuteStatusCount> countTaskInstanceStateByUser(
@ -61,7 +61,7 @@ public interface TaskInstanceMapper extends BaseMapper<TaskInstance> {
@Param("projectCodes") Long[] projectCodes); @Param("projectCodes") Long[] projectCodes);
IPage<TaskInstance> queryTaskInstanceListPaging(IPage<TaskInstance> page, IPage<TaskInstance> queryTaskInstanceListPaging(IPage<TaskInstance> page,
@Param("projectId") int projectId, @Param("projectCode") Long projectCode,
@Param("processInstanceId") Integer processInstanceId, @Param("processInstanceId") Integer processInstanceId,
@Param("processInstanceName") String processInstanceName, @Param("processInstanceName") String processInstanceName,
@Param("searchVal") String searchVal, @Param("searchVal") String searchVal,

8
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml

@ -99,9 +99,9 @@
select count(1) as count select count(1) as count
from t_ds_task_instance task,t_ds_process_definition process from t_ds_task_instance task,t_ds_process_definition process
where task.process_definition_code=process.code where task.process_definition_code=process.code
<if test="projectIds != null and projectIds.length != 0"> <if test="projectCodes != null and projectCodes.length != 0">
and process.project_id in and process.project_code in
<foreach collection="projectIds" index="index" item="i" open="(" separator="," close=")"> <foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i} #{i}
</foreach> </foreach>
</if> </if>
@ -122,7 +122,7 @@
from t_ds_task_instance instance from t_ds_task_instance instance
left join t_ds_process_definition define on instance.process_definition_code = define.code left join t_ds_process_definition define on instance.process_definition_code = define.code
left join t_ds_process_instance process on process.id=instance.process_instance_id left join t_ds_process_instance process on process.id=instance.process_instance_id
where define.project_id = #{projectId} where define.project_code = #{projectCode}
<if test="startTime != null"> <if test="startTime != null">
and instance.start_time > #{startTime} and instance.start_time <![CDATA[ <=]]> #{endTime} and instance.start_time > #{startTime} and instance.start_time <![CDATA[ <=]]> #{endTime}
</if> </if>

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

@ -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());

Loading…
Cancel
Save