|
|
@ -16,6 +16,7 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.apache.dolphinscheduler.dao.mapper; |
|
|
|
package org.apache.dolphinscheduler.dao.mapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Command; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Command; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.CommandCount; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.CommandCount; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
@ -25,13 +26,25 @@ import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
|
|
|
|
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 java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.*; |
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* command mapper test |
|
|
|
|
|
|
|
*/ |
|
|
|
@RunWith(SpringRunner.class) |
|
|
|
@RunWith(SpringRunner.class) |
|
|
|
@SpringBootTest |
|
|
|
@SpringBootTest |
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
|
|
|
@Rollback(true) |
|
|
|
public class CommandMapperTest { |
|
|
|
public class CommandMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -41,71 +54,85 @@ public class CommandMapperTest { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
ProcessDefinitionMapper processDefinitionMapper; |
|
|
|
ProcessDefinitionMapper processDefinitionMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* insert |
|
|
|
* test insert |
|
|
|
* @return Command |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Command insertOne(){ |
|
|
|
@Test |
|
|
|
//insertOne
|
|
|
|
public void testInsert(){ |
|
|
|
Command command = new Command(); |
|
|
|
Command command = createCommand(); |
|
|
|
command.setCommandType(CommandType.START_PROCESS); |
|
|
|
assertNotNull(command.getId()); |
|
|
|
command.setProcessDefinitionId(1); |
|
|
|
assertThat(command.getId(),greaterThan(0)); |
|
|
|
command.setExecutorId(4); |
|
|
|
|
|
|
|
command.setProcessInstancePriority(Priority.MEDIUM); |
|
|
|
|
|
|
|
command.setFailureStrategy(FailureStrategy.CONTINUE); |
|
|
|
|
|
|
|
command.setWorkerGroupId(-1); |
|
|
|
|
|
|
|
command.setWarningGroupId(1); |
|
|
|
|
|
|
|
command.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
commandMapper.insert(command); |
|
|
|
|
|
|
|
return command; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test update |
|
|
|
* test select by id |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUpdate(){ |
|
|
|
public void testSelectById() { |
|
|
|
//insertOne
|
|
|
|
Command expectedCommand = createCommand(); |
|
|
|
Command command = insertOne(); |
|
|
|
//query
|
|
|
|
//update
|
|
|
|
Command actualCommand = commandMapper.selectById(expectedCommand.getId()); |
|
|
|
command.setStartTime(new Date()); |
|
|
|
|
|
|
|
int update = commandMapper.updateById(command); |
|
|
|
assertEquals(expectedCommand, actualCommand); |
|
|
|
Assert.assertEquals(update, 1); |
|
|
|
|
|
|
|
commandMapper.deleteById(command.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test delete |
|
|
|
* test update |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDelete(){ |
|
|
|
public void testUpdate(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Command expectedCommand = createCommand(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// update the command time if current command if recover from waiting
|
|
|
|
|
|
|
|
expectedCommand.setUpdateTime(DateUtils.getCurrentDate()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commandMapper.updateById(expectedCommand); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Command actualCommand = commandMapper.selectById(expectedCommand.getId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedCommand,actualCommand); |
|
|
|
|
|
|
|
|
|
|
|
Command Command = insertOne(); |
|
|
|
|
|
|
|
int delete = commandMapper.deleteById(Command.getId()); |
|
|
|
|
|
|
|
Assert.assertEquals(delete, 1); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test query |
|
|
|
* test delete |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testQuery() { |
|
|
|
public void testDelete(){ |
|
|
|
Command command = insertOne(); |
|
|
|
Command expectedCommand = createCommand(); |
|
|
|
//query
|
|
|
|
|
|
|
|
List<Command> commands = commandMapper.selectList(null); |
|
|
|
commandMapper.deleteById(expectedCommand.getId()); |
|
|
|
Assert.assertNotEquals(commands.size(), 0); |
|
|
|
|
|
|
|
commandMapper.deleteById(command.getId()); |
|
|
|
Command actualCommand = commandMapper.selectById(expectedCommand.getId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertNull(actualCommand); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test query all |
|
|
|
* test query all |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetAll() { |
|
|
|
public void testGetAll() { |
|
|
|
Command command = insertOne(); |
|
|
|
Integer count = 10; |
|
|
|
List<Command> commands = commandMapper.selectList(null); |
|
|
|
|
|
|
|
Assert.assertNotEquals(commands.size(), 0); |
|
|
|
Map<Integer, Command> commandMap = createCommandMap(count); |
|
|
|
commandMapper.deleteById(command.getId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Command> actualCommands = commandMapper.selectList(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(actualCommands.size(), greaterThanOrEqualTo(count)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Command actualCommand : actualCommands){ |
|
|
|
|
|
|
|
Command expectedCommand = commandMap.get(actualCommand.getId()); |
|
|
|
|
|
|
|
if (expectedCommand != null){ |
|
|
|
|
|
|
|
assertEquals(expectedCommand,actualCommand); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -113,28 +140,14 @@ public class CommandMapperTest { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetOneToRun() { |
|
|
|
public void testGetOneToRun() { |
|
|
|
ProcessDefinition processDefinition = new ProcessDefinition(); |
|
|
|
|
|
|
|
processDefinition.setReleaseState(ReleaseState.ONLINE); |
|
|
|
|
|
|
|
processDefinition.setName("ut test"); |
|
|
|
|
|
|
|
processDefinition.setProjectId(1); |
|
|
|
|
|
|
|
processDefinition.setFlag(Flag.YES); |
|
|
|
|
|
|
|
processDefinitionMapper.insert(processDefinition); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Command command = new Command(); |
|
|
|
ProcessDefinition processDefinition = createProcessDefinition(); |
|
|
|
command.setCommandType(CommandType.START_PROCESS); |
|
|
|
|
|
|
|
command.setProcessDefinitionId(processDefinition.getId()); |
|
|
|
|
|
|
|
command.setExecutorId(4); |
|
|
|
|
|
|
|
command.setProcessInstancePriority(Priority.MEDIUM); |
|
|
|
|
|
|
|
command.setFailureStrategy(FailureStrategy.CONTINUE); |
|
|
|
|
|
|
|
command.setWorkerGroupId(-1); |
|
|
|
|
|
|
|
command.setWarningGroupId(1); |
|
|
|
|
|
|
|
command.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
commandMapper.insert(command); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Command command2 = commandMapper.getOneToRun(); |
|
|
|
Command expectedCommand = createCommand(CommandType.START_PROCESS,processDefinition.getId()); |
|
|
|
Assert.assertNotEquals(command2, null); |
|
|
|
|
|
|
|
commandMapper.deleteById(command.getId()); |
|
|
|
Command actualCommand = commandMapper.getOneToRun(); |
|
|
|
processDefinitionMapper.deleteById(processDefinition.getId()); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedCommand, actualCommand); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -142,35 +155,122 @@ public class CommandMapperTest { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCountCommandState() { |
|
|
|
public void testCountCommandState() { |
|
|
|
Command command = insertOne(); |
|
|
|
Integer count = 10; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProcessDefinition processDefinition = createProcessDefinition(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandCount expectedCommandCount = createCommandMap(count, CommandType.START_PROCESS, processDefinition.getId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer[] projectIdArray = {processDefinition.getProjectId()}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date startTime = DateUtils.stringToDate("2019-12-29 00:10:00"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date endTime = DateUtils.stringToDate("2019-12-29 23:59:59"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<CommandCount> actualCommandCounts = commandMapper.countCommandState(0, startTime, endTime, projectIdArray); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(actualCommandCounts.size(),greaterThanOrEqualTo(1)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Boolean flag = false; |
|
|
|
|
|
|
|
for (CommandCount actualCommandCount : actualCommandCounts){ |
|
|
|
|
|
|
|
if (actualCommandCount.getCommandType().equals(expectedCommandCount.getCommandType())){ |
|
|
|
|
|
|
|
assertEquals(expectedCommandCount,actualCommandCount); |
|
|
|
|
|
|
|
flag = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(flag); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//insertOne
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* create command map |
|
|
|
|
|
|
|
* @param count map count |
|
|
|
|
|
|
|
* @param commandType comman type |
|
|
|
|
|
|
|
* @param processDefinitionId process definition id |
|
|
|
|
|
|
|
* @return command map |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private CommandCount createCommandMap( |
|
|
|
|
|
|
|
Integer count, |
|
|
|
|
|
|
|
CommandType commandType, |
|
|
|
|
|
|
|
Integer processDefinitionId){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandCount commandCount = new CommandCount(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0 ;i < count ;i++){ |
|
|
|
|
|
|
|
createCommand(commandType,processDefinitionId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
commandCount.setCommandType(commandType); |
|
|
|
|
|
|
|
commandCount.setCount(count); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return commandCount; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* create process definition |
|
|
|
|
|
|
|
* @return process definition |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private ProcessDefinition createProcessDefinition(){ |
|
|
|
ProcessDefinition processDefinition = new ProcessDefinition(); |
|
|
|
ProcessDefinition processDefinition = new ProcessDefinition(); |
|
|
|
processDefinition.setName("def 1"); |
|
|
|
processDefinition.setReleaseState(ReleaseState.ONLINE); |
|
|
|
processDefinition.setProjectId(1010); |
|
|
|
processDefinition.setName("ut test"); |
|
|
|
processDefinition.setUserId(101); |
|
|
|
processDefinition.setProjectId(1); |
|
|
|
processDefinition.setUpdateTime(new Date()); |
|
|
|
processDefinition.setFlag(Flag.YES); |
|
|
|
processDefinition.setCreateTime(new Date()); |
|
|
|
|
|
|
|
processDefinitionMapper.insert(processDefinition); |
|
|
|
processDefinitionMapper.insert(processDefinition); |
|
|
|
|
|
|
|
|
|
|
|
command.setProcessDefinitionId(processDefinition.getId()); |
|
|
|
return processDefinition; |
|
|
|
commandMapper.updateById(command); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* create command map |
|
|
|
|
|
|
|
* @param count map count |
|
|
|
|
|
|
|
* @return command map |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Map<Integer,Command> createCommandMap(Integer count){ |
|
|
|
|
|
|
|
Map<Integer,Command> commandMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
List<CommandCount> commandCounts = commandMapper.countCommandState( |
|
|
|
for (int i = 0; i < count ;i++){ |
|
|
|
4, null, null, new Integer[0] |
|
|
|
Command command = createCommand(); |
|
|
|
); |
|
|
|
commandMap.put(command.getId(),command); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return commandMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Integer[] projectIdArray = new Integer[2]; |
|
|
|
|
|
|
|
projectIdArray[0] = processDefinition.getProjectId(); |
|
|
|
|
|
|
|
projectIdArray[1] = 200; |
|
|
|
|
|
|
|
List<CommandCount> commandCounts2 = commandMapper.countCommandState( |
|
|
|
|
|
|
|
4, null, null, projectIdArray |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commandMapper.deleteById(command.getId()); |
|
|
|
/** |
|
|
|
processDefinitionMapper.deleteById(processDefinition.getId()); |
|
|
|
* create command |
|
|
|
Assert.assertNotEquals(commandCounts.size(), 0); |
|
|
|
* @return |
|
|
|
Assert.assertNotEquals(commandCounts2.size(), 0); |
|
|
|
*/ |
|
|
|
|
|
|
|
private Command createCommand(){ |
|
|
|
|
|
|
|
return createCommand(CommandType.START_PROCESS,1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* create command |
|
|
|
|
|
|
|
* @return Command |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Command createCommand(CommandType commandType,Integer processDefinitionId){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Command command = new Command(); |
|
|
|
|
|
|
|
command.setCommandType(commandType); |
|
|
|
|
|
|
|
command.setProcessDefinitionId(processDefinitionId); |
|
|
|
|
|
|
|
command.setExecutorId(4); |
|
|
|
|
|
|
|
command.setCommandParam("test command param"); |
|
|
|
|
|
|
|
command.setTaskDependType(TaskDependType.TASK_ONLY); |
|
|
|
|
|
|
|
command.setFailureStrategy(FailureStrategy.CONTINUE); |
|
|
|
|
|
|
|
command.setWarningType(WarningType.ALL); |
|
|
|
|
|
|
|
command.setWarningGroupId(1); |
|
|
|
|
|
|
|
command.setScheduleTime(DateUtils.stringToDate("2019-12-29 12:10:00")); |
|
|
|
|
|
|
|
command.setProcessInstancePriority(Priority.MEDIUM); |
|
|
|
|
|
|
|
command.setStartTime(DateUtils.stringToDate("2019-12-29 10:10:00")); |
|
|
|
|
|
|
|
command.setUpdateTime(DateUtils.stringToDate("2019-12-29 10:10:00")); |
|
|
|
|
|
|
|
command.setWorkerGroupId(-1); |
|
|
|
|
|
|
|
commandMapper.insert(command); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return command; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |