|
|
|
@ -18,6 +18,7 @@
|
|
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
|
import org.apache.dolphinscheduler.api.exceptions.ServiceException; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.impl.TaskDefinitionServiceImpl; |
|
|
|
|
import org.apache.dolphinscheduler.common.constants.Constants; |
|
|
|
@ -42,6 +43,8 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
import org.mockito.InjectMocks; |
|
|
|
|
import org.mockito.Mock; |
|
|
|
@ -77,6 +80,27 @@ public class TaskDefinitionServiceImplTest {
|
|
|
|
|
@Mock |
|
|
|
|
private TaskPluginManager taskPluginManager; |
|
|
|
|
|
|
|
|
|
private static final String TASK_PARAMETER = |
|
|
|
|
"{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 1\",\"conditionResult\":{\"successNode\":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}}";; |
|
|
|
|
private static final long PROJECT_CODE = 1L; |
|
|
|
|
private static final long PROCESS_DEFINITION_CODE = 2L; |
|
|
|
|
private static final long TASK_CODE = 3L; |
|
|
|
|
private static final int VERSION = 1; |
|
|
|
|
private static final int RESOURCE_RATE = -1; |
|
|
|
|
protected User user; |
|
|
|
|
protected Exception exception; |
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
|
public void before() { |
|
|
|
|
User loginUser = new User(); |
|
|
|
|
loginUser.setId(1); |
|
|
|
|
loginUser.setTenantId(2); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
loginUser.setUserName("admin"); |
|
|
|
|
user = loginUser; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void createTaskDefinition() { |
|
|
|
|
long projectCode = 1L; |
|
|
|
@ -110,45 +134,45 @@ public class TaskDefinitionServiceImplTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void updateTaskDefinition() { |
|
|
|
|
String taskDefinitionJson = "{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" |
|
|
|
|
+ "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\"," |
|
|
|
|
+ "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":" |
|
|
|
|
+ "\\\"echo ${datetime}\\\",\\\"conditionResult\\\":\\\"{\\\\\\\"successNode\\\\\\\":[\\\\\\\"\\\\\\\"]," |
|
|
|
|
+ "\\\\\\\"failedNode\\\\\\\":[\\\\\\\"\\\\\\\"]}\\\",\\\"dependence\\\":{}}\",\"flag\":0,\"taskPriority\":0," |
|
|
|
|
+ "\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":0,\"timeoutFlag\":0," |
|
|
|
|
+ "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}"; |
|
|
|
|
long projectCode = 1L; |
|
|
|
|
long taskCode = 1L; |
|
|
|
|
|
|
|
|
|
Project project = getProject(projectCode); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
|
|
|
|
|
|
User loginUser = new User(); |
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,TASK_DEFINITION_UPDATE)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
Mockito.when(processService.isTaskOnline(taskCode)).thenReturn(Boolean.FALSE); |
|
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(new TaskDefinition()); |
|
|
|
|
Mockito.when(taskDefinitionMapper.updateById(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(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true); |
|
|
|
|
Mockito.when(processTaskRelationMapper.queryByTaskCode(3)).thenReturn(getProcessTaskRelationList2()); |
|
|
|
|
Mockito.when(processTaskRelationMapper |
|
|
|
|
.updateProcessTaskRelationTaskVersion(Mockito.any(ProcessTaskRelation.class))).thenReturn(1); |
|
|
|
|
result = taskDefinitionService.updateTaskDefinition(user, PROJECT_CODE, TASK_CODE, taskDefinitionJson); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
|
// String taskDefinitionJson = "{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":"
|
|
|
|
|
// + "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\","
|
|
|
|
|
// + "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":"
|
|
|
|
|
// + "\\\"echo ${datetime}\\\",\\\"conditionResult\\\":\\\"{\\\\\\\"successNode\\\\\\\":[\\\\\\\"\\\\\\\"],"
|
|
|
|
|
// + "\\\\\\\"failedNode\\\\\\\":[\\\\\\\"\\\\\\\"]}\\\",\\\"dependence\\\":{}}\",\"flag\":0,\"taskPriority\":0,"
|
|
|
|
|
// + "\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":0,\"timeoutFlag\":0,"
|
|
|
|
|
// + "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}";
|
|
|
|
|
// long projectCode = 1L;
|
|
|
|
|
// long taskCode = 1L;
|
|
|
|
|
//
|
|
|
|
|
// Project project = getProject(projectCode);
|
|
|
|
|
// Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
|
|
|
|
|
//
|
|
|
|
|
// User loginUser = new User();
|
|
|
|
|
// loginUser.setId(-1);
|
|
|
|
|
// loginUser.setUserType(UserType.GENERAL_USER);
|
|
|
|
|
//
|
|
|
|
|
// Map<String, Object> result = new HashMap<>();
|
|
|
|
|
// putMsg(result, Status.SUCCESS, projectCode);
|
|
|
|
|
// Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, TASK_DEFINITION_UPDATE)).thenReturn(result);
|
|
|
|
|
//
|
|
|
|
|
// Mockito.when(processService.isTaskOnline(taskCode)).thenReturn(Boolean.FALSE);
|
|
|
|
|
// Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(new TaskDefinition());
|
|
|
|
|
// Mockito.when(taskDefinitionMapper.updateById(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(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true);
|
|
|
|
|
// Mockito.when(processTaskRelationMapper.queryByTaskCode(3)).thenReturn(getProcessTaskRelationList2());
|
|
|
|
|
// Mockito.when(processTaskRelationMapper
|
|
|
|
|
// .updateProcessTaskRelationTaskVersion(Mockito.any(ProcessTaskRelation.class))).thenReturn(1);
|
|
|
|
|
// result = taskDefinitionService.updateTaskDefinition(loginUser, projectCode, taskCode, taskDefinitionJson);
|
|
|
|
|
// Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
|
|
|
|
// failure
|
|
|
|
|
Mockito.when(processTaskRelationMapper |
|
|
|
|
.updateProcessTaskRelationTaskVersion(Mockito.any(ProcessTaskRelation.class))).thenReturn(2); |
|
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
|
() -> taskDefinitionService.updateTaskDefinition(user, PROJECT_CODE, TASK_CODE, taskDefinitionJson)); |
|
|
|
|
Assertions.assertEquals(Status.PROCESS_TASK_RELATION_BATCH_UPDATE_ERROR.getCode(), |
|
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
|
// Mockito.when(processTaskRelationMapper
|
|
|
|
|
// .updateProcessTaskRelationTaskVersion(Mockito.any(ProcessTaskRelation.class))).thenReturn(2);
|
|
|
|
|
// exception = Assertions.assertThrows(ServiceException.class,
|
|
|
|
|
// () -> taskDefinitionService.updateTaskDefinition(loginUser, PROJECT_CODE, taskCode, taskDefinitionJson));
|
|
|
|
|
// Assertions.assertEquals(Status.PROCESS_TASK_RELATION_BATCH_UPDATE_ERROR.getCode(),
|
|
|
|
|
// ((ServiceException) exception).getCode());
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|