|
|
@ -20,9 +20,14 @@ package org.apache.dolphinscheduler.dao.mapper; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
|
|
|
import org.apache.dolphinscheduler.common.enums.Flag; |
|
|
|
import org.apache.dolphinscheduler.common.enums.Flag; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.*; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
@ -32,8 +37,8 @@ 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 org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import java.util.List; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
|
|
|
|
|
|
@RunWith(SpringRunner.class) |
|
|
|
@RunWith(SpringRunner.class) |
|
|
|
@SpringBootTest |
|
|
|
@SpringBootTest |
|
|
@ -54,10 +59,6 @@ public class ProcessInstanceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* insert process instance with specified start time and end time,set state to SUCCESS |
|
|
|
* insert process instance with specified start time and end time,set state to SUCCESS |
|
|
|
* |
|
|
|
|
|
|
|
* @param startTime |
|
|
|
|
|
|
|
* @param endTime |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ProcessInstance insertOne(Date startTime, Date endTime) { |
|
|
|
private ProcessInstance insertOne(Date startTime, Date endTime) { |
|
|
|
ProcessInstance processInstance = new ProcessInstance(); |
|
|
|
ProcessInstance processInstance = new ProcessInstance(); |
|
|
@ -73,13 +74,14 @@ public class ProcessInstanceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* insert |
|
|
|
* insert |
|
|
|
|
|
|
|
* |
|
|
|
* @return ProcessInstance |
|
|
|
* @return ProcessInstance |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ProcessInstance insertOne(){ |
|
|
|
private ProcessInstance insertOne() { |
|
|
|
//insertOne
|
|
|
|
//insertOne
|
|
|
|
ProcessInstance processInstance = new ProcessInstance(); |
|
|
|
ProcessInstance processInstance = new ProcessInstance(); |
|
|
|
Date start = new Date(2019-1900, 1-1, 1, 0, 10,0); |
|
|
|
Date start = new Date(2019 - 1900, 1 - 1, 1, 0, 10, 0); |
|
|
|
Date end = new Date(2019-1900, 1-1, 1, 1, 0,0); |
|
|
|
Date end = new Date(2019 - 1900, 1 - 1, 1, 1, 0, 0); |
|
|
|
processInstance.setStartTime(start); |
|
|
|
processInstance.setStartTime(start); |
|
|
|
processInstance.setEndTime(end); |
|
|
|
processInstance.setEndTime(end); |
|
|
|
processInstance.setState(ExecutionStatus.SUBMITTED_SUCCESS); |
|
|
|
processInstance.setState(ExecutionStatus.SUBMITTED_SUCCESS); |
|
|
@ -92,7 +94,7 @@ public class ProcessInstanceMapperTest { |
|
|
|
* test update |
|
|
|
* test update |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUpdate(){ |
|
|
|
public void testUpdate() { |
|
|
|
//insertOne
|
|
|
|
//insertOne
|
|
|
|
ProcessInstance processInstanceMap = insertOne(); |
|
|
|
ProcessInstance processInstanceMap = insertOne(); |
|
|
|
//update
|
|
|
|
//update
|
|
|
@ -105,7 +107,7 @@ public class ProcessInstanceMapperTest { |
|
|
|
* test delete |
|
|
|
* test delete |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDelete(){ |
|
|
|
public void testDelete() { |
|
|
|
ProcessInstance processInstanceMap = insertOne(); |
|
|
|
ProcessInstance processInstanceMap = insertOne(); |
|
|
|
int delete = processInstanceMapper.deleteById(processInstanceMap.getId()); |
|
|
|
int delete = processInstanceMapper.deleteById(processInstanceMap.getId()); |
|
|
|
Assert.assertEquals(1, delete); |
|
|
|
Assert.assertEquals(1, delete); |
|
|
@ -185,8 +187,8 @@ public class ProcessInstanceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
IPage<ProcessInstance> processInstanceIPage = processInstanceMapper.queryProcessInstanceListPaging( |
|
|
|
IPage<ProcessInstance> processInstanceIPage = processInstanceMapper.queryProcessInstanceListPaging( |
|
|
|
page, |
|
|
|
page, |
|
|
|
processDefinition.getProjectId(), |
|
|
|
processDefinition.getProjectCode(), |
|
|
|
processInstance.getProcessDefinitionId(), |
|
|
|
processInstance.getProcessDefinitionCode(), |
|
|
|
processInstance.getName(), |
|
|
|
processInstance.getName(), |
|
|
|
0, |
|
|
|
0, |
|
|
|
stateArray, |
|
|
|
stateArray, |
|
|
@ -283,10 +285,10 @@ public class ProcessInstanceMapperTest { |
|
|
|
ProcessInstance processInstance1 = insertOne(); |
|
|
|
ProcessInstance processInstance1 = insertOne(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ProcessInstance> processInstances = processInstanceMapper.queryByProcessDefineId(processInstance.getProcessDefinitionId(), 1); |
|
|
|
List<ProcessInstance> processInstances = processInstanceMapper.queryByProcessDefineCode(processInstance.getProcessDefinitionCode(), 1); |
|
|
|
Assert.assertEquals(1, processInstances.size()); |
|
|
|
Assert.assertEquals(1, processInstances.size()); |
|
|
|
|
|
|
|
|
|
|
|
processInstances = processInstanceMapper.queryByProcessDefineId(processInstance.getProcessDefinitionId(), 2); |
|
|
|
processInstances = processInstanceMapper.queryByProcessDefineCode(processInstance.getProcessDefinitionCode(), 2); |
|
|
|
Assert.assertEquals(2, processInstances.size()); |
|
|
|
Assert.assertEquals(2, processInstances.size()); |
|
|
|
|
|
|
|
|
|
|
|
processInstanceMapper.deleteById(processInstance.getId()); |
|
|
|
processInstanceMapper.deleteById(processInstance.getId()); |
|
|
@ -302,7 +304,7 @@ public class ProcessInstanceMapperTest { |
|
|
|
processInstance.setScheduleTime(new Date()); |
|
|
|
processInstance.setScheduleTime(new Date()); |
|
|
|
processInstanceMapper.updateById(processInstance); |
|
|
|
processInstanceMapper.updateById(processInstance); |
|
|
|
|
|
|
|
|
|
|
|
ProcessInstance processInstance1 = processInstanceMapper.queryLastSchedulerProcess(processInstance.getProcessDefinitionId(), null, null ); |
|
|
|
ProcessInstance processInstance1 = processInstanceMapper.queryLastSchedulerProcess(processInstance.getProcessDefinitionCode(), null, null); |
|
|
|
Assert.assertNotEquals(processInstance1, null); |
|
|
|
Assert.assertNotEquals(processInstance1, null); |
|
|
|
processInstanceMapper.deleteById(processInstance.getId()); |
|
|
|
processInstanceMapper.deleteById(processInstance.getId()); |
|
|
|
} |
|
|
|
} |
|
|
@ -320,7 +322,7 @@ public class ProcessInstanceMapperTest { |
|
|
|
ExecutionStatus.RUNNING_EXECUTION.ordinal(), |
|
|
|
ExecutionStatus.RUNNING_EXECUTION.ordinal(), |
|
|
|
ExecutionStatus.SUBMITTED_SUCCESS.ordinal()}; |
|
|
|
ExecutionStatus.SUBMITTED_SUCCESS.ordinal()}; |
|
|
|
|
|
|
|
|
|
|
|
ProcessInstance processInstance1 = processInstanceMapper.queryLastRunningProcess(processInstance.getProcessDefinitionId(), null, null , stateArray); |
|
|
|
ProcessInstance processInstance1 = processInstanceMapper.queryLastRunningProcess(processInstance.getProcessDefinitionCode(), null, null, stateArray); |
|
|
|
|
|
|
|
|
|
|
|
Assert.assertNotEquals(processInstance1, null); |
|
|
|
Assert.assertNotEquals(processInstance1, null); |
|
|
|
processInstanceMapper.deleteById(processInstance.getId()); |
|
|
|
processInstanceMapper.deleteById(processInstance.getId()); |
|
|
@ -334,15 +336,13 @@ public class ProcessInstanceMapperTest { |
|
|
|
ProcessInstance processInstance = insertOne(); |
|
|
|
ProcessInstance processInstance = insertOne(); |
|
|
|
processInstanceMapper.updateById(processInstance); |
|
|
|
processInstanceMapper.updateById(processInstance); |
|
|
|
|
|
|
|
|
|
|
|
Date start = new Date(2019-1900, 1-1, 01, 0, 0, 0); |
|
|
|
Date start = new Date(2019 - 1900, 1 - 1, 01, 0, 0, 0); |
|
|
|
Date end = new Date(2019-1900, 1-1, 01, 5, 0, 0); |
|
|
|
Date end = new Date(2019 - 1900, 1 - 1, 01, 5, 0, 0); |
|
|
|
ProcessInstance processInstance1 = processInstanceMapper.queryLastManualProcess(processInstance.getProcessDefinitionId(),start, end |
|
|
|
ProcessInstance processInstance1 = processInstanceMapper.queryLastManualProcess(processInstance.getProcessDefinitionCode(), start, end); |
|
|
|
); |
|
|
|
|
|
|
|
Assert.assertEquals(processInstance1.getId(), processInstance.getId()); |
|
|
|
Assert.assertEquals(processInstance1.getId(), processInstance.getId()); |
|
|
|
|
|
|
|
|
|
|
|
start = new Date(2019-1900, 1-1, 01, 1, 0, 0); |
|
|
|
start = new Date(2019 - 1900, 1 - 1, 01, 1, 0, 0); |
|
|
|
processInstance1 = processInstanceMapper.queryLastManualProcess(processInstance.getProcessDefinitionId(),start, end |
|
|
|
processInstance1 = processInstanceMapper.queryLastManualProcess(processInstance.getProcessDefinitionCode(), start, end); |
|
|
|
); |
|
|
|
|
|
|
|
Assert.assertNull(processInstance1); |
|
|
|
Assert.assertNull(processInstance1); |
|
|
|
|
|
|
|
|
|
|
|
processInstanceMapper.deleteById(processInstance.getId()); |
|
|
|
processInstanceMapper.deleteById(processInstance.getId()); |
|
|
@ -352,9 +352,6 @@ public class ProcessInstanceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test whether it is in descending order by running duration |
|
|
|
* test whether it is in descending order by running duration |
|
|
|
* |
|
|
|
|
|
|
|
* @param processInstances |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private boolean isSortedByDuration(List<ProcessInstance> processInstances) { |
|
|
|
private boolean isSortedByDuration(List<ProcessInstance> processInstances) { |
|
|
|
for (int i = 1; i < processInstances.size(); i++) { |
|
|
|
for (int i = 1; i < processInstances.size(); i++) { |
|
|
@ -383,7 +380,7 @@ public class ProcessInstanceMapperTest { |
|
|
|
ProcessInstance processInstance3 = insertOne(startTime3, endTime3); |
|
|
|
ProcessInstance processInstance3 = insertOne(startTime3, endTime3); |
|
|
|
Date start = new Date(2020, 1, 1, 1, 1, 1); |
|
|
|
Date start = new Date(2020, 1, 1, 1, 1, 1); |
|
|
|
Date end = new Date(2021, 1, 1, 1, 1, 1); |
|
|
|
Date end = new Date(2021, 1, 1, 1, 1, 1); |
|
|
|
List<ProcessInstance> processInstances = processInstanceMapper.queryTopNProcessInstance(2, start, end,ExecutionStatus.SUCCESS); |
|
|
|
List<ProcessInstance> processInstances = processInstanceMapper.queryTopNProcessInstance(2, start, end, ExecutionStatus.SUCCESS); |
|
|
|
Assert.assertEquals(2, processInstances.size()); |
|
|
|
Assert.assertEquals(2, processInstances.size()); |
|
|
|
Assert.assertTrue(isSortedByDuration(processInstances)); |
|
|
|
Assert.assertTrue(isSortedByDuration(processInstances)); |
|
|
|
for (ProcessInstance processInstance : processInstances) { |
|
|
|
for (ProcessInstance processInstance : processInstances) { |
|
|
|