|
|
|
@ -14,30 +14,35 @@
|
|
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
|
* limitations under the License. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.dao.mapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import javafx.concurrent.Task; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.CommandType; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.Flag; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.TaskType; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.*; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstanceMap; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
import org.mockito.internal.junit.ExceptionFactory; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
|
import org.springframework.test.annotation.Rollback; |
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
|
|
|
|
@RunWith(SpringRunner.class) |
|
|
|
|
@SpringBootTest |
|
|
|
@ -60,15 +65,17 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* insert |
|
|
|
|
* |
|
|
|
|
* @return TaskInstance |
|
|
|
|
*/ |
|
|
|
|
private TaskInstance insertOne(){ |
|
|
|
|
private TaskInstance insertOne() { |
|
|
|
|
//insertOne
|
|
|
|
|
return insertOne("us task", 1, ExecutionStatus.RUNNING_EXECUTION, TaskType.SHELL.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* construct a task instance and then insert |
|
|
|
|
* |
|
|
|
|
* @param taskName |
|
|
|
|
* @param processInstanceId |
|
|
|
|
* @param state |
|
|
|
@ -96,7 +103,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
* test update |
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testUpdate(){ |
|
|
|
|
public void testUpdate() { |
|
|
|
|
//insertOne
|
|
|
|
|
TaskInstance taskInstance = insertOne(); |
|
|
|
|
//update
|
|
|
|
@ -109,7 +116,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
* test delete |
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testDelete(){ |
|
|
|
|
public void testDelete() { |
|
|
|
|
TaskInstance taskInstance = insertOne(); |
|
|
|
|
int delete = taskInstanceMapper.deleteById(taskInstance.getId()); |
|
|
|
|
Assert.assertEquals(1, delete); |
|
|
|
@ -168,7 +175,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
taskInstanceMapper.deleteById(task2.getId()); |
|
|
|
|
taskInstanceMapper.deleteById(task.getId()); |
|
|
|
|
Assert.assertNotEquals(taskInstances.size(), 0); |
|
|
|
|
Assert.assertNotEquals(taskInstances1.size(), 0 ); |
|
|
|
|
Assert.assertNotEquals(taskInstances1.size(), 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -181,7 +188,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
taskInstanceMapper.updateById(task); |
|
|
|
|
|
|
|
|
|
List<TaskInstance> taskInstances = taskInstanceMapper.queryByHostAndStatus( |
|
|
|
|
task.getHost(), new int[]{ExecutionStatus.RUNNING_EXECUTION.ordinal()} |
|
|
|
|
task.getHost(), new int[] {ExecutionStatus.RUNNING_EXECUTION.ordinal()} |
|
|
|
|
); |
|
|
|
|
taskInstanceMapper.deleteById(task.getId()); |
|
|
|
|
Assert.assertNotEquals(taskInstances.size(), 0); |
|
|
|
@ -198,7 +205,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
|
|
|
|
|
int setResult = taskInstanceMapper.setFailoverByHostAndStateArray( |
|
|
|
|
task.getHost(), |
|
|
|
|
new int[]{ExecutionStatus.RUNNING_EXECUTION.ordinal()}, |
|
|
|
|
new int[] {ExecutionStatus.RUNNING_EXECUTION.ordinal()}, |
|
|
|
|
ExecutionStatus.NEED_FAULT_TOLERANCE |
|
|
|
|
); |
|
|
|
|
taskInstanceMapper.deleteById(task.getId()); |
|
|
|
@ -240,8 +247,8 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
new int[0] |
|
|
|
|
); |
|
|
|
|
int countTask2 = taskInstanceMapper.countTask( |
|
|
|
|
new Integer[]{definition.getProjectId()}, |
|
|
|
|
new int[]{task.getId()} |
|
|
|
|
new Integer[] {definition.getProjectId()}, |
|
|
|
|
new int[] {task.getId()} |
|
|
|
|
); |
|
|
|
|
taskInstanceMapper.deleteById(task.getId()); |
|
|
|
|
processDefinitionMapper.deleteById(definition.getId()); |
|
|
|
@ -267,7 +274,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
|
|
|
|
|
List<ExecuteStatusCount> count = taskInstanceMapper.countTaskInstanceStateByUser( |
|
|
|
|
null, null, |
|
|
|
|
new Integer[]{definition.getProjectId()} |
|
|
|
|
new Integer[] {definition.getProjectId()} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
processDefinitionMapper.deleteById(definition.getId()); |
|
|
|
@ -298,7 +305,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
task.setProcessInstanceId(processInstance.getId()); |
|
|
|
|
taskInstanceMapper.updateById(task); |
|
|
|
|
|
|
|
|
|
Page<TaskInstance> page = new Page(1,3); |
|
|
|
|
Page<TaskInstance> page = new Page(1, 3); |
|
|
|
|
IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging( |
|
|
|
|
page, |
|
|
|
|
definition.getProjectId(), |
|
|
|
@ -308,7 +315,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
0, |
|
|
|
|
new int[0], |
|
|
|
|
"", |
|
|
|
|
null,null |
|
|
|
|
null, null |
|
|
|
|
); |
|
|
|
|
processInstanceMapper.deleteById(processInstance.getId()); |
|
|
|
|
taskInstanceMapper.deleteById(task.getId()); |
|
|
|
@ -328,7 +335,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
|
|
|
|
|
// test query result
|
|
|
|
|
List<Integer> resultArray = taskInstanceMapper.queryTaskByPIdAndStatusAndType(66, |
|
|
|
|
new int[]{ExecutionStatus.FAILURE.ordinal(), ExecutionStatus.KILL.ordinal(), ExecutionStatus.NEED_FAULT_TOLERANCE.ordinal()}, |
|
|
|
|
new int[] {ExecutionStatus.FAILURE.ordinal(), ExecutionStatus.KILL.ordinal(), ExecutionStatus.NEED_FAULT_TOLERANCE.ordinal()}, |
|
|
|
|
TaskType.SUB_PROCESS.toString()); |
|
|
|
|
Assert.assertEquals(3, resultArray.size()); |
|
|
|
|
|
|
|
|
@ -340,7 +347,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryTaskBySubProcessTaskIdAndStatusAndType() { |
|
|
|
|
TaskInstance parentTask = insertOne("parent-task",66, ExecutionStatus.FAILURE, TaskType.SUB_PROCESS.toString()); |
|
|
|
|
TaskInstance parentTask = insertOne("parent-task", 66, ExecutionStatus.FAILURE, TaskType.SUB_PROCESS.toString()); |
|
|
|
|
|
|
|
|
|
ProcessInstanceMap processInstanceMap = new ProcessInstanceMap(); |
|
|
|
|
processInstanceMap.setParentProcessInstanceId(66); |
|
|
|
@ -353,7 +360,7 @@ public class TaskInstanceMapperTest {
|
|
|
|
|
|
|
|
|
|
// test query result
|
|
|
|
|
List<Integer> resultList = taskInstanceMapper.queryTaskBySubProcessTaskIdAndStatusAndType(parentTask.getId(), |
|
|
|
|
new int[]{ExecutionStatus.FORCED_SUCCESS.ordinal()}, |
|
|
|
|
new int[] {ExecutionStatus.FORCED_SUCCESS.ordinal()}, |
|
|
|
|
null); |
|
|
|
|
|
|
|
|
|
Assert.assertEquals(1, resultList.size()); |
|
|
|
|