SbloodyS commented on code in PR #18069: URL: https://github.com/apache/dolphinscheduler/pull/18069#discussion_r3055183855
########## dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/tasks/EmrServerlessTaskAPITest.java: ########## @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.test.cases.tasks; + +import org.apache.dolphinscheduler.api.test.core.DolphinScheduler; +import org.apache.dolphinscheduler.api.test.entity.HttpResponse; +import org.apache.dolphinscheduler.api.test.entity.LoginResponseData; +import org.apache.dolphinscheduler.api.test.pages.LoginPage; +import org.apache.dolphinscheduler.api.test.pages.project.ProjectPage; +import org.apache.dolphinscheduler.api.test.pages.workflow.ExecutorPage; +import org.apache.dolphinscheduler.api.test.pages.workflow.WorkflowDefinitionPage; +import org.apache.dolphinscheduler.api.test.utils.JSONUtils; +import org.apache.dolphinscheduler.common.enums.FailureStrategy; +import org.apache.dolphinscheduler.common.enums.ReleaseState; +import org.apache.dolphinscheduler.common.enums.UserType; +import org.apache.dolphinscheduler.common.enums.WarningType; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; + +import lombok.extern.slf4j.Slf4j; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.DisableIfTestFails; + +@DolphinScheduler(composeFiles = "docker/task-emr-serverless/docker-compose.yaml") +@Slf4j +@DisableIfTestFails +public class EmrServerlessTaskAPITest { + + private static final String username = "admin"; + + private static final String password = "dolphinscheduler123"; + + private static String sessionId; + + private static User loginUser; + + private static ExecutorPage executorPage; + + private static WorkflowDefinitionPage workflowDefinitionPage; + + private static ProjectPage projectPage; + + private static long projectCode; + + private static long workflowDefinitionCode; + + private static List<Integer> workflowInstanceIds; + + @BeforeAll + public static void setup() { + LoginPage loginPage = new LoginPage(); + HttpResponse loginHttpResponse = loginPage.login(username, password); + sessionId = + JSONUtils.convertValue(loginHttpResponse.getBody().getData(), LoginResponseData.class).getSessionId(); + executorPage = new ExecutorPage(sessionId); + workflowDefinitionPage = new WorkflowDefinitionPage(sessionId); + projectPage = new ProjectPage(sessionId); + loginUser = new User(); + loginUser.setUserName("admin"); + loginUser.setId(1); + loginUser.setUserType(UserType.ADMIN_USER); + } + + @AfterAll + public static void cleanup() { + log.info("success cleanup"); + } + + @Test + @Order(1) + public void testEmrServerlessSuccessWorkflowInstance() { + try { + String workflowDefinitionName = "test_emr_serverless_success_" + System.currentTimeMillis(); + // create test project + HttpResponse createProjectResponse = projectPage.createProject(loginUser, "project-test-emr-serverless"); + HttpResponse queryAllProjectListResponse = projectPage.queryAllProjectList(loginUser); + Assertions.assertTrue(queryAllProjectListResponse.getBody().getSuccess()); + projectCode = (long) ((LinkedHashMap<String, Object>) ((List<LinkedHashMap>) queryAllProjectListResponse + .getBody().getData()).get(0)).get("code"); + + // upload test workflow definition json + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader + .getResource("workflow-json/task-emr-serverless/emrServerlessSuccessWorkflow.json").getFile()); + HttpResponse createWorkflowDefinitionResponse = workflowDefinitionPage + .createWorkflowDefinition(loginUser, projectCode, file, workflowDefinitionName); + Assertions.assertTrue(createWorkflowDefinitionResponse.getBody().getSuccess()); + + // get workflow definition code + HttpResponse queryAllWorkflowDefinitionByProjectCodeResponse = + workflowDefinitionPage.queryAllWorkflowDefinitionByProjectCode(loginUser, projectCode); + Assertions.assertTrue(queryAllWorkflowDefinitionByProjectCodeResponse.getBody().getSuccess()); + Assertions.assertTrue(queryAllWorkflowDefinitionByProjectCodeResponse.getBody().getData().toString() + .contains("test name")); + workflowDefinitionCode = + (long) ((LinkedHashMap<String, Object>) ((LinkedHashMap<String, Object>) ((List<LinkedHashMap>) queryAllWorkflowDefinitionByProjectCodeResponse + .getBody().getData()).get(0)).get("workflowDefinition")).get("code"); + + // release test workflow + HttpResponse releaseWorkflowDefinitionResponse = workflowDefinitionPage.releaseWorkflowDefinition(loginUser, + projectCode, workflowDefinitionCode, ReleaseState.ONLINE); + Assertions.assertTrue(releaseWorkflowDefinitionResponse.getBody().getSuccess()); + + // trigger workflow instance + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = new Date(); + String scheduleTime = String.format("%s,%s", formatter.format(date), formatter.format(date)); + log.info("use current time {} as scheduleTime", scheduleTime); + HttpResponse startWorkflowInstanceResponse = executorPage.startWorkflowInstance(loginUser, projectCode, + workflowDefinitionCode, scheduleTime, FailureStrategy.END, WarningType.NONE); + Assertions.assertTrue(startWorkflowInstanceResponse.getBody().getSuccess()); + + workflowInstanceIds = (List<Integer>) startWorkflowInstanceResponse.getBody().getData(); Review Comment: You should assert workflow instance running successfully. ########## dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/tasks/EmrServerlessTaskAPITest.java: ########## @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.test.cases.tasks; + +import org.apache.dolphinscheduler.api.test.core.DolphinScheduler; +import org.apache.dolphinscheduler.api.test.entity.HttpResponse; +import org.apache.dolphinscheduler.api.test.entity.LoginResponseData; +import org.apache.dolphinscheduler.api.test.pages.LoginPage; +import org.apache.dolphinscheduler.api.test.pages.project.ProjectPage; +import org.apache.dolphinscheduler.api.test.pages.workflow.ExecutorPage; +import org.apache.dolphinscheduler.api.test.pages.workflow.WorkflowDefinitionPage; +import org.apache.dolphinscheduler.api.test.utils.JSONUtils; +import org.apache.dolphinscheduler.common.enums.FailureStrategy; +import org.apache.dolphinscheduler.common.enums.ReleaseState; +import org.apache.dolphinscheduler.common.enums.UserType; +import org.apache.dolphinscheduler.common.enums.WarningType; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; + +import lombok.extern.slf4j.Slf4j; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.DisableIfTestFails; + +@DolphinScheduler(composeFiles = "docker/task-emr-serverless/docker-compose.yaml") +@Slf4j +@DisableIfTestFails +public class EmrServerlessTaskAPITest { + + private static final String username = "admin"; + + private static final String password = "dolphinscheduler123"; + + private static String sessionId; + + private static User loginUser; + + private static ExecutorPage executorPage; + + private static WorkflowDefinitionPage workflowDefinitionPage; + + private static ProjectPage projectPage; + + private static long projectCode; + + private static long workflowDefinitionCode; + + private static List<Integer> workflowInstanceIds; + + @BeforeAll + public static void setup() { + LoginPage loginPage = new LoginPage(); + HttpResponse loginHttpResponse = loginPage.login(username, password); + sessionId = + JSONUtils.convertValue(loginHttpResponse.getBody().getData(), LoginResponseData.class).getSessionId(); + executorPage = new ExecutorPage(sessionId); + workflowDefinitionPage = new WorkflowDefinitionPage(sessionId); + projectPage = new ProjectPage(sessionId); + loginUser = new User(); + loginUser.setUserName("admin"); + loginUser.setId(1); + loginUser.setUserType(UserType.ADMIN_USER); + } + + @AfterAll + public static void cleanup() { + log.info("success cleanup"); + } + + @Test + @Order(1) + public void testEmrServerlessSuccessWorkflowInstance() { + try { + String workflowDefinitionName = "test_emr_serverless_success_" + System.currentTimeMillis(); + // create test project + HttpResponse createProjectResponse = projectPage.createProject(loginUser, "project-test-emr-serverless"); + HttpResponse queryAllProjectListResponse = projectPage.queryAllProjectList(loginUser); + Assertions.assertTrue(queryAllProjectListResponse.getBody().getSuccess()); + projectCode = (long) ((LinkedHashMap<String, Object>) ((List<LinkedHashMap>) queryAllProjectListResponse + .getBody().getData()).get(0)).get("code"); + + // upload test workflow definition json + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader + .getResource("workflow-json/task-emr-serverless/emrServerlessSuccessWorkflow.json").getFile()); + HttpResponse createWorkflowDefinitionResponse = workflowDefinitionPage + .createWorkflowDefinition(loginUser, projectCode, file, workflowDefinitionName); + Assertions.assertTrue(createWorkflowDefinitionResponse.getBody().getSuccess()); + + // get workflow definition code + HttpResponse queryAllWorkflowDefinitionByProjectCodeResponse = + workflowDefinitionPage.queryAllWorkflowDefinitionByProjectCode(loginUser, projectCode); + Assertions.assertTrue(queryAllWorkflowDefinitionByProjectCodeResponse.getBody().getSuccess()); + Assertions.assertTrue(queryAllWorkflowDefinitionByProjectCodeResponse.getBody().getData().toString() + .contains("test name")); + workflowDefinitionCode = + (long) ((LinkedHashMap<String, Object>) ((LinkedHashMap<String, Object>) ((List<LinkedHashMap>) queryAllWorkflowDefinitionByProjectCodeResponse + .getBody().getData()).get(0)).get("workflowDefinition")).get("code"); + + // release test workflow + HttpResponse releaseWorkflowDefinitionResponse = workflowDefinitionPage.releaseWorkflowDefinition(loginUser, + projectCode, workflowDefinitionCode, ReleaseState.ONLINE); + Assertions.assertTrue(releaseWorkflowDefinitionResponse.getBody().getSuccess()); + + // trigger workflow instance + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = new Date(); + String scheduleTime = String.format("%s,%s", formatter.format(date), formatter.format(date)); + log.info("use current time {} as scheduleTime", scheduleTime); + HttpResponse startWorkflowInstanceResponse = executorPage.startWorkflowInstance(loginUser, projectCode, + workflowDefinitionCode, scheduleTime, FailureStrategy.END, WarningType.NONE); + Assertions.assertTrue(startWorkflowInstanceResponse.getBody().getSuccess()); + + workflowInstanceIds = (List<Integer>) startWorkflowInstanceResponse.getBody().getData(); + } catch (Exception e) { + log.error("failed", e); + Assertions.fail(); + } + } + + @Test + @Order(2) + public void testEmrServerlessFailedWorkflowInstance() { + try { + String workflowDefinitionName = "test_emr_serverless_failed_" + System.currentTimeMillis(); + + // upload failed workflow definition json + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader + .getResource("workflow-json/task-emr-serverless/emrServerlessFailedWorkflow.json").getFile()); + HttpResponse createWorkflowDefinitionResponse = workflowDefinitionPage + .createWorkflowDefinition(loginUser, projectCode, file, workflowDefinitionName); + Assertions.assertTrue(createWorkflowDefinitionResponse.getBody().getSuccess()); + + // get workflow definition code + HttpResponse queryAllWorkflowDefinitionByProjectCodeResponse = + workflowDefinitionPage.queryAllWorkflowDefinitionByProjectCode(loginUser, projectCode); + Assertions.assertTrue(queryAllWorkflowDefinitionByProjectCodeResponse.getBody().getSuccess()); + long failedWorkflowDefinitionCode = + (long) ((LinkedHashMap<String, Object>) ((LinkedHashMap<String, Object>) ((List<LinkedHashMap>) queryAllWorkflowDefinitionByProjectCodeResponse + .getBody().getData()).get(0)).get("workflowDefinition")).get("code"); + + // release + HttpResponse releaseWorkflowDefinitionResponse = workflowDefinitionPage.releaseWorkflowDefinition( + loginUser, projectCode, failedWorkflowDefinitionCode, ReleaseState.ONLINE); + Assertions.assertTrue(releaseWorkflowDefinitionResponse.getBody().getSuccess()); + + // trigger + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = new Date(); + String scheduleTime = String.format("%s,%s", formatter.format(date), formatter.format(date)); + HttpResponse startWorkflowInstanceResponse = executorPage.startWorkflowInstance(loginUser, projectCode, + failedWorkflowDefinitionCode, scheduleTime, FailureStrategy.END, WarningType.NONE); + Assertions.assertTrue(startWorkflowInstanceResponse.getBody().getSuccess()); Review Comment: Same here. You should assert workflow instance running failed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
