|
|
|
@ -60,6 +60,7 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper;
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UserMapper; |
|
|
|
|
import org.apache.dolphinscheduler.service.exceptions.ServiceException; |
|
|
|
|
import org.apache.dolphinscheduler.service.quartz.cron.CronUtilsTest; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
@ -72,7 +73,9 @@ import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
|
import org.junit.Rule; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
import org.mockito.InjectMocks; |
|
|
|
|
import org.mockito.Mock; |
|
|
|
@ -92,6 +95,9 @@ public class ProcessServiceTest {
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(CronUtilsTest.class); |
|
|
|
|
|
|
|
|
|
@Rule |
|
|
|
|
public final ExpectedException exception = ExpectedException.none(); |
|
|
|
|
|
|
|
|
|
@InjectMocks |
|
|
|
|
private ProcessService processService; |
|
|
|
|
@Mock |
|
|
|
@ -255,10 +261,12 @@ public class ProcessServiceTest {
|
|
|
|
|
int processInstanceId = 222; |
|
|
|
|
//there is not enough thread for this command
|
|
|
|
|
Command command1 = new Command(); |
|
|
|
|
command1.setId(1); |
|
|
|
|
command1.setProcessDefinitionCode(definitionCode); |
|
|
|
|
command1.setProcessDefinitionVersion(definitionVersion); |
|
|
|
|
command1.setCommandParam("{\"ProcessInstanceId\":222}"); |
|
|
|
|
command1.setCommandType(CommandType.START_PROCESS); |
|
|
|
|
Mockito.when(commandMapper.deleteById(1)).thenReturn(1); |
|
|
|
|
|
|
|
|
|
ProcessDefinition processDefinition = new ProcessDefinition(); |
|
|
|
|
processDefinition.setId(123); |
|
|
|
@ -284,31 +292,37 @@ public class ProcessServiceTest {
|
|
|
|
|
Assert.assertNotNull(processService.handleCommand(logger, host, command1, processDefinitionCacheMaps)); |
|
|
|
|
|
|
|
|
|
Command command2 = new Command(); |
|
|
|
|
command2.setId(2); |
|
|
|
|
command2.setCommandParam("{\"ProcessInstanceId\":222,\"StartNodeIdList\":\"n1,n2\"}"); |
|
|
|
|
command2.setProcessDefinitionCode(definitionCode); |
|
|
|
|
command2.setProcessDefinitionVersion(definitionVersion); |
|
|
|
|
command2.setCommandType(CommandType.RECOVER_SUSPENDED_PROCESS); |
|
|
|
|
command2.setProcessInstanceId(processInstanceId); |
|
|
|
|
|
|
|
|
|
Mockito.when(commandMapper.deleteById(2)).thenReturn(1); |
|
|
|
|
Assert.assertNotNull(processService.handleCommand(logger, host, command2, processDefinitionCacheMaps)); |
|
|
|
|
|
|
|
|
|
Command command3 = new Command(); |
|
|
|
|
command3.setId(3); |
|
|
|
|
command3.setProcessDefinitionCode(definitionCode); |
|
|
|
|
command3.setProcessDefinitionVersion(definitionVersion); |
|
|
|
|
command3.setProcessInstanceId(processInstanceId); |
|
|
|
|
command3.setCommandParam("{\"WaitingThreadInstanceId\":222}"); |
|
|
|
|
command3.setCommandType(CommandType.START_FAILURE_TASK_PROCESS); |
|
|
|
|
Mockito.when(commandMapper.deleteById(3)).thenReturn(1); |
|
|
|
|
Assert.assertNotNull(processService.handleCommand(logger, host, command3, processDefinitionCacheMaps)); |
|
|
|
|
|
|
|
|
|
Command command4 = new Command(); |
|
|
|
|
command4.setId(4); |
|
|
|
|
command4.setProcessDefinitionCode(definitionCode); |
|
|
|
|
command4.setProcessDefinitionVersion(definitionVersion); |
|
|
|
|
command4.setCommandParam("{\"WaitingThreadInstanceId\":222,\"StartNodeIdList\":\"n1,n2\"}"); |
|
|
|
|
command4.setCommandType(CommandType.REPEAT_RUNNING); |
|
|
|
|
command4.setProcessInstanceId(processInstanceId); |
|
|
|
|
Mockito.when(commandMapper.deleteById(4)).thenReturn(1); |
|
|
|
|
Assert.assertNotNull(processService.handleCommand(logger, host, command4, processDefinitionCacheMaps)); |
|
|
|
|
|
|
|
|
|
Command command5 = new Command(); |
|
|
|
|
command5.setId(5); |
|
|
|
|
command5.setProcessDefinitionCode(definitionCode); |
|
|
|
|
command5.setProcessDefinitionVersion(definitionVersion); |
|
|
|
|
HashMap<String, String> startParams = new HashMap<>(); |
|
|
|
@ -318,6 +332,7 @@ public class ProcessServiceTest {
|
|
|
|
|
command5.setCommandParam(JSONUtils.toJsonString(commandParams)); |
|
|
|
|
command5.setCommandType(CommandType.START_PROCESS); |
|
|
|
|
command5.setDryRun(Constants.DRY_RUN_FLAG_NO); |
|
|
|
|
Mockito.when(commandMapper.deleteById(5)).thenReturn(1); |
|
|
|
|
ProcessInstance processInstance1 = processService.handleCommand(logger, host, command5, processDefinitionCacheMaps); |
|
|
|
|
Assert.assertTrue(processInstance1.getGlobalParams().contains("\"testStartParam1\"")); |
|
|
|
|
|
|
|
|
@ -342,14 +357,18 @@ public class ProcessServiceTest {
|
|
|
|
|
processInstance2.setProcessDefinitionVersion(1); |
|
|
|
|
Mockito.when(processInstanceMapper.queryDetailById(223)).thenReturn(processInstance2); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(11L)).thenReturn(processDefinition1); |
|
|
|
|
Mockito.when(commandMapper.deleteById(1)).thenReturn(1); |
|
|
|
|
Assert.assertNotNull(processService.handleCommand(logger, host, command1, processDefinitionCacheMaps)); |
|
|
|
|
|
|
|
|
|
Command command6 = new Command(); |
|
|
|
|
command6.setId(6); |
|
|
|
|
command6.setProcessDefinitionCode(11L); |
|
|
|
|
command6.setCommandParam("{\"ProcessInstanceId\":223}"); |
|
|
|
|
command6.setCommandType(CommandType.RECOVER_SERIAL_WAIT); |
|
|
|
|
command6.setProcessDefinitionVersion(1); |
|
|
|
|
Mockito.when(processInstanceMapper.queryByProcessDefineCodeAndStatusAndNextId(11L,Constants.RUNNING_PROCESS_STATE,223)).thenReturn(lists); |
|
|
|
|
Mockito.when(processInstanceMapper.updateNextProcessIdById(223, 222)).thenReturn(true); |
|
|
|
|
Mockito.when(commandMapper.deleteById(6)).thenReturn(1); |
|
|
|
|
ProcessInstance processInstance6 = processService.handleCommand(logger, host, command6, processDefinitionCacheMaps); |
|
|
|
|
Assert.assertTrue(processInstance6 != null); |
|
|
|
|
|
|
|
|
@ -362,10 +381,12 @@ public class ProcessServiceTest {
|
|
|
|
|
Mockito.when(processInstanceMapper.queryDetailById(224)).thenReturn(processInstance7); |
|
|
|
|
|
|
|
|
|
Command command7 = new Command(); |
|
|
|
|
command7.setId(7); |
|
|
|
|
command7.setProcessDefinitionCode(11L); |
|
|
|
|
command7.setCommandParam("{\"ProcessInstanceId\":224}"); |
|
|
|
|
command7.setCommandType(CommandType.RECOVER_SERIAL_WAIT); |
|
|
|
|
command7.setProcessDefinitionVersion(1); |
|
|
|
|
Mockito.when(commandMapper.deleteById(7)).thenReturn(1); |
|
|
|
|
Mockito.when(processInstanceMapper.queryByProcessDefineCodeAndStatusAndNextId(11L,Constants.RUNNING_PROCESS_STATE,224)).thenReturn(null); |
|
|
|
|
ProcessInstance processInstance8 = processService.handleCommand(logger, host, command7, processDefinitionCacheMaps); |
|
|
|
|
Assert.assertTrue(processInstance8 == null); |
|
|
|
@ -382,6 +403,7 @@ public class ProcessServiceTest {
|
|
|
|
|
processInstance9.setProcessDefinitionCode(11L); |
|
|
|
|
processInstance9.setProcessDefinitionVersion(1); |
|
|
|
|
Command command9 = new Command(); |
|
|
|
|
command9.setId(9); |
|
|
|
|
command9.setProcessDefinitionCode(12L); |
|
|
|
|
command9.setCommandParam("{\"ProcessInstanceId\":225}"); |
|
|
|
|
command9.setCommandType(CommandType.RECOVER_SERIAL_WAIT); |
|
|
|
@ -389,10 +411,51 @@ public class ProcessServiceTest {
|
|
|
|
|
Mockito.when(processInstanceMapper.queryDetailById(225)).thenReturn(processInstance9); |
|
|
|
|
Mockito.when(processInstanceMapper.queryByProcessDefineCodeAndStatusAndNextId(12L,Constants.RUNNING_PROCESS_STATE,0)).thenReturn(lists); |
|
|
|
|
Mockito.when(processInstanceMapper.updateById(processInstance)).thenReturn(1); |
|
|
|
|
Mockito.when(commandMapper.deleteById(9)).thenReturn(1); |
|
|
|
|
ProcessInstance processInstance10 = processService.handleCommand(logger, host, command9, processDefinitionCacheMaps); |
|
|
|
|
Assert.assertTrue(processInstance10 == null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test(expected = ServiceException.class) |
|
|
|
|
public void testDeleteNotExistCommand() { |
|
|
|
|
String host = "127.0.0.1"; |
|
|
|
|
int definitionVersion = 1; |
|
|
|
|
long definitionCode = 123; |
|
|
|
|
int processInstanceId = 222; |
|
|
|
|
|
|
|
|
|
Command command1 = new Command(); |
|
|
|
|
command1.setId(1); |
|
|
|
|
command1.setProcessDefinitionCode(definitionCode); |
|
|
|
|
command1.setProcessDefinitionVersion(definitionVersion); |
|
|
|
|
command1.setCommandParam("{\"ProcessInstanceId\":222}"); |
|
|
|
|
command1.setCommandType(CommandType.START_PROCESS); |
|
|
|
|
|
|
|
|
|
ProcessDefinition processDefinition = new ProcessDefinition(); |
|
|
|
|
processDefinition.setId(123); |
|
|
|
|
processDefinition.setName("test"); |
|
|
|
|
processDefinition.setVersion(definitionVersion); |
|
|
|
|
processDefinition.setCode(definitionCode); |
|
|
|
|
processDefinition.setGlobalParams("[{\"prop\":\"startParam1\",\"direct\":\"IN\",\"type\":\"VARCHAR\",\"value\":\"\"}]"); |
|
|
|
|
processDefinition.setExecutionType(ProcessExecutionTypeEnum.PARALLEL); |
|
|
|
|
|
|
|
|
|
ProcessInstance processInstance = new ProcessInstance(); |
|
|
|
|
processInstance.setId(222); |
|
|
|
|
processInstance.setProcessDefinitionCode(11L); |
|
|
|
|
processInstance.setHost("127.0.0.1:5678"); |
|
|
|
|
processInstance.setProcessDefinitionVersion(1); |
|
|
|
|
processInstance.setId(processInstanceId); |
|
|
|
|
processInstance.setProcessDefinitionCode(definitionCode); |
|
|
|
|
processInstance.setProcessDefinitionVersion(definitionVersion); |
|
|
|
|
|
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(command1.getProcessDefinitionCode())).thenReturn(processDefinition); |
|
|
|
|
Mockito.when(processDefineLogMapper.queryByDefinitionCodeAndVersion(processInstance.getProcessDefinitionCode(), |
|
|
|
|
processInstance.getProcessDefinitionVersion())).thenReturn(new ProcessDefinitionLog(processDefinition)); |
|
|
|
|
Mockito.when(processInstanceMapper.queryDetailById(222)).thenReturn(processInstance); |
|
|
|
|
|
|
|
|
|
// will throw exception when command id is 0 and delete fail
|
|
|
|
|
processService.handleCommand(logger, host, command1, processDefinitionCacheMaps); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testGetUserById() { |
|
|
|
|
User user = new User(); |
|
|
|
|