|
@@ -26,10 +26,11 @@ import org.apache.dolphinscheduler.api.dto.schedule.ScheduleUpdateRequest;
|
|
|
import org.apache.dolphinscheduler.api.enums.Status;
|
|
|
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
|
|
|
import org.apache.dolphinscheduler.api.service.impl.SchedulerServiceImpl;
|
|
|
-import org.apache.dolphinscheduler.common.constants.Constants;
|
|
|
import org.apache.dolphinscheduler.common.enums.ReleaseState;
|
|
|
+import org.apache.dolphinscheduler.common.model.Server;
|
|
|
import org.apache.dolphinscheduler.dao.entity.Environment;
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
|
|
+import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project;
|
|
|
import org.apache.dolphinscheduler.dao.entity.Schedule;
|
|
|
import org.apache.dolphinscheduler.dao.entity.User;
|
|
@@ -41,7 +42,8 @@ import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
|
|
|
import org.apache.dolphinscheduler.scheduler.api.SchedulerApi;
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
@@ -118,7 +120,6 @@ public class SchedulerServiceTest extends BaseServiceTestTool {
|
|
|
|
|
|
@Test
|
|
|
public void testSetScheduleState() {
|
|
|
- Map<String, Object> result;
|
|
|
Project project = getProject();
|
|
|
|
|
|
ProcessDefinition processDefinition = new ProcessDefinition();
|
|
@@ -130,40 +131,49 @@ public class SchedulerServiceTest extends BaseServiceTestTool {
|
|
|
schedule.setReleaseState(ReleaseState.OFFLINE);
|
|
|
|
|
|
Mockito.when(scheduleMapper.selectById(1)).thenReturn(schedule);
|
|
|
-
|
|
|
- Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
|
|
|
-
|
|
|
Mockito.when(processDefinitionMapper.queryByCode(1)).thenReturn(processDefinition);
|
|
|
+ Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
|
|
|
|
|
|
- // hash no auth
|
|
|
- result = schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.ONLINE);
|
|
|
-
|
|
|
- Mockito.when(projectService.hasProjectAndPerm(user, project, result, null)).thenReturn(true);
|
|
|
// schedule not exists
|
|
|
- result = schedulerService.setScheduleState(user, project.getCode(), 2, ReleaseState.ONLINE);
|
|
|
- Assertions.assertEquals(Status.SCHEDULE_CRON_NOT_EXISTS, result.get(Constants.STATUS));
|
|
|
-
|
|
|
- // SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE
|
|
|
- result = schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.OFFLINE);
|
|
|
- Assertions.assertEquals(Status.SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE, result.get(Constants.STATUS));
|
|
|
+ exception = Assertions.assertThrows(ServiceException.class, () -> {
|
|
|
+ schedulerService.setScheduleState(user, project.getCode(), 2, ReleaseState.ONLINE);
|
|
|
+ });
|
|
|
+ Assertions.assertEquals(Status.SCHEDULE_CRON_NOT_EXISTS.getCode(), ((ServiceException) exception).getCode());
|
|
|
+
|
|
|
+ // SCHEDULE_CRON_RELEASE_NEED_NOT_CHANGE
|
|
|
+ exception = Assertions.assertThrows(ServiceException.class, () -> {
|
|
|
+ schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.OFFLINE);
|
|
|
+ });
|
|
|
+ Assertions.assertEquals(Status.SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE.getCode(),
|
|
|
+ ((ServiceException) exception).getCode());
|
|
|
|
|
|
// PROCESS_DEFINE_NOT_EXIST
|
|
|
schedule.setProcessDefinitionCode(2);
|
|
|
- result = schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.ONLINE);
|
|
|
- Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, result.get(Constants.STATUS));
|
|
|
+ exception = Assertions.assertThrows(ServiceException.class, () -> {
|
|
|
+ schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.ONLINE);
|
|
|
+ });
|
|
|
+ Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode());
|
|
|
schedule.setProcessDefinitionCode(1);
|
|
|
|
|
|
- result = schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.ONLINE);
|
|
|
- Assertions.assertEquals(Status.PROCESS_DAG_IS_EMPTY, result.get(Constants.STATUS));
|
|
|
-
|
|
|
- processDefinition.setReleaseState(ReleaseState.ONLINE);
|
|
|
-
|
|
|
- result = schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.ONLINE);
|
|
|
- Assertions.assertEquals(Status.PROCESS_DAG_IS_EMPTY, result.get(Constants.STATUS));
|
|
|
+ // online also success
|
|
|
+ ProcessTaskRelation processTaskRelation = new ProcessTaskRelation();
|
|
|
+ List<ProcessTaskRelation> processTaskRelationList = new ArrayList<>();
|
|
|
+ processTaskRelationList.add(processTaskRelation);
|
|
|
+ Mockito.when(processTaskRelationMapper.queryByProcessCode(projectCode, 1)).thenReturn(processTaskRelationList);
|
|
|
+ exception = Assertions.assertThrows(ServiceException.class, () -> {
|
|
|
+ schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.ONLINE);
|
|
|
+ });
|
|
|
+ Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_RELEASE.getCode(), ((ServiceException) exception).getCode());
|
|
|
|
|
|
// SUCCESS
|
|
|
- result = schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.ONLINE);
|
|
|
- Assertions.assertEquals(Status.PROCESS_DAG_IS_EMPTY, result.get(Constants.STATUS));
|
|
|
+ Server server = new Server();
|
|
|
+ List<Server> serverList = new ArrayList<>();
|
|
|
+ serverList.add(server);
|
|
|
+ Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(serverList);
|
|
|
+ processDefinition.setReleaseState(ReleaseState.ONLINE);
|
|
|
+ Assertions.assertDoesNotThrow(() -> {
|
|
|
+ schedulerService.setScheduleState(user, project.getCode(), 1, ReleaseState.ONLINE);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -428,6 +438,7 @@ public class SchedulerServiceTest extends BaseServiceTestTool {
|
|
|
|
|
|
private Project getProject() {
|
|
|
Project project = new Project();
|
|
|
+ project.setId(1);
|
|
|
project.setName(projectName);
|
|
|
project.setCode(projectCode);
|
|
|
project.setUserId(userId);
|