From 0847512a389d0e7b3fc76a41f2072cd3396ee095 Mon Sep 17 00:00:00 2001 From: EricGao888 Date: Tue, 14 May 2024 11:03:04 +0800 Subject: [PATCH] Add ut cases to make sure yaml.loadXXX parse file correctly --- .../http/parser/HttpTaskDefinitionParser.java | 20 +++++++++---------- .../task/api/k8s/K8sTaskExecutorTest.java | 9 +++++++++ .../parser/HttpTaskDefinitionParserTest.java | 15 +++++++++++++- .../src/test/resources/mock_loop_task.yaml | 1 + 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParser.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParser.java index a9eae27a85ef..b28cd0c301cf 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParser.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParser.java @@ -63,16 +63,16 @@ public class HttpTaskDefinitionParser implements TaskDefinitionParser expectedCommands = Arrays.asList("perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"); + List actualCommands = + k8sTaskExecutor.getJob().getSpec().getTemplate().getSpec().getContainers().get(0).getCommand(); + Assertions.assertEquals(expectedCommands, actualCommands); + } + } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java index a68fa2321196..e25eaf72a1af 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java @@ -20,6 +20,8 @@ import org.apache.dolphinscheduler.plugin.task.api.loop.template.LoopTaskYamlDefinition; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -32,13 +34,24 @@ public class HttpTaskDefinitionParserTest { @Test public void parseYamlConfigFile() throws IOException { LoopTaskYamlDefinition loopTaskYamlDefinition = new HttpTaskDefinitionParser().parseYamlConfigFile(yamlFile); + // check not null Assertions.assertNotNull(loopTaskYamlDefinition); Assertions.assertNotNull(loopTaskYamlDefinition.getService()); + Assertions.assertNotNull(loopTaskYamlDefinition.getService().getName()); + Assertions.assertNotNull(loopTaskYamlDefinition.getService().getType()); + Assertions.assertNotNull(loopTaskYamlDefinition.getService().getApi()); + Assertions.assertNotNull(loopTaskYamlDefinition.getService().getApi().getSubmit()); + Assertions.assertNotNull(loopTaskYamlDefinition.getService().getApi().getQueryState()); + Assertions.assertNotNull(loopTaskYamlDefinition.getService().getApi().getCancel()); + // check data consistency LoopTaskYamlDefinition.LoopTaskServiceYamlDefinition service = loopTaskYamlDefinition.getService(); Assertions.assertEquals("MockService", service.getName()); Assertions.assertEquals("Http", service.getType()); + Map expectedHeaders = new HashMap<>(); + expectedHeaders.put("Content-Type", "text/html"); + expectedHeaders.put("Content-Length", "1234"); Assertions.assertEquals("/api/v1/submit", service.getApi().getSubmit().getUrl()); - Assertions.assertNotNull(service.getApi()); + Assertions.assertEquals(expectedHeaders, service.getApi().getSubmit().getHttpHeaders()); } @Test diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/resources/mock_loop_task.yaml b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/resources/mock_loop_task.yaml index 3f891c805b20..61c98e8632ff 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/resources/mock_loop_task.yaml +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/resources/mock_loop_task.yaml @@ -22,6 +22,7 @@ service: url: /api/v1/submit method: POST dataType: Json + httpHeaders: { "Content-Type": "text/html", "Content-Length": "1234" } requestParams: { "taskId": "704" } taskInstanceIdJPath: "$.taskInstanceId[0]" queryState: