|
|
@ -22,14 +22,12 @@ import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; |
|
|
|
import org.apache.dolphinscheduler.api.service.impl.TaskDefinitionServiceImpl; |
|
|
|
import org.apache.dolphinscheduler.api.service.impl.TaskDefinitionServiceImpl; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
import org.apache.dolphinscheduler.common.model.TaskNode; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.task.shell.ShellParameters; |
|
|
|
import org.apache.dolphinscheduler.common.task.shell.ShellParameters; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; |
|
|
@ -37,6 +35,7 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
|
|
|
|
|
|
|
|
import java.text.MessageFormat; |
|
|
|
import java.text.MessageFormat; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
@ -51,48 +50,6 @@ import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
|
|
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
public class TaskDefinitionServiceImplTest { |
|
|
|
public class TaskDefinitionServiceImplTest { |
|
|
|
String taskDefinitionJson = "{\n" |
|
|
|
|
|
|
|
+ " \"type\": \"SQL\",\n" |
|
|
|
|
|
|
|
+ " \"id\": \"tasks-27297\",\n" |
|
|
|
|
|
|
|
+ " \"name\": \"SQL\",\n" |
|
|
|
|
|
|
|
+ " \"params\": {\n" |
|
|
|
|
|
|
|
+ " \"type\": \"MYSQL\",\n" |
|
|
|
|
|
|
|
+ " \"datasource\": 1,\n" |
|
|
|
|
|
|
|
+ " \"sql\": \"select * from test\",\n" |
|
|
|
|
|
|
|
+ " \"udfs\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"sqlType\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"title\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"receivers\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"receiversCc\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"showType\": \"TABLE\",\n" |
|
|
|
|
|
|
|
+ " \"localParams\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"connParams\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"preStatements\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"postStatements\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"description\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"runFlag\": \"NORMAL\",\n" |
|
|
|
|
|
|
|
+ " \"dependence\": {\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"maxRetryTimes\": \"0\",\n" |
|
|
|
|
|
|
|
+ " \"retryInterval\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"timeout\": {\n" |
|
|
|
|
|
|
|
+ " \"strategy\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"enable\": false\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"taskInstancePriority\": \"MEDIUM\",\n" |
|
|
|
|
|
|
|
+ " \"workerGroupId\": -1,\n" |
|
|
|
|
|
|
|
+ " \"preTasks\": [\n" |
|
|
|
|
|
|
|
+ " \"dependent\"\n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ "}\n"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@InjectMocks |
|
|
|
@InjectMocks |
|
|
|
private TaskDefinitionServiceImpl taskDefinitionService; |
|
|
|
private TaskDefinitionServiceImpl taskDefinitionService; |
|
|
@ -103,12 +60,6 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private TaskDefinitionLogMapper taskDefinitionLogMapper; |
|
|
|
private TaskDefinitionLogMapper taskDefinitionLogMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
private ProcessDefinitionMapper processDefineMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private ProjectMapper projectMapper; |
|
|
|
private ProjectMapper projectMapper; |
|
|
|
|
|
|
|
|
|
|
@ -118,6 +69,10 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private ProcessService processService; |
|
|
|
private ProcessService processService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createTaskDefinition() { |
|
|
|
public void createTaskDefinition() { |
|
|
|
long projectCode = 1L; |
|
|
|
long projectCode = 1L; |
|
|
@ -144,13 +99,13 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
Mockito.when(taskDefinitionMapper.batchInsert(Mockito.anyList())).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionMapper.batchInsert(Mockito.anyList())).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.batchInsert(Mockito.anyList())).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.batchInsert(Mockito.anyList())).thenReturn(1); |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
.createTaskDefinition(loginUser, projectCode, createTaskDefinitionJson); |
|
|
|
.createTaskDefinition(loginUser, projectCode, createTaskDefinitionJson); |
|
|
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void updateTaskDefinition () { |
|
|
|
public void updateTaskDefinition() { |
|
|
|
String taskDefinitionJson = "{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" |
|
|
|
String taskDefinitionJson = "{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" |
|
|
|
+ "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\"," |
|
|
|
+ "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\"," |
|
|
|
+ "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":" |
|
|
|
+ "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":" |
|
|
@ -173,7 +128,7 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(processService.isTaskOnline(taskCode)).thenReturn(Boolean.FALSE); |
|
|
|
Mockito.when(processService.isTaskOnline(taskCode)).thenReturn(Boolean.FALSE); |
|
|
|
Mockito.when(taskDefinitionMapper.queryByDefinitionCode(taskCode)).thenReturn(new TaskDefinition()); |
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(new TaskDefinition()); |
|
|
|
Mockito.when(taskDefinitionMapper.updateById(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionMapper.updateById(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.insert(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.insert(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.queryMaxVersionForDefinition(taskCode)).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.queryMaxVersionForDefinition(taskCode)).thenReturn(1); |
|
|
@ -197,13 +152,11 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); |
|
|
|
Mockito.when(taskDefinitionMapper.queryByName(project.getCode(), taskName)) |
|
|
|
|
|
|
|
.thenReturn(new TaskDefinition()); |
|
|
|
Mockito.when(taskDefinitionMapper.queryByDefinitionName(project.getCode(), taskName)) |
|
|
|
|
|
|
|
.thenReturn(new TaskDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
.queryTaskDefinitionByName(loginUser, projectCode, taskName); |
|
|
|
.queryTaskDefinitionByName(loginUser, projectCode, taskName); |
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
@ -222,17 +175,15 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
|
|
|
|
|
|
|
Mockito.when(processTaskRelationMapper.queryByTaskCode(Mockito.anyLong())) |
|
|
|
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); |
|
|
|
.thenReturn(new ArrayList<>()); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(taskDefinitionMapper.deleteByCode(Mockito.anyLong())) |
|
|
|
Mockito.when(taskDefinitionMapper.deleteByCode(Mockito.anyLong())) |
|
|
|
.thenReturn(1); |
|
|
|
.thenReturn(1); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
.deleteTaskDefinitionByCode(loginUser, projectCode, 11L); |
|
|
|
.deleteTaskDefinitionByCode(loginUser, projectCode, Mockito.anyLong()); |
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -252,16 +203,14 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version)) |
|
|
|
Mockito.when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version)) |
|
|
|
.thenReturn(new TaskDefinitionLog()); |
|
|
|
.thenReturn(new TaskDefinitionLog()); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(taskDefinitionMapper.queryByDefinitionCode(taskCode)) |
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(taskCode)) |
|
|
|
.thenReturn(new TaskDefinition()); |
|
|
|
.thenReturn(new TaskDefinition()); |
|
|
|
|
|
|
|
Mockito.when(taskDefinitionMapper.updateById(new TaskDefinitionLog())).thenReturn(1); |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
.switchVersion(loginUser, projectCode, taskCode, version); |
|
|
|
.switchVersion(loginUser, projectCode, taskCode, version); |
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|