You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/06/29 13:15:53 UTC

[GitHub] [dolphinscheduler] SbloodyS commented on a diff in pull request #10670: Project management basic test cases

SbloodyS commented on code in PR #10670:
URL: https://github.com/apache/dolphinscheduler/pull/10670#discussion_r909612131


##########
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/TaskInstanceAPITest.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to 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. Apache Software Foundation (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;
+
+import lombok.extern.slf4j.Slf4j;
+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.TaskInstancePage;
+import org.apache.dolphinscheduler.api.test.utils.JSONUtils;
+import org.junit.jupiter.api.*;

Review Comment:
   Same here.



##########
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/project/WorkFlowDefinitionPage.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to 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. Apache Software Foundation (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.pages.project;
+
+
+import org.apache.dolphinscheduler.api.test.core.Constants;
+import org.apache.dolphinscheduler.api.test.entity.HttpResponse;
+import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseData;
+import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseTotalList;
+import org.apache.dolphinscheduler.api.test.utils.JSONUtils;
+import org.apache.dolphinscheduler.api.test.utils.RequestClient;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+public final class WorkFlowDefinitionPage {
+    private static String genNumId = null;
+    private static String workFlowCode = null;
+
+    public void getGenNumId(String sessionId, String projectName) {
+
+        Map<String, Object> params = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
+        params.put("genNum", 1);
+        headers.put(Constants.SESSION_ID_KEY, sessionId);
+        ProjectPage project = new ProjectPage();
+        String projectCode = project.getProjectCode(sessionId, projectName);
+        RequestClient requestClient = new RequestClient();
+        HttpResponse res = requestClient.get("/projects/"+projectCode+"/task-definition/gen-task-codes", headers, params);
+        ArrayList list = (ArrayList) res.body().data();
+        genNumId = list.get(0).toString();
+
+
+    }
+
+
+    public HttpResponse createWorkflow(String sessionId, String projectName, String workFlowName) {
+        Map<String, Object> params = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
+        String taskDefinitionJson = "[{\"code\":" + genNumId + ",\"delayTime\":\"0\",\"description\":\"\",\"environmentCode\":-1,\"failRetryInterval\":\"1\",\"failRetryTimes\":\"0\",\"flag\":\"YES\",\"name\":\"echo_123\",\"taskParams\":{\"localParams\":[],\"rawScript\":\"echo 123\",\"resourceList\":[]},\"taskPriority\":\"MEDIUM\",\"taskType\":\"SHELL\",\"timeout\":0,\"timeoutFlag\":\"CLOSE\",\"timeoutNotifyStrategy\":\"\",\"workerGroup\":\"default\"}]";
+        String taskRelationJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":"+ genNumId + ",\"postTaskVersion\":0,\"conditionType\":\"NONE\",\"conditionParams\":{}}]";
+        String locations = "[{\"taskCode\":" + genNumId +",\"x\":33.5,\"y\":38.5}]";
+        params.put("taskDefinitionJson", taskDefinitionJson);
+        params.put("taskRelationJson", taskRelationJson);
+        params.put("locations", locations);
+        params.put("name", workFlowName);
+        params.put("tenantCode", "admin");
+        params.put("executionType", "PARALLEL");
+        params.put("description", "");
+        params.put("globalParams", "[]");
+        params.put("timeout", 0);
+        headers.put(Constants.SESSION_ID_KEY, sessionId);
+        RequestClient requestClient = new RequestClient();
+        ProjectPage project = new ProjectPage();
+        String projectCode = project.getProjectCode(sessionId, projectName);
+        System.out.printf("创建工作流 param是:%s",params);
+        System.out.printf("创建工作流header头是:%s", "/projects/"+projectCode+"/process-definition");
+        HttpResponse res = requestClient.post("/projects/"+projectCode+"/process-definition", headers, params);
+
+        System.out.printf("创建工作流结果:%s", res);

Review Comment:
   We should not use `System.out``` in any code. Please use `LOGGER`.



##########
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/project/WorkFlowDefinitionPage.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to 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. Apache Software Foundation (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.pages.project;
+
+
+import org.apache.dolphinscheduler.api.test.core.Constants;
+import org.apache.dolphinscheduler.api.test.entity.HttpResponse;
+import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseData;
+import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseTotalList;
+import org.apache.dolphinscheduler.api.test.utils.JSONUtils;
+import org.apache.dolphinscheduler.api.test.utils.RequestClient;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+public final class WorkFlowDefinitionPage {
+    private static String genNumId = null;
+    private static String workFlowCode = null;
+
+    public void getGenNumId(String sessionId, String projectName) {
+
+        Map<String, Object> params = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
+        params.put("genNum", 1);
+        headers.put(Constants.SESSION_ID_KEY, sessionId);
+        ProjectPage project = new ProjectPage();
+        String projectCode = project.getProjectCode(sessionId, projectName);
+        RequestClient requestClient = new RequestClient();
+        HttpResponse res = requestClient.get("/projects/"+projectCode+"/task-definition/gen-task-codes", headers, params);
+        ArrayList list = (ArrayList) res.body().data();
+        genNumId = list.get(0).toString();
+
+
+    }
+
+
+    public HttpResponse createWorkflow(String sessionId, String projectName, String workFlowName) {
+        Map<String, Object> params = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
+        String taskDefinitionJson = "[{\"code\":" + genNumId + ",\"delayTime\":\"0\",\"description\":\"\",\"environmentCode\":-1,\"failRetryInterval\":\"1\",\"failRetryTimes\":\"0\",\"flag\":\"YES\",\"name\":\"echo_123\",\"taskParams\":{\"localParams\":[],\"rawScript\":\"echo 123\",\"resourceList\":[]},\"taskPriority\":\"MEDIUM\",\"taskType\":\"SHELL\",\"timeout\":0,\"timeoutFlag\":\"CLOSE\",\"timeoutNotifyStrategy\":\"\",\"workerGroup\":\"default\"}]";
+        String taskRelationJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":"+ genNumId + ",\"postTaskVersion\":0,\"conditionType\":\"NONE\",\"conditionParams\":{}}]";
+        String locations = "[{\"taskCode\":" + genNumId +",\"x\":33.5,\"y\":38.5}]";
+        params.put("taskDefinitionJson", taskDefinitionJson);
+        params.put("taskRelationJson", taskRelationJson);
+        params.put("locations", locations);
+        params.put("name", workFlowName);
+        params.put("tenantCode", "admin");
+        params.put("executionType", "PARALLEL");
+        params.put("description", "");
+        params.put("globalParams", "[]");
+        params.put("timeout", 0);
+        headers.put(Constants.SESSION_ID_KEY, sessionId);
+        RequestClient requestClient = new RequestClient();
+        ProjectPage project = new ProjectPage();
+        String projectCode = project.getProjectCode(sessionId, projectName);
+        System.out.printf("创建工作流 param是:%s",params);
+        System.out.printf("创建工作流header头是:%s", "/projects/"+projectCode+"/process-definition");
+        HttpResponse res = requestClient.post("/projects/"+projectCode+"/process-definition", headers, params);
+
+        System.out.printf("创建工作流结果:%s", res);
+        return res;
+    }
+
+    public HttpResponse queryWorkflow(String sessionId, String projectName, String workFlowName) {
+        Map<String, Object> params = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
+        params.put("pageSize",10);
+        params.put("pageNo",1);
+        params.put("searchVal",workFlowName);
+        headers.put(Constants.SESSION_ID_KEY, sessionId);
+        RequestClient requestClient = new RequestClient();
+        ProjectPage project = new ProjectPage();
+        String projectCode = project.getProjectCode(sessionId, projectName);
+        HttpResponse res = requestClient.get("/projects/"+ projectCode + "/process-definition", headers, params);
+        System.out.printf("查询工作流结果:%s\n", res);
+        for (WorkFlowResponseTotalList workFlowList : JSONUtils.convertValue(res.body().data(), WorkFlowResponseData.class).totalList()) {
+            workFlowCode =  workFlowList.code();
+        }
+
+        return res;
+    }
+
+    public HttpResponse onLineWorkflow(String sessionId, String projectName, String workFlowName){
+        WorkFlowDefinitionPage workflow = new WorkFlowDefinitionPage();
+        workflow.queryWorkflow(sessionId, projectName, workFlowName);
+        Map<String, Object> params = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
+        params.put("name", workFlowName);
+        params.put("releaseState", "ONLINE");
+        headers.put(Constants.SESSION_ID_KEY, sessionId);
+        RequestClient requestClient = new RequestClient();
+        ProjectPage project = new ProjectPage();
+        String projectCode = project.getProjectCode(sessionId, projectName);
+        HttpResponse res = requestClient.post("/projects/"+projectCode+"/process-definition/"+workFlowCode+"/release", headers, params);
+
+        System.out.printf("上线工作流:%s", res);
+        return res;
+
+    }
+
+    public HttpResponse runWorkflow(String sessionId, String projectName, String workFlowName){
+        WorkFlowDefinitionPage workflow = new WorkFlowDefinitionPage();
+        workflow.queryWorkflow(sessionId, projectName, workFlowName);
+        workflow.onLineWorkflow(sessionId, projectName, workFlowName);
+        Map<String, Object> params = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
+        params.put("processDefinitionCode", workFlowCode);
+        params.put("startEndTime", "2022-06-25T16:00:00.000Z");
+        params.put("startEndTime", "2022-06-25T16:00:00.000Z");
+        params.put("scheduleTime", "2022-06-26 00:00:00,2022-06-26 00:00:00");
+        params.put("failureStrategy", "CONTINUE");
+        params.put("warningType", "NONE");
+        params.put("warningGroupId", "");
+        params.put("execType", "START_PROCESS");
+        params.put("startNodeList", "");
+        params.put("taskDependType", "TASK_POST");
+        params.put("dependentMode", "OFF_MODE");
+        params.put("runMode", "RUN_MODE_SERIAL");
+        params.put("processInstancePriority", "MEDIUM");
+        params.put("workerGroup", "default");
+        params.put("environmentCode", "");
+        params.put("startParams", "");
+        params.put("expectedParallelismNumber", "");
+        params.put("dryRun", 0);

Review Comment:
   It is recommended to create an entity class instead of a map to increase code readability and reusability.



##########
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/project/WorkFlowDefinitionPage.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to 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. Apache Software Foundation (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.pages.project;
+
+
+import org.apache.dolphinscheduler.api.test.core.Constants;
+import org.apache.dolphinscheduler.api.test.entity.HttpResponse;
+import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseData;
+import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseTotalList;
+import org.apache.dolphinscheduler.api.test.utils.JSONUtils;
+import org.apache.dolphinscheduler.api.test.utils.RequestClient;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+public final class WorkFlowDefinitionPage {
+    private static String genNumId = null;
+    private static String workFlowCode = null;
+
+    public void getGenNumId(String sessionId, String projectName) {
+
+        Map<String, Object> params = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
+        params.put("genNum", 1);
+        headers.put(Constants.SESSION_ID_KEY, sessionId);
+        ProjectPage project = new ProjectPage();
+        String projectCode = project.getProjectCode(sessionId, projectName);
+        RequestClient requestClient = new RequestClient();
+        HttpResponse res = requestClient.get("/projects/"+projectCode+"/task-definition/gen-task-codes", headers, params);
+        ArrayList list = (ArrayList) res.body().data();
+        genNumId = list.get(0).toString();
+
+
+    }
+
+
+    public HttpResponse createWorkflow(String sessionId, String projectName, String workFlowName) {
+        Map<String, Object> params = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
+        String taskDefinitionJson = "[{\"code\":" + genNumId + ",\"delayTime\":\"0\",\"description\":\"\",\"environmentCode\":-1,\"failRetryInterval\":\"1\",\"failRetryTimes\":\"0\",\"flag\":\"YES\",\"name\":\"echo_123\",\"taskParams\":{\"localParams\":[],\"rawScript\":\"echo 123\",\"resourceList\":[]},\"taskPriority\":\"MEDIUM\",\"taskType\":\"SHELL\",\"timeout\":0,\"timeoutFlag\":\"CLOSE\",\"timeoutNotifyStrategy\":\"\",\"workerGroup\":\"default\"}]";
+        String taskRelationJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":"+ genNumId + ",\"postTaskVersion\":0,\"conditionType\":\"NONE\",\"conditionParams\":{}}]";
+        String locations = "[{\"taskCode\":" + genNumId +",\"x\":33.5,\"y\":38.5}]";
+        params.put("taskDefinitionJson", taskDefinitionJson);
+        params.put("taskRelationJson", taskRelationJson);
+        params.put("locations", locations);
+        params.put("name", workFlowName);
+        params.put("tenantCode", "admin");
+        params.put("executionType", "PARALLEL");
+        params.put("description", "");
+        params.put("globalParams", "[]");
+        params.put("timeout", 0);
+        headers.put(Constants.SESSION_ID_KEY, sessionId);

Review Comment:
   Same as line 142.



##########
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/WorkFlowInstanceAPITest.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to 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. Apache Software Foundation (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;
+
+import lombok.extern.slf4j.Slf4j;
+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.WorkFlowDefinitionPage;
+import org.apache.dolphinscheduler.api.test.utils.JSONUtils;
+import org.junit.jupiter.api.*;

Review Comment:
   Same here.



##########
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/ProjectAPITest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to 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. Apache Software Foundation (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;
+
+import lombok.extern.slf4j.Slf4j;
+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.utils.JSONUtils;
+import org.junit.jupiter.api.*;

Review Comment:
   Please avoid import *



##########
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/WorkFlowAPITest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to 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. Apache Software Foundation (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;
+
+import lombok.extern.slf4j.Slf4j;
+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.WorkFlowDefinitionPage;
+import org.apache.dolphinscheduler.api.test.utils.JSONUtils;
+import org.junit.jupiter.api.*;

Review Comment:
   Same here.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org