Browse Source

[Improvement][Test] Migrate all UT cases from jUnit4 to jUnit5 in task-plugin module as an example (#12299)

* Migrate all UT cases from jUnit4 to jUnit5 in task-plugin module as an example
3.2.0-release
Eric Gao 2 years ago committed by GitHub
parent
commit
875682d267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTaskTest.java
  2. 22
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/TaskTest.java
  3. 25
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/CheckTypeTest.java
  4. 15
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ConnectorTypeTest.java
  5. 17
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqFailureStrategyTest.java
  6. 23
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqTaskStateTest.java
  7. 23
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ExecuteSqlTypeTest.java
  8. 29
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/InputTypeTest.java
  9. 41
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OperatorTypeTest.java
  10. 29
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OptionSourceTypeTest.java
  11. 29
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/RuleTypeTest.java
  12. 30
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ValueTypeTest.java
  13. 15
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/k8s/K8sTaskExecutorTest.java
  14. 14
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java
  15. 11
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java
  16. 32
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java
  17. 14
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/resource/AbstractResourceParametersTest.java
  18. 21
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtilsTest.java
  19. 38
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java
  20. 165
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/DependentUtilsTest.java
  21. 6
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JdbcUrlParserTest.java
  22. 10
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JsonPathUtilsTest.java
  23. 6
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/LogUtilsTest.java
  24. 15
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java
  25. 14
      dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunConstantsTest.java
  26. 16
      dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunParametersTest.java
  27. 17
      dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityParameterTest.java
  28. 12
      dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityTaskTest.java
  29. 7
      dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/utils/Md5UtilsTest.java
  30. 55
      dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/test/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncTaskTest.java
  31. 11
      dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxParametersTest.java
  32. 92
      dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsHookTest.java
  33. 69
      dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsTaskTest.java
  34. 26
      dolphinscheduler-task-plugin/dolphinscheduler-task-dvc/src/test/java/org/apache/dolphinscheduler/plugin/task/dvc/DvcTaskTest.java
  35. 47
      dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java
  36. 77
      dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java
  37. 52
      dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java
  38. 15
      dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java
  39. 52
      dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java
  40. 15
      dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java
  41. 16
      dolphinscheduler-task-plugin/dolphinscheduler-task-hivecli/src/test/java/org/apache/dolphinscheduler/plugin/task/hivecli/HiveCliTaskTest.java
  42. 48
      dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java
  43. 42
      dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpTaskTest.java
  44. 42
      dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/test/java/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java
  45. 16
      dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/test/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTaskTest.java
  46. 24
      dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sParametersTest.java
  47. 19
      dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java
  48. 66
      dolphinscheduler-task-plugin/dolphinscheduler-task-mlflow/src/test/java/org/apache/dolphinler/plugin/task/mlflow/MlflowTaskTest.java
  49. 17
      dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java
  50. 29
      dolphinscheduler-task-plugin/dolphinscheduler-task-pigeon/src/test/java/org/apache/dolphinscheduler/plugin/task/pigeon/PigeonTaskTest.java
  51. 6
      dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java
  52. 72
      dolphinscheduler-task-plugin/dolphinscheduler-task-pytorch/src/test/java/org/apache/dolphinscheduler/plugin/task/pytorch/PytorchTaskTest.java
  53. 45
      dolphinscheduler-task-plugin/dolphinscheduler-task-sagemaker/src/test/java/org/apache/dolphinscheduler/plugin/task/sagemaker/SagemakerTaskTest.java
  54. 14
      dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkParametersTest.java
  55. 14
      dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkTaskTest.java
  56. 4
      dolphinscheduler-task-plugin/dolphinscheduler-task-sqoop/src/test/java/org/apache/dolphinscheduler/plugin/task/sqoop/SqoopParameterEntityTest.java
  57. 52
      dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java

9
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/AbstractTaskTest.java

@ -16,11 +16,12 @@
*/ */
package org.apache.dolphinscheduler.plugin.task.api; package org.apache.dolphinscheduler.plugin.task.api;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class AbstractTaskTest { public class AbstractTaskTest {
@ -33,8 +34,8 @@ public class AbstractTaskTest {
if (matcher.find()) { if (matcher.find()) {
str = matcher.group(); str = matcher.group();
} }
Assert.assertNotNull(str); Assertions.assertNotNull(str);
Assert.assertEquals(jobId, str.substring(6)); Assertions.assertEquals(jobId, str.substring(6));
} }
} }

22
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/TaskTest.java

@ -1,22 +0,0 @@
package org.apache.dolphinscheduler.plugin.task.api;/*
* 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.
*/
public class TaskTest {
}

25
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/CheckTypeTest.java

@ -17,30 +17,31 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class CheckTypeTest { public class CheckTypeTest {
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, CheckType.COMPARISON_MINUS_STATISTICS.getCode()); Assertions.assertEquals(0, CheckType.COMPARISON_MINUS_STATISTICS.getCode());
assertEquals(1, CheckType.STATISTICS_MINUS_COMPARISON.getCode()); Assertions.assertEquals(1, CheckType.STATISTICS_MINUS_COMPARISON.getCode());
assertEquals(2, CheckType.STATISTICS_COMPARISON_PERCENTAGE.getCode()); Assertions.assertEquals(2, CheckType.STATISTICS_COMPARISON_PERCENTAGE.getCode());
assertEquals(3, CheckType.STATISTICS_COMPARISON_DIFFERENCE_COMPARISON_PERCENTAGE.getCode()); Assertions.assertEquals(3, CheckType.STATISTICS_COMPARISON_DIFFERENCE_COMPARISON_PERCENTAGE.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("comparison_minus_statistics", CheckType.COMPARISON_MINUS_STATISTICS.getDescription()); Assertions.assertEquals("comparison_minus_statistics", CheckType.COMPARISON_MINUS_STATISTICS.getDescription());
assertEquals("statistics_minus_comparison", CheckType.STATISTICS_MINUS_COMPARISON.getDescription()); Assertions.assertEquals("statistics_minus_comparison", CheckType.STATISTICS_MINUS_COMPARISON.getDescription());
assertEquals("statistics_comparison_percentage", CheckType.STATISTICS_COMPARISON_PERCENTAGE.getDescription()); Assertions.assertEquals("statistics_comparison_percentage",
assertEquals("statistics_comparison_difference_comparison_percentage", CheckType.STATISTICS_COMPARISON_DIFFERENCE_COMPARISON_PERCENTAGE.getDescription()); CheckType.STATISTICS_COMPARISON_PERCENTAGE.getDescription());
Assertions.assertEquals("statistics_comparison_difference_comparison_percentage",
CheckType.STATISTICS_COMPARISON_DIFFERENCE_COMPARISON_PERCENTAGE.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(CheckType.COMPARISON_MINUS_STATISTICS, CheckType.of(0)); Assertions.assertEquals(CheckType.COMPARISON_MINUS_STATISTICS, CheckType.of(0));
} }
} }

15
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ConnectorTypeTest.java

@ -17,26 +17,25 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class ConnectorTypeTest { public class ConnectorTypeTest {
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, ConnectorType.JDBC.getCode()); Assertions.assertEquals(0, ConnectorType.JDBC.getCode());
assertEquals(1, ConnectorType.HIVE.getCode()); Assertions.assertEquals(1, ConnectorType.HIVE.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("JDBC", ConnectorType.JDBC.getDescription()); Assertions.assertEquals("JDBC", ConnectorType.JDBC.getDescription());
assertEquals("HIVE", ConnectorType.HIVE.getDescription()); Assertions.assertEquals("HIVE", ConnectorType.HIVE.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(ConnectorType.JDBC, ConnectorType.of(0)); Assertions.assertEquals(ConnectorType.JDBC, ConnectorType.of(0));
} }
} }

17
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqFailureStrategyTest.java

@ -17,27 +17,26 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class DqFailureStrategyTest { public class DqFailureStrategyTest {
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, DqFailureStrategy.ALERT.getCode()); Assertions.assertEquals(0, DqFailureStrategy.ALERT.getCode());
assertEquals(1, DqFailureStrategy.BLOCK.getCode()); Assertions.assertEquals(1, DqFailureStrategy.BLOCK.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("alert", DqFailureStrategy.ALERT.getDescription()); Assertions.assertEquals("alert", DqFailureStrategy.ALERT.getDescription());
assertEquals("block", DqFailureStrategy.BLOCK.getDescription()); Assertions.assertEquals("block", DqFailureStrategy.BLOCK.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(DqFailureStrategy.ALERT, DqFailureStrategy.of(0)); Assertions.assertEquals(DqFailureStrategy.ALERT, DqFailureStrategy.of(0));
assertEquals(DqFailureStrategy.BLOCK, DqFailureStrategy.of(1)); Assertions.assertEquals(DqFailureStrategy.BLOCK, DqFailureStrategy.of(1));
} }
} }

23
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/DqTaskStateTest.java

@ -17,30 +17,29 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class DqTaskStateTest { public class DqTaskStateTest {
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, DqTaskState.DEFAULT.getCode()); Assertions.assertEquals(0, DqTaskState.DEFAULT.getCode());
assertEquals(1, DqTaskState.SUCCESS.getCode()); Assertions.assertEquals(1, DqTaskState.SUCCESS.getCode());
assertEquals(2, DqTaskState.FAILURE.getCode()); Assertions.assertEquals(2, DqTaskState.FAILURE.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("default", DqTaskState.DEFAULT.getDescription()); Assertions.assertEquals("default", DqTaskState.DEFAULT.getDescription());
assertEquals("success", DqTaskState.SUCCESS.getDescription()); Assertions.assertEquals("success", DqTaskState.SUCCESS.getDescription());
assertEquals("failure", DqTaskState.FAILURE.getDescription()); Assertions.assertEquals("failure", DqTaskState.FAILURE.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(DqTaskState.DEFAULT, DqTaskState.of(0)); Assertions.assertEquals(DqTaskState.DEFAULT, DqTaskState.of(0));
assertEquals(DqTaskState.SUCCESS, DqTaskState.of(1)); Assertions.assertEquals(DqTaskState.SUCCESS, DqTaskState.of(1));
assertEquals(DqTaskState.FAILURE, DqTaskState.of(2)); Assertions.assertEquals(DqTaskState.FAILURE, DqTaskState.of(2));
} }
} }

23
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ExecuteSqlTypeTest.java

@ -17,30 +17,29 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class ExecuteSqlTypeTest { public class ExecuteSqlTypeTest {
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, ExecuteSqlType.MIDDLE.getCode()); Assertions.assertEquals(0, ExecuteSqlType.MIDDLE.getCode());
assertEquals(1, ExecuteSqlType.STATISTICS.getCode()); Assertions.assertEquals(1, ExecuteSqlType.STATISTICS.getCode());
assertEquals(2, ExecuteSqlType.COMPARISON.getCode()); Assertions.assertEquals(2, ExecuteSqlType.COMPARISON.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("middle", ExecuteSqlType.MIDDLE.getDescription()); Assertions.assertEquals("middle", ExecuteSqlType.MIDDLE.getDescription());
assertEquals("statistics", ExecuteSqlType.STATISTICS.getDescription()); Assertions.assertEquals("statistics", ExecuteSqlType.STATISTICS.getDescription());
assertEquals("comparison", ExecuteSqlType.COMPARISON.getDescription()); Assertions.assertEquals("comparison", ExecuteSqlType.COMPARISON.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(ExecuteSqlType.MIDDLE, ExecuteSqlType.of(0)); Assertions.assertEquals(ExecuteSqlType.MIDDLE, ExecuteSqlType.of(0));
assertEquals(ExecuteSqlType.STATISTICS, ExecuteSqlType.of(1)); Assertions.assertEquals(ExecuteSqlType.STATISTICS, ExecuteSqlType.of(1));
assertEquals(ExecuteSqlType.COMPARISON, ExecuteSqlType.of(2)); Assertions.assertEquals(ExecuteSqlType.COMPARISON, ExecuteSqlType.of(2));
} }
} }

29
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/InputTypeTest.java

@ -17,33 +17,32 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class InputTypeTest { public class InputTypeTest {
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, InputType.DEFAULT.getCode()); Assertions.assertEquals(0, InputType.DEFAULT.getCode());
assertEquals(1, InputType.STATISTICS.getCode()); Assertions.assertEquals(1, InputType.STATISTICS.getCode());
assertEquals(2, InputType.COMPARISON.getCode()); Assertions.assertEquals(2, InputType.COMPARISON.getCode());
assertEquals(3, InputType.CHECK.getCode()); Assertions.assertEquals(3, InputType.CHECK.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("default", InputType.DEFAULT.getDescription()); Assertions.assertEquals("default", InputType.DEFAULT.getDescription());
assertEquals("statistics", InputType.STATISTICS.getDescription()); Assertions.assertEquals("statistics", InputType.STATISTICS.getDescription());
assertEquals("comparison", InputType.COMPARISON.getDescription()); Assertions.assertEquals("comparison", InputType.COMPARISON.getDescription());
assertEquals("check", InputType.CHECK.getDescription()); Assertions.assertEquals("check", InputType.CHECK.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(InputType.DEFAULT, InputType.of(0)); Assertions.assertEquals(InputType.DEFAULT, InputType.of(0));
assertEquals(InputType.STATISTICS, InputType.of(1)); Assertions.assertEquals(InputType.STATISTICS, InputType.of(1));
assertEquals(InputType.COMPARISON, InputType.of(2)); Assertions.assertEquals(InputType.COMPARISON, InputType.of(2));
assertEquals(InputType.CHECK, InputType.of(3)); Assertions.assertEquals(InputType.CHECK, InputType.of(3));
} }
} }

41
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OperatorTypeTest.java

@ -17,39 +17,38 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class OperatorTypeTest { public class OperatorTypeTest {
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, OperatorType.EQ.getCode()); Assertions.assertEquals(0, OperatorType.EQ.getCode());
assertEquals(1, OperatorType.LT.getCode()); Assertions.assertEquals(1, OperatorType.LT.getCode());
assertEquals(2, OperatorType.LE.getCode()); Assertions.assertEquals(2, OperatorType.LE.getCode());
assertEquals(3, OperatorType.GT.getCode()); Assertions.assertEquals(3, OperatorType.GT.getCode());
assertEquals(4, OperatorType.GE.getCode()); Assertions.assertEquals(4, OperatorType.GE.getCode());
assertEquals(5, OperatorType.NE.getCode()); Assertions.assertEquals(5, OperatorType.NE.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("equal", OperatorType.EQ.getDescription()); Assertions.assertEquals("equal", OperatorType.EQ.getDescription());
assertEquals("little than", OperatorType.LT.getDescription()); Assertions.assertEquals("little than", OperatorType.LT.getDescription());
assertEquals("little and equal", OperatorType.LE.getDescription()); Assertions.assertEquals("little and equal", OperatorType.LE.getDescription());
assertEquals("great than", OperatorType.GT.getDescription()); Assertions.assertEquals("great than", OperatorType.GT.getDescription());
assertEquals("great and equal", OperatorType.GE.getDescription()); Assertions.assertEquals("great and equal", OperatorType.GE.getDescription());
assertEquals("not equal", OperatorType.NE.getDescription()); Assertions.assertEquals("not equal", OperatorType.NE.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(OperatorType.EQ, OperatorType.of(0)); Assertions.assertEquals(OperatorType.EQ, OperatorType.of(0));
assertEquals(OperatorType.LT, OperatorType.of(1)); Assertions.assertEquals(OperatorType.LT, OperatorType.of(1));
assertEquals(OperatorType.LE, OperatorType.of(2)); Assertions.assertEquals(OperatorType.LE, OperatorType.of(2));
assertEquals(OperatorType.GT, OperatorType.of(3)); Assertions.assertEquals(OperatorType.GT, OperatorType.of(3));
assertEquals(OperatorType.GE, OperatorType.of(4)); Assertions.assertEquals(OperatorType.GE, OperatorType.of(4));
assertEquals(OperatorType.NE, OperatorType.of(5)); Assertions.assertEquals(OperatorType.NE, OperatorType.of(5));
} }
} }

29
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OptionSourceTypeTest.java

@ -17,33 +17,32 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class OptionSourceTypeTest { public class OptionSourceTypeTest {
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, OptionSourceType.DEFAULT.getCode()); Assertions.assertEquals(0, OptionSourceType.DEFAULT.getCode());
assertEquals(1, OptionSourceType.DATASOURCE_ID.getCode()); Assertions.assertEquals(1, OptionSourceType.DATASOURCE_ID.getCode());
assertEquals(2, OptionSourceType.DATASOURCE_TYPE.getCode()); Assertions.assertEquals(2, OptionSourceType.DATASOURCE_TYPE.getCode());
assertEquals(3, OptionSourceType.COMPARISON_TYPE.getCode()); Assertions.assertEquals(3, OptionSourceType.COMPARISON_TYPE.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("default", OptionSourceType.DEFAULT.getDescription()); Assertions.assertEquals("default", OptionSourceType.DEFAULT.getDescription());
assertEquals("datasource_id", OptionSourceType.DATASOURCE_ID.getDescription()); Assertions.assertEquals("datasource_id", OptionSourceType.DATASOURCE_ID.getDescription());
assertEquals("datasource_type", OptionSourceType.DATASOURCE_TYPE.getDescription()); Assertions.assertEquals("datasource_type", OptionSourceType.DATASOURCE_TYPE.getDescription());
assertEquals("comparison_type", OptionSourceType.COMPARISON_TYPE.getDescription()); Assertions.assertEquals("comparison_type", OptionSourceType.COMPARISON_TYPE.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(OptionSourceType.DEFAULT, OptionSourceType.of(0)); Assertions.assertEquals(OptionSourceType.DEFAULT, OptionSourceType.of(0));
assertEquals(OptionSourceType.DATASOURCE_ID, OptionSourceType.of(1)); Assertions.assertEquals(OptionSourceType.DATASOURCE_ID, OptionSourceType.of(1));
assertEquals(OptionSourceType.DATASOURCE_TYPE, OptionSourceType.of(2)); Assertions.assertEquals(OptionSourceType.DATASOURCE_TYPE, OptionSourceType.of(2));
assertEquals(OptionSourceType.COMPARISON_TYPE, OptionSourceType.of(3)); Assertions.assertEquals(OptionSourceType.COMPARISON_TYPE, OptionSourceType.of(3));
} }
} }

29
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/RuleTypeTest.java

@ -17,33 +17,32 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class RuleTypeTest { public class RuleTypeTest {
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, RuleType.SINGLE_TABLE.getCode()); Assertions.assertEquals(0, RuleType.SINGLE_TABLE.getCode());
assertEquals(1, RuleType.SINGLE_TABLE_CUSTOM_SQL.getCode()); Assertions.assertEquals(1, RuleType.SINGLE_TABLE_CUSTOM_SQL.getCode());
assertEquals(2, RuleType.MULTI_TABLE_ACCURACY.getCode()); Assertions.assertEquals(2, RuleType.MULTI_TABLE_ACCURACY.getCode());
assertEquals(3, RuleType.MULTI_TABLE_COMPARISON.getCode()); Assertions.assertEquals(3, RuleType.MULTI_TABLE_COMPARISON.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("single_table", RuleType.SINGLE_TABLE.getDescription()); Assertions.assertEquals("single_table", RuleType.SINGLE_TABLE.getDescription());
assertEquals("single_table_custom_sql", RuleType.SINGLE_TABLE_CUSTOM_SQL.getDescription()); Assertions.assertEquals("single_table_custom_sql", RuleType.SINGLE_TABLE_CUSTOM_SQL.getDescription());
assertEquals("multi_table_accuracy", RuleType.MULTI_TABLE_ACCURACY.getDescription()); Assertions.assertEquals("multi_table_accuracy", RuleType.MULTI_TABLE_ACCURACY.getDescription());
assertEquals("multi_table_comparison", RuleType.MULTI_TABLE_COMPARISON.getDescription()); Assertions.assertEquals("multi_table_comparison", RuleType.MULTI_TABLE_COMPARISON.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(RuleType.SINGLE_TABLE, RuleType.of(0)); Assertions.assertEquals(RuleType.SINGLE_TABLE, RuleType.of(0));
assertEquals(RuleType.SINGLE_TABLE_CUSTOM_SQL, RuleType.of(1)); Assertions.assertEquals(RuleType.SINGLE_TABLE_CUSTOM_SQL, RuleType.of(1));
assertEquals(RuleType.MULTI_TABLE_ACCURACY, RuleType.of(2)); Assertions.assertEquals(RuleType.MULTI_TABLE_ACCURACY, RuleType.of(2));
assertEquals(RuleType.MULTI_TABLE_COMPARISON, RuleType.of(3)); Assertions.assertEquals(RuleType.MULTI_TABLE_COMPARISON, RuleType.of(3));
} }
} }

30
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/ValueTypeTest.java

@ -17,11 +17,11 @@
package org.apache.dolphinscheduler.plugin.task.api.enums.dp; package org.apache.dolphinscheduler.plugin.task.api.enums.dp;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class ValueTypeTest { public class ValueTypeTest {
/** /**
* 0-string * 0-string
* 1-list * 1-list
@ -30,25 +30,25 @@ public class ValueTypeTest {
*/ */
@Test @Test
public void testGetCode() { public void testGetCode() {
assertEquals(0, ValueType.STRING.getCode()); Assertions.assertEquals(0, ValueType.STRING.getCode());
assertEquals(1, ValueType.LIST.getCode()); Assertions.assertEquals(1, ValueType.LIST.getCode());
assertEquals(2, ValueType.NUMBER.getCode()); Assertions.assertEquals(2, ValueType.NUMBER.getCode());
assertEquals(3, ValueType.LIKE_SQL.getCode()); Assertions.assertEquals(3, ValueType.LIKE_SQL.getCode());
} }
@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertEquals("string", ValueType.STRING.getDescription()); Assertions.assertEquals("string", ValueType.STRING.getDescription());
assertEquals("list", ValueType.LIST.getDescription()); Assertions.assertEquals("list", ValueType.LIST.getDescription());
assertEquals("number", ValueType.NUMBER.getDescription()); Assertions.assertEquals("number", ValueType.NUMBER.getDescription());
assertEquals("sql", ValueType.LIKE_SQL.getDescription()); Assertions.assertEquals("sql", ValueType.LIKE_SQL.getDescription());
} }
@Test @Test
public void testOf() { public void testOf() {
assertEquals(ValueType.STRING, ValueType.of(0)); Assertions.assertEquals(ValueType.STRING, ValueType.of(0));
assertEquals(ValueType.LIST, ValueType.of(1)); Assertions.assertEquals(ValueType.LIST, ValueType.of(1));
assertEquals(ValueType.NUMBER, ValueType.of(2)); Assertions.assertEquals(ValueType.NUMBER, ValueType.of(2));
assertEquals(ValueType.LIKE_SQL, ValueType.of(3)); Assertions.assertEquals(ValueType.LIKE_SQL, ValueType.of(3));
} }
} }

15
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/k8s/K8sTaskExecutorTest.java

@ -20,7 +20,6 @@ package org.apache.dolphinscheduler.plugin.task.api.k8s;
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.CLUSTER; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.CLUSTER;
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_KILL; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_KILL;
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.NAMESPACE_NAME; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.NAMESPACE_NAME;
import static org.hamcrest.Matchers.is;
import org.apache.dolphinscheduler.plugin.task.api.TaskException; import org.apache.dolphinscheduler.plugin.task.api.TaskException;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
@ -30,9 +29,9 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import io.fabric8.kubernetes.api.model.batch.v1.Job; import io.fabric8.kubernetes.api.model.batch.v1.Job;
import io.fabric8.kubernetes.api.model.batch.v1.JobStatus; import io.fabric8.kubernetes.api.model.batch.v1.JobStatus;
@ -48,7 +47,7 @@ public class K8sTaskExecutorTest {
private final int taskInstanceId = 1000; private final int taskInstanceId = 1000;
private final String taskName = "k8s_task_test"; private final String taskName = "k8s_task_test";
private Job job; private Job job;
@Before @BeforeEach
public void before() { public void before() {
TaskExecutionContext taskRequest = new TaskExecutionContext(); TaskExecutionContext taskRequest = new TaskExecutionContext();
taskRequest.setTaskInstanceId(taskInstanceId); taskRequest.setTaskInstanceId(taskInstanceId);
@ -70,7 +69,7 @@ public class K8sTaskExecutorTest {
JobStatus jobStatus = new JobStatus(); JobStatus jobStatus = new JobStatus();
jobStatus.setSucceeded(1); jobStatus.setSucceeded(1);
job.setStatus(jobStatus); job.setStatus(jobStatus);
Assert.assertEquals(0, Integer.compare(0, k8sTaskExecutor.getK8sJobStatus(job))); Assertions.assertEquals(0, Integer.compare(0, k8sTaskExecutor.getK8sJobStatus(job)));
} }
@Test @Test
public void testSetTaskStatusNormal() { public void testSetTaskStatusNormal() {
@ -79,14 +78,14 @@ public class K8sTaskExecutorTest {
K8sTaskMainParameters k8STaskMainParameters = new K8sTaskMainParameters(); K8sTaskMainParameters k8STaskMainParameters = new K8sTaskMainParameters();
k8sTaskExecutor.setJob(job); k8sTaskExecutor.setJob(job);
k8sTaskExecutor.setTaskStatus(jobStatus, String.valueOf(taskInstanceId), taskResponse, k8STaskMainParameters); k8sTaskExecutor.setTaskStatus(jobStatus, String.valueOf(taskInstanceId), taskResponse, k8STaskMainParameters);
Assert.assertEquals(0, Integer.compare(EXIT_CODE_KILL, taskResponse.getExitStatusCode())); Assertions.assertEquals(0, Integer.compare(EXIT_CODE_KILL, taskResponse.getExitStatusCode()));
} }
@Test @Test
public void testWaitTimeoutNormal() { public void testWaitTimeoutNormal() {
try { try {
k8sTaskExecutor.waitTimeout(true); k8sTaskExecutor.waitTimeout(true);
} catch (TaskException e) { } catch (TaskException e) {
Assert.assertThat(e.getMessage(), is("K8sTask is timeout")); Assertions.assertEquals(e.getMessage(), "K8sTask is timeout");
} }
} }
} }

14
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/parser/HttpTaskDefinitionParserTest.java

@ -21,8 +21,8 @@ import org.apache.dolphinscheduler.plugin.task.api.loop.template.LoopTaskYamlDef
import java.io.IOException; import java.io.IOException;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class HttpTaskDefinitionParserTest { public class HttpTaskDefinitionParserTest {
@ -32,11 +32,11 @@ public class HttpTaskDefinitionParserTest {
@Test @Test
public void parseYamlConfigFile() throws IOException { public void parseYamlConfigFile() throws IOException {
LoopTaskYamlDefinition loopTaskYamlDefinition = new HttpTaskDefinitionParser().parseYamlConfigFile(yamlFile); LoopTaskYamlDefinition loopTaskYamlDefinition = new HttpTaskDefinitionParser().parseYamlConfigFile(yamlFile);
Assert.assertNotNull(loopTaskYamlDefinition); Assertions.assertNotNull(loopTaskYamlDefinition);
Assert.assertNotNull(loopTaskYamlDefinition.getService()); Assertions.assertNotNull(loopTaskYamlDefinition.getService());
LoopTaskYamlDefinition.LoopTaskServiceYamlDefinition service = loopTaskYamlDefinition.getService(); LoopTaskYamlDefinition.LoopTaskServiceYamlDefinition service = loopTaskYamlDefinition.getService();
Assert.assertEquals("MockService", service.getName()); Assertions.assertEquals("MockService", service.getName());
Assert.assertNotNull(service.getApi()); Assertions.assertNotNull(service.getApi());
} }
@Test @Test
@ -45,7 +45,7 @@ public class HttpTaskDefinitionParserTest {
LoopTaskYamlDefinition loopTaskYamlDefinition = httpTaskDefinitionParser.parseYamlConfigFile(yamlFile); LoopTaskYamlDefinition loopTaskYamlDefinition = httpTaskDefinitionParser.parseYamlConfigFile(yamlFile);
httpTaskDefinitionParser.validateYamlDefinition(loopTaskYamlDefinition); httpTaskDefinitionParser.validateYamlDefinition(loopTaskYamlDefinition);
// if no exception assert true // if no exception assert true
Assert.assertTrue(true); Assertions.assertTrue(true);
} }
} }

11
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java

@ -25,14 +25,15 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class AbstractParametersTest { public class AbstractParametersTest {
@Test @Test
public void testGetInputLocalParametersMap() { public void testGetInputLocalParametersMap() {
AbstractParameters parameters = new AbstractParameters() { AbstractParameters parameters = new AbstractParameters() {
@Override @Override
public boolean checkParameters() { public boolean checkParameters() {
return false; return false;
@ -47,8 +48,8 @@ public class AbstractParametersTest {
// should return property key1 and key2 (direct null and IN) // should return property key1 and key2 (direct null and IN)
Map<String, Property> inputLocalParametersMap = parameters.getInputLocalParametersMap(); Map<String, Property> inputLocalParametersMap = parameters.getInputLocalParametersMap();
Assert.assertEquals(2, inputLocalParametersMap.size()); Assertions.assertEquals(2, inputLocalParametersMap.size());
Assert.assertTrue(inputLocalParametersMap.containsKey("key1")); Assertions.assertTrue(inputLocalParametersMap.containsKey("key1"));
Assert.assertTrue(inputLocalParametersMap.containsKey("key2")); Assertions.assertTrue(inputLocalParametersMap.containsKey("key2"));
} }
} }

32
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java

@ -17,8 +17,6 @@
package org.apache.dolphinscheduler.plugin.task.api.parameters; package org.apache.dolphinscheduler.plugin.task.api.parameters;
import static org.junit.Assert.assertNotNull;
import org.apache.dolphinscheduler.plugin.task.api.enums.DataType; import org.apache.dolphinscheduler.plugin.task.api.enums.DataType;
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct; import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
import org.apache.dolphinscheduler.plugin.task.api.model.Property; import org.apache.dolphinscheduler.plugin.task.api.model.Property;
@ -28,8 +26,8 @@ import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class SqlParametersTest { public class SqlParametersTest {
@ -55,7 +53,7 @@ public class SqlParametersTest {
properties.add(property); properties.add(property);
SqlParameters sqlParameters = new SqlParameters(); SqlParameters sqlParameters = new SqlParameters();
Assert.assertTrue(CollectionUtils.isEmpty(sqlParameters.getResourceFilesList())); Assertions.assertTrue(CollectionUtils.isEmpty(sqlParameters.getResourceFilesList()));
sqlParameters.setType(type); sqlParameters.setType(type);
sqlParameters.setSql(sql); sqlParameters.setSql(sql);
@ -68,29 +66,29 @@ public class SqlParametersTest {
sqlParameters.setTitle(title); sqlParameters.setTitle(title);
sqlParameters.setGroupId(groupId); sqlParameters.setGroupId(groupId);
Assert.assertEquals(type, sqlParameters.getType()); Assertions.assertEquals(type, sqlParameters.getType());
Assert.assertEquals(sql, sqlParameters.getSql()); Assertions.assertEquals(sql, sqlParameters.getSql());
Assert.assertEquals(udfs, sqlParameters.getUdfs()); Assertions.assertEquals(udfs, sqlParameters.getUdfs());
Assert.assertEquals(datasource, sqlParameters.getDatasource()); Assertions.assertEquals(datasource, sqlParameters.getDatasource());
Assert.assertEquals(sqlType, sqlParameters.getSqlType()); Assertions.assertEquals(sqlType, sqlParameters.getSqlType());
Assert.assertEquals(sendEmail, sqlParameters.getSendEmail()); Assertions.assertEquals(sendEmail, sqlParameters.getSendEmail());
Assert.assertEquals(displayRows, sqlParameters.getDisplayRows()); Assertions.assertEquals(displayRows, sqlParameters.getDisplayRows());
Assert.assertEquals(showType, sqlParameters.getShowType()); Assertions.assertEquals(showType, sqlParameters.getShowType());
Assert.assertEquals(title, sqlParameters.getTitle()); Assertions.assertEquals(title, sqlParameters.getTitle());
Assert.assertEquals(groupId, sqlParameters.getGroupId()); Assertions.assertEquals(groupId, sqlParameters.getGroupId());
String sqlResult = "[{\"id\":6,\"test1\":\"6\"},{\"id\":70002,\"test1\":\"+1\"}]"; String sqlResult = "[{\"id\":6,\"test1\":\"6\"},{\"id\":70002,\"test1\":\"+1\"}]";
String sqlResult1 = "[{\"id\":6,\"test1\":\"6\"}]"; String sqlResult1 = "[{\"id\":6,\"test1\":\"6\"}]";
sqlParameters.setLocalParams(properties); sqlParameters.setLocalParams(properties);
sqlParameters.varPool = new ArrayList<>(); sqlParameters.varPool = new ArrayList<>();
sqlParameters.dealOutParam(sqlResult1); sqlParameters.dealOutParam(sqlResult1);
assertNotNull(sqlParameters.getVarPool().get(0)); Assertions.assertNotNull(sqlParameters.getVarPool().get(0));
property.setType(DataType.LIST); property.setType(DataType.LIST);
properties.clear(); properties.clear();
properties.add(property); properties.add(property);
sqlParameters.setLocalParams(properties); sqlParameters.setLocalParams(properties);
sqlParameters.dealOutParam(sqlResult); sqlParameters.dealOutParam(sqlResult);
assertNotNull(sqlParameters.getVarPool().get(0)); Assertions.assertNotNull(sqlParameters.getVarPool().get(0));
} }
} }

14
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/resource/AbstractResourceParametersTest.java

@ -22,17 +22,19 @@ import org.apache.dolphinscheduler.plugin.task.api.parameters.SqlParameters;
import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.enums.DbType;
import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class AbstractResourceParametersTest { public class AbstractResourceParametersTest {
@Test @Test
public void testDataSource() { public void testDataSource() {
TaskExecutionContext taskExecutionContext = new TaskExecutionContext(); TaskExecutionContext taskExecutionContext = new TaskExecutionContext();
String taskParam = "{\"localParams\":[],\"resourceList\":[],\"type\":\"MYSQL\",\"datasource\":\"1\",\"sql\":\"select now();\",\"sqlType\":\"0\",\"preStatements\":[],\"postStatements\":[],\"conditionResult\":\"null\",\"dependence\":\"null\",\"switchResult\":\"null\",\"waitStartTimeout\":null}"; String taskParam =
"{\"localParams\":[],\"resourceList\":[],\"type\":\"MYSQL\",\"datasource\":\"1\",\"sql\":\"select now();\",\"sqlType\":\"0\",\"preStatements\":[],\"postStatements\":[],\"conditionResult\":\"null\",\"dependence\":\"null\",\"switchResult\":\"null\",\"waitStartTimeout\":null}";
ResourceParametersHelper resourceParametersHelper = JSONUtils.parseObject(taskParam, SqlParameters.class).getResources(); ResourceParametersHelper resourceParametersHelper =
JSONUtils.parseObject(taskParam, SqlParameters.class).getResources();
resourceParametersHelper.getResourceMap().forEach((type, map) -> { resourceParametersHelper.getResourceMap().forEach((type, map) -> {
map.forEach((code, parameters) -> { map.forEach((code, parameters) -> {
@ -49,8 +51,6 @@ public class AbstractResourceParametersTest {
taskExecutionContext = JSONUtils.parseObject(json, TaskExecutionContext.class); taskExecutionContext = JSONUtils.parseObject(json, TaskExecutionContext.class);
Assert.assertNotNull(taskExecutionContext); Assertions.assertNotNull(taskExecutionContext);
} }
} }

21
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtilsTest.java

@ -24,8 +24,8 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -34,19 +34,22 @@ public class ParameterUtilsTest {
@Test @Test
public void expandListParameter() { public void expandListParameter() {
Map<Integer, Property> params = new HashMap<>(); Map<Integer, Property> params = new HashMap<>();
params.put(1, new Property(null, null, DataType.LIST, JSONUtils.toJsonString(Lists.newArrayList("c1", "c2", "c3")))); params.put(1,
new Property(null, null, DataType.LIST, JSONUtils.toJsonString(Lists.newArrayList("c1", "c2", "c3"))));
params.put(2, new Property(null, null, DataType.DATE, "2020-06-30")); params.put(2, new Property(null, null, DataType.DATE, "2020-06-30"));
params.put(3, new Property(null, null, DataType.LIST, JSONUtils.toJsonString(Lists.newArrayList(3.1415, 2.44, 3.44)))); params.put(3, new Property(null, null, DataType.LIST,
String sql = ParameterUtils.expandListParameter(params, "select * from test where col1 in (?) and date=? and col2 in (?)"); JSONUtils.toJsonString(Lists.newArrayList(3.1415, 2.44, 3.44))));
Assert.assertEquals("select * from test where col1 in (?,?,?) and date=? and col2 in (?,?,?)", sql); String sql = ParameterUtils.expandListParameter(params,
Assert.assertEquals(7, params.size()); "select * from test where col1 in (?) and date=? and col2 in (?)");
Assertions.assertEquals("select * from test where col1 in (?,?,?) and date=? and col2 in (?,?,?)", sql);
Assertions.assertEquals(7, params.size());
Map<Integer, Property> params2 = new HashMap<>(); Map<Integer, Property> params2 = new HashMap<>();
params2.put(1, new Property(null, null, DataType.LIST, JSONUtils.toJsonString(Lists.newArrayList("c1")))); params2.put(1, new Property(null, null, DataType.LIST, JSONUtils.toJsonString(Lists.newArrayList("c1"))));
params2.put(2, new Property(null, null, DataType.DATE, "2020-06-30")); params2.put(2, new Property(null, null, DataType.DATE, "2020-06-30"));
String sql2 = ParameterUtils.expandListParameter(params2, "select * from test where col1 in (?) and date=?"); String sql2 = ParameterUtils.expandListParameter(params2, "select * from test where col1 in (?) and date=?");
Assert.assertEquals("select * from test where col1 in (?) and date=?", sql2); Assertions.assertEquals("select * from test where col1 in (?) and date=?", sql2);
Assert.assertEquals(2, params2.size()); Assertions.assertEquals(2, params2.size());
} }
} }

38
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java

@ -23,11 +23,11 @@ import org.apache.dolphinscheduler.spi.utils.DateUtils;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TimePlaceholderUtilsTest { public class TimePlaceholderUtilsTest {
Date date = DateUtils.parse("2022-08-26 00:00:00", "yyyy-MM-dd HH:mm:ss"); Date date = DateUtils.parse("2022-08-26 00:00:00", "yyyy-MM-dd HH:mm:ss");
Map<String, String> timeParams = BusinessTimeUtils.getBusinessTime(CommandType.COMPLEMENT_DATA, date); Map<String, String> timeParams = BusinessTimeUtils.getBusinessTime(CommandType.COMPLEMENT_DATA, date);
@ -38,10 +38,10 @@ public class TimePlaceholderUtilsTest {
String thisDate = "$[this_day(yyyyMMdd)]"; String thisDate = "$[this_day(yyyyMMdd)]";
String thisDayTime = ParameterUtils.convertParameterPlaceholders(thisDay, timeParams); String thisDayTime = ParameterUtils.convertParameterPlaceholders(thisDay, timeParams);
Assert.assertEquals(thisDayTime, "2022-08-26"); Assertions.assertEquals(thisDayTime, "2022-08-26");
String thisDateTime = ParameterUtils.convertParameterPlaceholders(thisDate, timeParams); String thisDateTime = ParameterUtils.convertParameterPlaceholders(thisDate, timeParams);
Assert.assertEquals(thisDateTime, "20220826"); Assertions.assertEquals(thisDateTime, "20220826");
} }
@Test @Test
@ -49,10 +49,10 @@ public class TimePlaceholderUtilsTest {
String lastDay = "$[last_day(yyyy-MM-dd)]"; String lastDay = "$[last_day(yyyy-MM-dd)]";
String lastDate = "$[last_day(yyyyMMdd)]"; String lastDate = "$[last_day(yyyyMMdd)]";
String lastDayTime = ParameterUtils.convertParameterPlaceholders(lastDay, timeParams); String lastDayTime = ParameterUtils.convertParameterPlaceholders(lastDay, timeParams);
Assert.assertEquals(lastDayTime, "2022-08-25"); Assertions.assertEquals(lastDayTime, "2022-08-25");
String lastDateTime = ParameterUtils.convertParameterPlaceholders(lastDate, timeParams); String lastDateTime = ParameterUtils.convertParameterPlaceholders(lastDate, timeParams);
Assert.assertEquals(lastDateTime, "20220825"); Assertions.assertEquals(lastDateTime, "20220825");
} }
@Test @Test
@ -62,20 +62,20 @@ public class TimePlaceholderUtilsTest {
String yearWeekDay = "$[year_week(yyyyMMdd)]"; String yearWeekDay = "$[year_week(yyyyMMdd)]";
String yearWeekDateTime = ParameterUtils.convertParameterPlaceholders(yearWeekDate, timeParams); String yearWeekDateTime = ParameterUtils.convertParameterPlaceholders(yearWeekDate, timeParams);
Assert.assertEquals(yearWeekDateTime, "2022-34"); Assertions.assertEquals(yearWeekDateTime, "2022-34");
String yearWeekDayTime = ParameterUtils.convertParameterPlaceholders(yearWeekDay, timeParams); String yearWeekDayTime = ParameterUtils.convertParameterPlaceholders(yearWeekDay, timeParams);
Assert.assertEquals(yearWeekDayTime, "202234"); Assertions.assertEquals(yearWeekDayTime, "202234");
// Start the week on Friday // Start the week on Friday
String yearWeekDateAny = "$[year_week(yyyy-MM-dd,5)]"; String yearWeekDateAny = "$[year_week(yyyy-MM-dd,5)]";
String yearWeekDayAny = "$[year_week(yyyyMMdd,5)]"; String yearWeekDayAny = "$[year_week(yyyyMMdd,5)]";
String yearWeekDateAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDateAny, timeParams); String yearWeekDateAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDateAny, timeParams);
Assert.assertEquals(yearWeekDateAnyTime, "2022-35"); Assertions.assertEquals(yearWeekDateAnyTime, "2022-35");
String yearWeekDayAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDayAny, timeParams); String yearWeekDayAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDayAny, timeParams);
Assert.assertEquals(yearWeekDayAnyTime, "202235"); Assertions.assertEquals(yearWeekDayAnyTime, "202235");
} }
@Test @Test
@ -84,10 +84,10 @@ public class TimePlaceholderUtilsTest {
String monthFirstDay = "$[month_first_day(yyyyMMdd,-1)]"; String monthFirstDay = "$[month_first_day(yyyyMMdd,-1)]";
String monthFirstDateTime = ParameterUtils.convertParameterPlaceholders(monthFirstDate, timeParams); String monthFirstDateTime = ParameterUtils.convertParameterPlaceholders(monthFirstDate, timeParams);
Assert.assertEquals(monthFirstDateTime, "2022-07-01"); Assertions.assertEquals(monthFirstDateTime, "2022-07-01");
String monthFirstDayTime = ParameterUtils.convertParameterPlaceholders(monthFirstDay, timeParams); String monthFirstDayTime = ParameterUtils.convertParameterPlaceholders(monthFirstDay, timeParams);
Assert.assertEquals(monthFirstDayTime, "20220701"); Assertions.assertEquals(monthFirstDayTime, "20220701");
} }
@Test @Test
@ -96,10 +96,10 @@ public class TimePlaceholderUtilsTest {
String monthLastDay = "$[month_last_day(yyyyMMdd,-1)]"; String monthLastDay = "$[month_last_day(yyyyMMdd,-1)]";
String monthLastDateTime = ParameterUtils.convertParameterPlaceholders(monthLastDate, timeParams); String monthLastDateTime = ParameterUtils.convertParameterPlaceholders(monthLastDate, timeParams);
Assert.assertEquals(monthLastDateTime, "2022-07-31"); Assertions.assertEquals(monthLastDateTime, "2022-07-31");
String monthLastDayTime = ParameterUtils.convertParameterPlaceholders(monthLastDay, timeParams); String monthLastDayTime = ParameterUtils.convertParameterPlaceholders(monthLastDay, timeParams);
Assert.assertEquals(monthLastDayTime, "20220731"); Assertions.assertEquals(monthLastDayTime, "20220731");
} }
@Test @Test
@ -108,10 +108,10 @@ public class TimePlaceholderUtilsTest {
String weekFirstDay = "$[week_first_day(yyyyMMdd,0)]"; String weekFirstDay = "$[week_first_day(yyyyMMdd,0)]";
String weekFirstDateTime = ParameterUtils.convertParameterPlaceholders(weekFirstDate, timeParams); String weekFirstDateTime = ParameterUtils.convertParameterPlaceholders(weekFirstDate, timeParams);
Assert.assertEquals(weekFirstDateTime, "2022-08-22"); Assertions.assertEquals(weekFirstDateTime, "2022-08-22");
String weekFirstDayTime = ParameterUtils.convertParameterPlaceholders(weekFirstDay, timeParams); String weekFirstDayTime = ParameterUtils.convertParameterPlaceholders(weekFirstDay, timeParams);
Assert.assertEquals(weekFirstDayTime, "20220822"); Assertions.assertEquals(weekFirstDayTime, "20220822");
} }
@Test @Test
@ -120,9 +120,9 @@ public class TimePlaceholderUtilsTest {
String weekLastDay = "$[week_last_day(yyyyMMdd,0)]"; String weekLastDay = "$[week_last_day(yyyyMMdd,0)]";
String weekLastDateTime = ParameterUtils.convertParameterPlaceholders(weekLastDate, timeParams); String weekLastDateTime = ParameterUtils.convertParameterPlaceholders(weekLastDate, timeParams);
Assert.assertEquals(weekLastDateTime,"2022-08-28"); Assertions.assertEquals(weekLastDateTime, "2022-08-28");
String weekLastDayTime = ParameterUtils.convertParameterPlaceholders(weekLastDay, timeParams); String weekLastDayTime = ParameterUtils.convertParameterPlaceholders(weekLastDay, timeParams);
Assert.assertEquals(weekLastDayTime,"20220828"); Assertions.assertEquals(weekLastDayTime, "20220828");
} }
} }

165
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/DependentUtilsTest.java

@ -26,14 +26,15 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
public class DependentUtilsTest { public class DependentUtilsTest {
private static final Logger logger = LoggerFactory.getLogger(DependentUtilsTest.class); private static final Logger logger = LoggerFactory.getLogger(DependentUtilsTest.class);
@Test @Test
@ -44,33 +45,33 @@ public class DependentUtilsTest {
dependResultList.add(DependResult.FAILED); dependResultList.add(DependResult.FAILED);
dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS);
DependResult result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); DependResult result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.FAILED); Assertions.assertEquals(result, DependResult.FAILED);
// waiting // waiting
dependResultList = new ArrayList<>(); dependResultList = new ArrayList<>();
dependResultList.add(DependResult.WAITING); dependResultList.add(DependResult.WAITING);
dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS);
result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.WAITING); Assertions.assertEquals(result, DependResult.WAITING);
// success // success
dependResultList = new ArrayList<>(); dependResultList = new ArrayList<>();
dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS);
dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS);
result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.SUCCESS); Assertions.assertEquals(result, DependResult.SUCCESS);
// one success // one success
dependResultList = new ArrayList<>(); dependResultList = new ArrayList<>();
dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS);
result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.SUCCESS); Assertions.assertEquals(result, DependResult.SUCCESS);
// one failed // one failed
dependResultList = new ArrayList<>(); dependResultList = new ArrayList<>();
dependResultList.add(DependResult.FAILED); dependResultList.add(DependResult.FAILED);
result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.FAILED); Assertions.assertEquals(result, DependResult.FAILED);
// or success // or success
dependentRelation = DependentRelation.OR; dependentRelation = DependentRelation.OR;
@ -78,33 +79,33 @@ public class DependentUtilsTest {
dependResultList.add(DependResult.FAILED); dependResultList.add(DependResult.FAILED);
dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS);
result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.SUCCESS); Assertions.assertEquals(result, DependResult.SUCCESS);
// waiting // waiting
dependResultList = new ArrayList<>(); dependResultList = new ArrayList<>();
dependResultList.add(DependResult.WAITING); dependResultList.add(DependResult.WAITING);
dependResultList.add(DependResult.FAILED); dependResultList.add(DependResult.FAILED);
result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.WAITING); Assertions.assertEquals(result, DependResult.WAITING);
// success // success
dependResultList = new ArrayList<>(); dependResultList = new ArrayList<>();
dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS);
dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS);
result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.SUCCESS); Assertions.assertEquals(result, DependResult.SUCCESS);
// one success // one success
dependResultList = new ArrayList<>(); dependResultList = new ArrayList<>();
dependResultList.add(DependResult.SUCCESS); dependResultList.add(DependResult.SUCCESS);
result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.SUCCESS); Assertions.assertEquals(result, DependResult.SUCCESS);
// one failed // one failed
dependResultList = new ArrayList<>(); dependResultList = new ArrayList<>();
dependResultList.add(DependResult.FAILED); dependResultList.add(DependResult.FAILED);
result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList); result = DependentUtils.getDependResultForRelation(dependentRelation, dependResultList);
Assert.assertEquals(result, DependResult.FAILED); Assertions.assertEquals(result, DependResult.FAILED);
} }
@Test @Test
@ -123,7 +124,7 @@ public class DependentUtilsTest {
DateUtils.getEndOfDay(day2)); DateUtils.getEndOfDay(day2));
String dateValue = "last1Days"; String dateValue = "last1Days";
List<DateInterval> dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); List<DateInterval> dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue);
Assert.assertEquals(dateIntervals.get(0), di1); Assertions.assertEquals(dateIntervals.get(0), di1);
dateValue = "last2Days"; dateValue = "last2Days";
dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue);
@ -131,142 +132,144 @@ public class DependentUtilsTest {
logger.info(dateInterval.getStartTime().toString() + " == " + dateInterval.getEndTime().toString()); logger.info(dateInterval.getStartTime().toString() + " == " + dateInterval.getEndTime().toString());
} }
Assert.assertEquals(dateIntervals.get(1), di1); Assertions.assertEquals(dateIntervals.get(1), di1);
Assert.assertEquals(dateIntervals.get(0), di2); Assertions.assertEquals(dateIntervals.get(0), di2);
dateValue = "today"; dateValue = "today";
dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue);
Assert.assertEquals(dateIntervals.get(0), diCur); Assertions.assertEquals(dateIntervals.get(0), diCur);
dateValue = "thisWeek"; dateValue = "thisWeek";
Date firstWeekDay = DateUtils.getMonday(curDay); Date firstWeekDay = DateUtils.getMonday(curDay);
dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue);
DateInterval weekHead = new DateInterval(DateUtils.getStartOfDay(firstWeekDay), DateUtils.getEndOfDay(firstWeekDay)); DateInterval weekHead =
new DateInterval(DateUtils.getStartOfDay(firstWeekDay), DateUtils.getEndOfDay(firstWeekDay));
DateInterval weekThis = new DateInterval(DateUtils.getStartOfDay(curDay), DateUtils.getEndOfDay(curDay)); DateInterval weekThis = new DateInterval(DateUtils.getStartOfDay(curDay), DateUtils.getEndOfDay(curDay));
Assert.assertEquals(dateIntervals.get(0), weekHead); Assertions.assertEquals(dateIntervals.get(0), weekHead);
Assert.assertEquals(dateIntervals.get(dateIntervals.size() - 1), weekThis); Assertions.assertEquals(dateIntervals.get(dateIntervals.size() - 1), weekThis);
dateValue = "thisMonth"; dateValue = "thisMonth";
Date firstMonthDay = DateUtils.getFirstDayOfMonth(curDay); Date firstMonthDay = DateUtils.getFirstDayOfMonth(curDay);
dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue);
DateInterval monthHead = new DateInterval(DateUtils.getStartOfDay(firstMonthDay), DateUtils.getEndOfDay(firstMonthDay)); DateInterval monthHead =
new DateInterval(DateUtils.getStartOfDay(firstMonthDay), DateUtils.getEndOfDay(firstMonthDay));
DateInterval monthThis = new DateInterval(DateUtils.getStartOfDay(curDay), DateUtils.getEndOfDay(curDay)); DateInterval monthThis = new DateInterval(DateUtils.getStartOfDay(curDay), DateUtils.getEndOfDay(curDay));
Assert.assertEquals(dateIntervals.get(0), monthHead); Assertions.assertEquals(dateIntervals.get(0), monthHead);
Assert.assertEquals(dateIntervals.get(dateIntervals.size() - 1), monthThis); Assertions.assertEquals(dateIntervals.get(dateIntervals.size() - 1), monthThis);
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-04 10:00:00"), "last1Hour"); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-04 10:00:00"), "last1Hour");
DateInterval expect = new DateInterval(DateUtils.stringToDate("2019-02-04 09:00:00"), DateInterval expect = new DateInterval(DateUtils.stringToDate("2019-02-04 09:00:00"),
DateUtils.getEndOfHour(DateUtils.stringToDate("2019-02-04 09:00:00"))); DateUtils.getEndOfHour(DateUtils.stringToDate("2019-02-04 09:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-04 10:00:00"), "last2Hours"); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-04 10:00:00"), "last2Hours");
expect = new DateInterval(DateUtils.stringToDate("2019-02-04 08:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-02-04 08:00:00"),
DateUtils.getEndOfHour(DateUtils.stringToDate("2019-02-04 08:00:00"))); DateUtils.getEndOfHour(DateUtils.stringToDate("2019-02-04 08:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-04 10:00:00"), "last3Hours"); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-04 10:00:00"), "last3Hours");
expect = new DateInterval(DateUtils.stringToDate("2019-02-04 07:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-02-04 07:00:00"),
DateUtils.getEndOfHour(DateUtils.stringToDate("2019-02-04 07:00:00"))); DateUtils.getEndOfHour(DateUtils.stringToDate("2019-02-04 07:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
dateValue = "last3Days"; dateValue = "last3Days";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-02-07 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-02-07 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-07 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-07 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
dateValue = "last7Days"; dateValue = "last7Days";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-02-03 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-02-03 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-03 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-03 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
dateValue = "lastWeek"; dateValue = "lastWeek";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-01-28 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-01-28 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-28 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-28 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
expect = new DateInterval(DateUtils.stringToDate("2019-02-03 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-02-03 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-03 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-03 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(6)); Assertions.assertEquals(expect, dateIntervals.get(6));
Assert.assertEquals(7, dateIntervals.size()); Assertions.assertEquals(7, dateIntervals.size());
dateValue = "lastMonday"; dateValue = "lastMonday";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-01-28 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-01-28 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-28 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-28 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
dateValue = "lastTuesday"; dateValue = "lastTuesday";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-01-29 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-01-29 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-29 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-29 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
dateValue = "lastWednesday"; dateValue = "lastWednesday";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-01-30 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-01-30 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-30 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-30 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
dateValue = "lastThursday"; dateValue = "lastThursday";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-01-31 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-01-31 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-31 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-31 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
dateValue = "lastFriday"; dateValue = "lastFriday";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-02-01 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-02-01 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-01 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-01 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
dateValue = "lastSaturday"; dateValue = "lastSaturday";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-02-02 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-02-02 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-02 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-02 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
dateValue = "lastSunday"; dateValue = "lastSunday";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-02-03 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-02-03 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-03 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-02-03 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
dateValue = "lastMonth"; dateValue = "lastMonth";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-01-01 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-01-01 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-01 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-01 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
expect = new DateInterval(DateUtils.stringToDate("2019-01-31 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-01-31 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-31 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-31 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(30)); Assertions.assertEquals(expect, dateIntervals.get(30));
Assert.assertEquals(31, dateIntervals.size()); Assertions.assertEquals(31, dateIntervals.size());
dateValue = "lastMonthBegin"; dateValue = "lastMonthBegin";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-01-01 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-01-01 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-01 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-01 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
dateValue = "lastMonthEnd"; dateValue = "lastMonthEnd";
dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue); dateIntervals = DependentUtils.getDateIntervalList(DateUtils.stringToDate("2019-02-10 07:00:00"), dateValue);
expect = new DateInterval(DateUtils.stringToDate("2019-01-31 00:00:00"), expect = new DateInterval(DateUtils.stringToDate("2019-01-31 00:00:00"),
DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-31 00:00:00"))); DateUtils.getEndOfDay(DateUtils.stringToDate("2019-01-31 00:00:00")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
} }
@Test @Test
@ -296,26 +299,26 @@ public class DependentUtilsTest {
DateInterval di7 = new DateInterval(DateUtils.getStartOfDay(day7), DateInterval di7 = new DateInterval(DateUtils.getStartOfDay(day7),
DateUtils.getEndOfDay(day7)); DateUtils.getEndOfDay(day7));
List<DateInterval> dateIntervals = DependentDateUtils.getLastWeekInterval(curDay); List<DateInterval> dateIntervals = DependentDateUtils.getLastWeekInterval(curDay);
Assert.assertEquals(dateIntervals.size(), 7); Assertions.assertEquals(dateIntervals.size(), 7);
Assert.assertEquals(dateIntervals.get(0), di1); Assertions.assertEquals(dateIntervals.get(0), di1);
Assert.assertEquals(dateIntervals.get(1), di2); Assertions.assertEquals(dateIntervals.get(1), di2);
Assert.assertEquals(dateIntervals.get(2), di3); Assertions.assertEquals(dateIntervals.get(2), di3);
Assert.assertEquals(dateIntervals.get(3), di4); Assertions.assertEquals(dateIntervals.get(3), di4);
List<DateInterval> monday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 1); List<DateInterval> monday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 1);
Assert.assertEquals(monday.get(0), di1); Assertions.assertEquals(monday.get(0), di1);
List<DateInterval> tuesday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 2); List<DateInterval> tuesday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 2);
Assert.assertEquals(tuesday.get(0), di2); Assertions.assertEquals(tuesday.get(0), di2);
List<DateInterval> wednesday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 3); List<DateInterval> wednesday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 3);
Assert.assertEquals(wednesday.get(0), di3); Assertions.assertEquals(wednesday.get(0), di3);
List<DateInterval> thursday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 4); List<DateInterval> thursday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 4);
Assert.assertEquals(thursday.get(0), di4); Assertions.assertEquals(thursday.get(0), di4);
List<DateInterval> friday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 5); List<DateInterval> friday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 5);
Assert.assertEquals(friday.get(0), di5); Assertions.assertEquals(friday.get(0), di5);
List<DateInterval> saturday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 6); List<DateInterval> saturday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 6);
Assert.assertEquals(saturday.get(0), di6); Assertions.assertEquals(saturday.get(0), di6);
List<DateInterval> sunday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 7); List<DateInterval> sunday = DependentDateUtils.getLastWeekOneDayInterval(curDay, 7);
Assert.assertEquals(sunday.get(0), di7); Assertions.assertEquals(sunday.get(0), di7);
} }
@Test @Test
@ -333,14 +336,14 @@ public class DependentUtilsTest {
DateUtils.getEndOfHour(day3)); DateUtils.getEndOfHour(day3));
List<DateInterval> dateIntervals = DependentDateUtils.getLastHoursInterval(curDay, 1); List<DateInterval> dateIntervals = DependentDateUtils.getLastHoursInterval(curDay, 1);
Assert.assertEquals(dateIntervals.get(0), di1); Assertions.assertEquals(dateIntervals.get(0), di1);
dateIntervals = DependentDateUtils.getLastHoursInterval(curDay, 2); dateIntervals = DependentDateUtils.getLastHoursInterval(curDay, 2);
Assert.assertEquals(dateIntervals.get(1), di1); Assertions.assertEquals(dateIntervals.get(1), di1);
Assert.assertEquals(dateIntervals.get(0), di2); Assertions.assertEquals(dateIntervals.get(0), di2);
dateIntervals = DependentDateUtils.getLastHoursInterval(curDay, 3); dateIntervals = DependentDateUtils.getLastHoursInterval(curDay, 3);
Assert.assertEquals(dateIntervals.get(2), di1); Assertions.assertEquals(dateIntervals.get(2), di1);
Assert.assertEquals(dateIntervals.get(1), di2); Assertions.assertEquals(dateIntervals.get(1), di2);
Assert.assertEquals(dateIntervals.get(0), di3); Assertions.assertEquals(dateIntervals.get(0), di3);
} }
@ -352,10 +355,11 @@ public class DependentUtilsTest {
List<DateInterval> dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); List<DateInterval> dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue);
DateInterval expect = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 12:00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 12:59:59"))); DateInterval expect = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 12:00:00")),
DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 12:59:59")));
Assert.assertEquals(expect, dateIntervals.get(0)); Assertions.assertEquals(expect, dateIntervals.get(0));
Assert.assertEquals(1, dateIntervals.size()); Assertions.assertEquals(1, dateIntervals.size());
} }
@Test @Test
@ -371,17 +375,20 @@ public class DependentUtilsTest {
if (a < 10) { if (a < 10) {
i = "0" + i; i = "0" + i;
} }
DateInterval dateInterval = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":00:00")), DateInterval dateInterval =
new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":00:00")),
DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":59:59"))); DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":59:59")));
expect.add(dateInterval); expect.add(dateInterval);
} }
DateInterval dateInterval = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 00:00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 00:59:59"))); DateInterval dateInterval =
new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 00:00:00")),
DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 00:59:59")));
expect.add(dateInterval); expect.add(dateInterval);
Assert.assertEquals(24, dateIntervals.size()); Assertions.assertEquals(24, dateIntervals.size());
for (int i = 0; i < expect.size(); i++) { for (int i = 0; i < expect.size(); i++) {
Assert.assertEquals(expect.get(i), dateIntervals.get(i)); Assertions.assertEquals(expect.get(i), dateIntervals.get(i));
} }
} }
@ -398,9 +405,9 @@ public class DependentUtilsTest {
List<DateInterval> dateIntervals = DependentDateUtils.getLastMonthInterval(curDay); List<DateInterval> dateIntervals = DependentDateUtils.getLastMonthInterval(curDay);
Assert.assertEquals(dateIntervals.size(), 31); Assertions.assertEquals(dateIntervals.size(), 31);
Assert.assertEquals(dateIntervals.get(0), di1); Assertions.assertEquals(dateIntervals.get(0), di1);
Assert.assertEquals(dateIntervals.get(30), di2); Assertions.assertEquals(dateIntervals.get(30), di2);
} }
} }

6
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JdbcUrlParserTest.java

@ -19,8 +19,8 @@ package org.apache.dolphinscheduler.plugin.task.api.utils;
import org.apache.dolphinscheduler.plugin.task.api.model.JdbcInfo; import org.apache.dolphinscheduler.plugin.task.api.model.JdbcInfo;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* JdbcUrlParserTest * JdbcUrlParserTest
@ -38,7 +38,7 @@ public class JdbcUrlParserTest {
+ "driverName='mysql', database='dolphinscheduler', " + "driverName='mysql', database='dolphinscheduler', "
+ "params='useUnicode=true&characterEncoding=UTF-8', " + "params='useUnicode=true&characterEncoding=UTF-8', "
+ "address='jdbc:mysql://localhost:3306'}"; + "address='jdbc:mysql://localhost:3306'}";
Assert.assertEquals(expected,jdbcInfoStr); Assertions.assertEquals(expected, jdbcInfoStr);
} }
} }
} }

10
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/JsonPathUtilsTest.java

@ -19,8 +19,8 @@ package org.apache.dolphinscheduler.plugin.task.api.utils;
import java.util.Optional; import java.util.Optional;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class JsonPathUtilsTest { public class JsonPathUtilsTest {
@ -28,13 +28,13 @@ public class JsonPathUtilsTest {
public void read() { public void read() {
String json = "{\"taskInstanceId\":\"123\",\"taskInstanceFinished\":true}"; String json = "{\"taskInstanceId\":\"123\",\"taskInstanceFinished\":true}";
Optional<Boolean> optionalBoolean = JsonPathUtils.read(json, "$.taskInstanceFinished"); Optional<Boolean> optionalBoolean = JsonPathUtils.read(json, "$.taskInstanceFinished");
Assert.assertTrue(optionalBoolean.get()); Assertions.assertTrue(optionalBoolean.get());
} }
@Test @Test
public void exist() { public void exist() {
String json = "{\"taskInstanceId\":\"123\",\"taskInstanceFinished\":true}"; String json = "{\"taskInstanceId\":\"123\",\"taskInstanceFinished\":true}";
Assert.assertTrue(JsonPathUtils.exist(json, "$.[?(@.taskInstanceFinished == true)]")); Assertions.assertTrue(JsonPathUtils.exist(json, "$.[?(@.taskInstanceFinished == true)]"));
Assert.assertFalse(JsonPathUtils.exist(json, "$.[?(@.taskInstanceFinished == false)]")); Assertions.assertFalse(JsonPathUtils.exist(json, "$.[?(@.taskInstanceFinished == false)]"));
} }
} }

6
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/LogUtilsTest.java

@ -19,8 +19,8 @@ package org.apache.dolphinscheduler.plugin.task.api.utils;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -32,6 +32,6 @@ public class LogUtilsTest {
@Test @Test
public void getAppIdsFromLogFile() { public void getAppIdsFromLogFile() {
List<String> appIds = LogUtils.getAppIdsFromLogFile(APP_ID_FILE); List<String> appIds = LogUtils.getAppIdsFromLogFile(APP_ID_FILE);
Assert.assertEquals(Lists.newArrayList("application_1548381669007_1234"), appIds); Assertions.assertEquals(Lists.newArrayList("application_1548381669007_1234"), appIds);
} }
} }

15
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java

@ -19,21 +19,24 @@ package org.apache.dolphinscheduler.plugin.task.api.utils;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class RetryUtilsTest { public class RetryUtilsTest {
@Test(expected = RuntimeException.class) @Test
public void retryFunction() { public void retryFunction() {
Boolean retrySuccess = RetryUtils.retryFunction(() -> true); Boolean retrySuccess = RetryUtils.retryFunction(() -> true);
Assert.assertTrue(retrySuccess); Assertions.assertTrue(retrySuccess);
Assertions.assertThrows(RuntimeException.class, () -> {
RetryUtils.retryFunction((Supplier<Boolean>) () -> { RetryUtils.retryFunction((Supplier<Boolean>) () -> {
throw new RuntimeException("Test failed function"); throw new RuntimeException("Test failed function");
}); });
// should throw runtime exception // make sure RuntimeException thrown
Assert.fail(); Assertions.fail();
});
} }
} }

14
dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunConstantsTest.java

@ -17,9 +17,9 @@
package org.apache.dolphinscheduler.plugin.task.chunjun; package org.apache.dolphinscheduler.plugin.task.chunjun;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ChunJunConstantsTest { public class ChunJunConstantsTest {
@ -29,7 +29,7 @@ public class ChunJunConstantsTest {
private String hadoopConfDir; private String hadoopConfDir;
@Before @BeforeEach
public void setUp() { public void setUp() {
flinkConfDir = "${FLINK_HOME}/conf"; flinkConfDir = "${FLINK_HOME}/conf";
flinkLibDir = "${FLINK_HOME}/lib"; flinkLibDir = "${FLINK_HOME}/lib";
@ -38,9 +38,9 @@ public class ChunJunConstantsTest {
@Test @Test
public void testEqualsString() { public void testEqualsString() {
Assert.assertEquals(ChunJunConstants.FLINK_CONF_DIR, flinkConfDir); Assertions.assertEquals(ChunJunConstants.FLINK_CONF_DIR, flinkConfDir);
Assert.assertEquals(ChunJunConstants.FLINK_LIB_DIR, flinkLibDir); Assertions.assertEquals(ChunJunConstants.FLINK_LIB_DIR, flinkLibDir);
Assert.assertEquals(ChunJunConstants.HADOOP_CONF_DIR, hadoopConfDir); Assertions.assertEquals(ChunJunConstants.HADOOP_CONF_DIR, hadoopConfDir);
} }
} }

16
dolphinscheduler-task-plugin/dolphinscheduler-task-chunjun/src/test/java/org/apache/dolphinscheduler/plugin/task/chunjun/ChunJunParametersTest.java

@ -17,15 +17,15 @@
package org.apache.dolphinscheduler.plugin.task.chunjun; package org.apache.dolphinscheduler.plugin.task.chunjun;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ChunJunParametersTest { public class ChunJunParametersTest {
private ChunJunParameters chunJunParameters = new ChunJunParameters(); private ChunJunParameters chunJunParameters = new ChunJunParameters();
@Before @BeforeEach
public void setUp() { public void setUp() {
chunJunParameters.setCustomConfig(0); chunJunParameters.setCustomConfig(0);
chunJunParameters.setDataSource(1); chunJunParameters.setDataSource(1);
@ -58,21 +58,21 @@ public class ChunJunParametersTest {
+ "deployMode=local" + "deployMode=local"
+ "}"; + "}";
Assert.assertNotEquals(expected, chunJunParameters.toString()); Assertions.assertNotEquals(expected, chunJunParameters.toString());
} }
@Test @Test
public void testCheckParameters() { public void testCheckParameters() {
Assert.assertFalse(chunJunParameters.checkParameters()); Assertions.assertFalse(chunJunParameters.checkParameters());
} }
@Test @Test
public void testGetResourceFilesList() { public void testGetResourceFilesList() {
Assert.assertNotNull(chunJunParameters.getResourceFilesList()); Assertions.assertNotNull(chunJunParameters.getResourceFilesList());
} }
@Test @Test
public void testGetResources() { public void testGetResources() {
Assert.assertNotNull(chunJunParameters.getResources()); Assertions.assertNotNull(chunJunParameters.getResources());
} }
} }

17
dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityParameterTest.java

@ -33,9 +33,9 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
@ -48,7 +48,7 @@ public class DataQualityParameterTest {
private DataQualityParameters dataQualityParameters = null; private DataQualityParameters dataQualityParameters = null;
@Before @BeforeEach
public void before() { public void before() {
dataQualityParameters = new DataQualityParameters(); dataQualityParameters = new DataQualityParameters();
dataQualityParameters.setRuleId(1); dataQualityParameters.setRuleId(1);
@ -75,7 +75,7 @@ public class DataQualityParameterTest {
dataQualityParameters.setRuleInputParameter(inputParameterValue); dataQualityParameters.setRuleInputParameter(inputParameterValue);
Assert.assertTrue(dataQualityParameters.checkParameters()); Assertions.assertTrue(dataQualityParameters.checkParameters());
} }
@Test @Test
@ -111,7 +111,8 @@ public class DataQualityParameterTest {
InputParam srcTable = InputParam.newBuilder("src_table", "源数据表") InputParam srcTable = InputParam.newBuilder("src_table", "源数据表")
.setProps(inputParamProps) .setProps(inputParamProps)
.addValidate(Validate.newBuilder().setType("string").setRequired(true).setTrigger(TriggerType.BLUR.getTriggerType()).build()) .addValidate(Validate.newBuilder().setType("string").setRequired(true)
.setTrigger(TriggerType.BLUR.getTriggerType()).build())
.build(); .build();
pluginParamsList.add(srcConnectorType); pluginParamsList.add(srcConnectorType);
@ -124,9 +125,9 @@ public class DataQualityParameterTest {
try { try {
result = mapper.writeValueAsString(pluginParamsList); result = mapper.writeValueAsString(pluginParamsList);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
Assert.fail(); Assertions.fail();
} }
Assert.assertEquals(formCreateJson,result); Assertions.assertEquals(formCreateJson, result);
} }
} }

12
dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityTaskTest.java

@ -38,8 +38,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* DataQualityTaskTest * DataQualityTaskTest
@ -96,7 +96,7 @@ public class DataQualityTaskTest {
+ "as unique_code,'table_count.total'AS statistics_name," + "as unique_code,'table_count.total'AS statistics_name,"
+ "table_count.total AS statistics_value,'2021-08-12 10:15:48' as data_time,'2021-08-12 10:15:48' as create_time," + "table_count.total AS statistics_value,'2021-08-12 10:15:48' as data_time,'2021-08-12 10:15:48' as create_time,"
+ "'2021-08-12 10:15:48' as update_time from table_count\"}}]}"; + "'2021-08-12 10:15:48' as update_time from table_count\"}}]}";
Assert.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); Assertions.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter()));
} }
private DataQualityTaskExecutionContext getSingleTableContext() { private DataQualityTaskExecutionContext getSingleTableContext() {
@ -540,7 +540,7 @@ public class DataQualityTaskTest {
+ "'2021-08-30 00:00:00' as data_time,'2021-08-30 00:00:00' as create_time,'2021-08-30 00:00:00' " + "'2021-08-30 00:00:00' as data_time,'2021-08-30 00:00:00' as create_time,'2021-08-30 00:00:00' "
+ "as update_time from test_person\"}}]}"; + "as update_time from test_person\"}}]}";
Assert.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); Assertions.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter()));
} }
@Test @Test
@ -819,7 +819,7 @@ public class DataQualityTaskTest {
+ "where c1>20 ) tmp2\"}}]}"; + "where c1>20 ) tmp2\"}}]}";
RuleManager ruleManager = new RuleManager(inputParameterValue, dataQualityTaskExecutionContext); RuleManager ruleManager = new RuleManager(inputParameterValue, dataQualityTaskExecutionContext);
Assert.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); Assertions.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter()));
} }
@Test @Test
@ -1171,6 +1171,6 @@ public class DataQualityTaskTest {
+ "\"config\":{\"path\":\"hdfs://localhost:8022/user/ods/data_quality_error_data/1_1_test\",\"input_table\":\"miss_items\"}}]}"; + "\"config\":{\"path\":\"hdfs://localhost:8022/user/ods/data_quality_error_data/1_1_test\",\"input_table\":\"miss_items\"}}]}";
RuleManager ruleManager = new RuleManager(inputParameterValue, dataQualityTaskExecutionContext); RuleManager ruleManager = new RuleManager(inputParameterValue, dataQualityTaskExecutionContext);
Assert.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter())); Assertions.assertEquals(expect, JSONUtils.toJsonString(ruleManager.generateDataQualityParameter()));
} }
} }

7
dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/utils/Md5UtilsTest.java

@ -17,14 +17,13 @@
package org.apache.dolphinscheduler.plugin.task.dq.utils; package org.apache.dolphinscheduler.plugin.task.dq.utils;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Test;
public class Md5UtilsTest { public class Md5UtilsTest {
@Test @Test
public void testGetMd5() { public void testGetMd5() {
assertEquals("jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=", Md5Utils.getMd5("123456", false)); Assertions.assertEquals("jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=", Md5Utils.getMd5("123456", false));
} }
} }

55
dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/test/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncTaskTest.java

@ -38,16 +38,16 @@ import software.amazon.awssdk.services.datasync.model.StartTaskExecutionResponse
import software.amazon.awssdk.services.datasync.model.TaskExecutionStatus; import software.amazon.awssdk.services.datasync.model.TaskExecutionStatus;
import software.amazon.awssdk.services.datasync.model.TaskStatus; import software.amazon.awssdk.services.datasync.model.TaskStatus;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockedStatic; import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class DatasyncTaskTest { public class DatasyncTaskTest {
private static final String mockExeArn = private static final String mockExeArn =
@ -63,7 +63,7 @@ public class DatasyncTaskTest {
@Mock @Mock
DataSyncClient client; DataSyncClient client;
MockedStatic<DatasyncHook> datasyncHookMockedStatic; MockedStatic<DatasyncHook> datasyncHookMockedStatic;
@Before @BeforeEach
public void before() throws IllegalAccessException { public void before() throws IllegalAccessException {
client = mock(DataSyncClient.class); client = mock(DataSyncClient.class);
datasyncHookMockedStatic = mockStatic(DatasyncHook.class); datasyncHookMockedStatic = mockStatic(DatasyncHook.class);
@ -129,22 +129,22 @@ public class DatasyncTaskTest {
DatasyncTask DatasyncTask = initTask(DatasyncParameters); DatasyncTask DatasyncTask = initTask(DatasyncParameters);
DatasyncParameters datasyncParameters = DatasyncTask.getParameters(); DatasyncParameters datasyncParameters = DatasyncTask.getParameters();
Assert.assertEquals("arn:aws:logs:ap-northeast-3:523202806641:log-group:/aws/datasync:*", Assertions.assertEquals("arn:aws:logs:ap-northeast-3:523202806641:log-group:/aws/datasync:*",
datasyncParameters.getCloudWatchLogGroupArn()); datasyncParameters.getCloudWatchLogGroupArn());
Assert.assertEquals("task001", datasyncParameters.getName()); Assertions.assertEquals("task001", datasyncParameters.getName());
Assert.assertEquals("arn:aws:datasync:ap-northeast-3:523202806641:location/loc-04ceafb4aaf7a1a0d", Assertions.assertEquals("arn:aws:datasync:ap-northeast-3:523202806641:location/loc-04ceafb4aaf7a1a0d",
datasyncParameters.getSourceLocationArn()); datasyncParameters.getSourceLocationArn());
Assert.assertEquals("arn:aws:datasync:ap-northeast-3:523202806641:location/loc-01cf61e102e58e365", Assertions.assertEquals("arn:aws:datasync:ap-northeast-3:523202806641:location/loc-01cf61e102e58e365",
datasyncParameters.getDestinationLocationArn()); datasyncParameters.getDestinationLocationArn());
Assert.assertEquals("inType1", datasyncParameters.getIncludes().get(0).getFilterType()); Assertions.assertEquals("inType1", datasyncParameters.getIncludes().get(0).getFilterType());
Assert.assertEquals("inValue1", datasyncParameters.getIncludes().get(0).getValue()); Assertions.assertEquals("inValue1", datasyncParameters.getIncludes().get(0).getValue());
Assert.assertEquals("exType1", datasyncParameters.getExcludes().get(0).getFilterType()); Assertions.assertEquals("exType1", datasyncParameters.getExcludes().get(0).getFilterType());
Assert.assertEquals("exValue1", datasyncParameters.getExcludes().get(0).getValue()); Assertions.assertEquals("exValue1", datasyncParameters.getExcludes().get(0).getValue());
Assert.assertEquals("tagKey1", datasyncParameters.getTags().get(0).getKey()); Assertions.assertEquals("tagKey1", datasyncParameters.getTags().get(0).getKey());
Assert.assertEquals("tagValue1", datasyncParameters.getTags().get(0).getValue()); Assertions.assertEquals("tagValue1", datasyncParameters.getTags().get(0).getValue());
Assert.assertEquals("* * * * * ?", datasyncParameters.getSchedule().getScheduleExpression()); Assertions.assertEquals("* * * * * ?", datasyncParameters.getSchedule().getScheduleExpression());
Assert.assertEquals("aTime", datasyncParameters.getOptions().getAtime()); Assertions.assertEquals("aTime", datasyncParameters.getOptions().getAtime());
Assert.assertEquals(Long.valueOf(10), datasyncParameters.getOptions().getBytesPerSecond()); Assertions.assertEquals(Long.valueOf(10), datasyncParameters.getOptions().getBytesPerSecond());
datasyncHookMockedStatic.close(); datasyncHookMockedStatic.close();
} }
@ -160,7 +160,7 @@ public class DatasyncTaskTest {
doReturn(true).when(hook).doubleCheckTaskStatus(any(), any()); doReturn(true).when(hook).doubleCheckTaskStatus(any(), any());
hook.createDatasyncTask(datasyncTask.getParameters()); hook.createDatasyncTask(datasyncTask.getParameters());
Assert.assertEquals(mockTaskArn, hook.getTaskArn()); Assertions.assertEquals(mockTaskArn, hook.getTaskArn());
datasyncHookMockedStatic.close(); datasyncHookMockedStatic.close();
} }
@ -175,7 +175,7 @@ public class DatasyncTaskTest {
when(response.taskExecutionArn()).thenReturn(mockExeArn); when(response.taskExecutionArn()).thenReturn(mockExeArn);
doReturn(true).when(hook).doubleCheckExecStatus(any(), any()); doReturn(true).when(hook).doubleCheckExecStatus(any(), any());
hook.startDatasyncTask(); hook.startDatasyncTask();
Assert.assertEquals(mockExeArn, hook.getTaskExecArn()); Assertions.assertEquals(mockExeArn, hook.getTaskExecArn());
datasyncHookMockedStatic.close(); datasyncHookMockedStatic.close();
} }
@ -187,7 +187,7 @@ public class DatasyncTaskTest {
SdkHttpResponse sdkMock = mock(SdkHttpResponse.class); SdkHttpResponse sdkMock = mock(SdkHttpResponse.class);
when(response.sdkHttpResponse()).thenReturn(sdkMock); when(response.sdkHttpResponse()).thenReturn(sdkMock);
when(sdkMock.isSuccessful()).thenReturn(true); when(sdkMock.isSuccessful()).thenReturn(true);
Assert.assertEquals(true, hook.cancelDatasyncTask()); Assertions.assertEquals(true, hook.cancelDatasyncTask());
datasyncHookMockedStatic.close(); datasyncHookMockedStatic.close();
} }
@ -195,10 +195,10 @@ public class DatasyncTaskTest {
public void testDescribeTask() { public void testDescribeTask() {
DatasyncHook hook = spy(new DatasyncHook()); DatasyncHook hook = spy(new DatasyncHook());
doReturn(null).when(hook).queryDatasyncTaskStatus(); doReturn(null).when(hook).queryDatasyncTaskStatus();
Assert.assertEquals(false, hook.doubleCheckTaskStatus(TaskStatus.AVAILABLE, DatasyncHook.taskFinishFlags)); Assertions.assertEquals(false, hook.doubleCheckTaskStatus(TaskStatus.AVAILABLE, DatasyncHook.taskFinishFlags));
doReturn(TaskStatus.AVAILABLE).when(hook).queryDatasyncTaskStatus(); doReturn(TaskStatus.AVAILABLE).when(hook).queryDatasyncTaskStatus();
Assert.assertEquals(true, hook.doubleCheckTaskStatus(TaskStatus.AVAILABLE, DatasyncHook.taskFinishFlags)); Assertions.assertEquals(true, hook.doubleCheckTaskStatus(TaskStatus.AVAILABLE, DatasyncHook.taskFinishFlags));
datasyncHookMockedStatic.close(); datasyncHookMockedStatic.close();
} }
@ -206,10 +206,11 @@ public class DatasyncTaskTest {
public void testDescribeTaskExec() { public void testDescribeTaskExec() {
DatasyncHook hook = spy(new DatasyncHook()); DatasyncHook hook = spy(new DatasyncHook());
doReturn(null).when(hook).queryDatasyncTaskExecStatus(); doReturn(null).when(hook).queryDatasyncTaskExecStatus();
Assert.assertEquals(false, hook.doubleCheckExecStatus(TaskExecutionStatus.SUCCESS, DatasyncHook.doneStatus)); Assertions.assertEquals(false,
hook.doubleCheckExecStatus(TaskExecutionStatus.SUCCESS, DatasyncHook.doneStatus));
doReturn(TaskExecutionStatus.SUCCESS).when(hook).queryDatasyncTaskExecStatus(); doReturn(TaskExecutionStatus.SUCCESS).when(hook).queryDatasyncTaskExecStatus();
Assert.assertEquals(true, hook.doubleCheckExecStatus(TaskExecutionStatus.SUCCESS, DatasyncHook.doneStatus)); Assertions.assertEquals(true, hook.doubleCheckExecStatus(TaskExecutionStatus.SUCCESS, DatasyncHook.doneStatus));
datasyncHookMockedStatic.close(); datasyncHookMockedStatic.close();
} }

11
dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxParametersTest.java

@ -18,12 +18,13 @@
package org.apache.dolphinscheduler.plugin.task.datax; package org.apache.dolphinscheduler.plugin.task.datax;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class DataxParametersTest { public class DataxParametersTest {
/** /**
@ -41,13 +42,13 @@ public class DataxParametersTest {
String actual = loadJvmEnvTest(dataxParameters); String actual = loadJvmEnvTest(dataxParameters);
String except = " --jvm=\"-Xms1G -Xmx1G\" "; String except = " --jvm=\"-Xms1G -Xmx1G\" ";
Assert.assertEquals(except,actual); Assertions.assertEquals(except, actual);
dataxParameters.setXms(13); dataxParameters.setXms(13);
dataxParameters.setXmx(14); dataxParameters.setXmx(14);
actual = loadJvmEnvTest(dataxParameters); actual = loadJvmEnvTest(dataxParameters);
except = " --jvm=\"-Xms13G -Xmx14G\" "; except = " --jvm=\"-Xms13G -Xmx14G\" ";
Assert.assertEquals(except,actual); Assertions.assertEquals(except, actual);
} }
@ -92,7 +93,7 @@ public class DataxParametersTest {
+ "resourceList=[{\"id\":2,\"resourceName\":\"/hdfs.keytab\",\"res\":null}]" + "resourceList=[{\"id\":2,\"resourceName\":\"/hdfs.keytab\",\"res\":null}]"
+ "}"; + "}";
Assert.assertEquals(expected,dataxParameters.toString()); Assertions.assertEquals(expected, dataxParameters.toString());
} }
public String loadJvmEnvTest(DataxParameters dataXParameters) { public String loadJvmEnvTest(DataxParameters dataXParameters) {

92
dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsHookTest.java

@ -23,15 +23,16 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.time.Duration;
import java.util.Arrays; import java.util.Arrays;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedStatic; import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import com.amazonaws.services.databasemigrationservice.AWSDatabaseMigrationService; import com.amazonaws.services.databasemigrationservice.AWSDatabaseMigrationService;
import com.amazonaws.services.databasemigrationservice.model.CreateReplicationTaskResult; import com.amazonaws.services.databasemigrationservice.model.CreateReplicationTaskResult;
@ -40,20 +41,21 @@ import com.amazonaws.services.databasemigrationservice.model.ReplicationTask;
import com.amazonaws.services.databasemigrationservice.model.ReplicationTaskStats; import com.amazonaws.services.databasemigrationservice.model.ReplicationTaskStats;
import com.amazonaws.services.databasemigrationservice.model.StartReplicationTaskResult; import com.amazonaws.services.databasemigrationservice.model.StartReplicationTaskResult;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class DmsHookTest { public class DmsHookTest {
final String replicationTaskArn = "arn:aws:dms:ap-southeast-1:123456789012:task:task"; final String replicationTaskArn = "arn:aws:dms:ap-southeast-1:123456789012:task:task";
AWSDatabaseMigrationService client; AWSDatabaseMigrationService client;
@Before @BeforeEach
public void before() { public void before() {
client = mock(AWSDatabaseMigrationService.class); client = mock(AWSDatabaseMigrationService.class);
} }
@Test(timeout = 60000) @Test
public void testCreateReplicationTask() throws Exception { public void testCreateReplicationTask() throws Exception {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) { try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
Assertions.assertTimeout(Duration.ofMillis(60000), () -> {
mockHook.when(DmsHook::createClient).thenReturn(client); mockHook.when(DmsHook::createClient).thenReturn(client);
DmsHook dmsHook = spy(new DmsHook()); DmsHook dmsHook = spy(new DmsHook());
@ -68,14 +70,16 @@ public class DmsHookTest {
when(createReplicationTaskResult.getReplicationTask()).thenReturn(replicationTask); when(createReplicationTaskResult.getReplicationTask()).thenReturn(replicationTask);
doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); doReturn(replicationTask).when(dmsHook).describeReplicationTasks();
Assert.assertTrue(dmsHook.createReplicationTask()); Assertions.assertTrue(dmsHook.createReplicationTask());
Assert.assertEquals(replicationTaskArn, dmsHook.getReplicationTaskArn()); Assertions.assertEquals(replicationTaskArn, dmsHook.getReplicationTaskArn());
Assert.assertEquals(taskIdentifier, dmsHook.getReplicationTaskIdentifier()); Assertions.assertEquals(taskIdentifier, dmsHook.getReplicationTaskIdentifier());
});
} }
} }
@Test(timeout = 60000) @Test
public void testStartReplicationTask() { public void testStartReplicationTask() {
Assertions.assertTimeout(Duration.ofMillis(60000), () -> {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) { try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
mockHook.when(DmsHook::createClient).thenReturn(client); mockHook.when(DmsHook::createClient).thenReturn(client);
@ -89,13 +93,15 @@ public class DmsHookTest {
when(startReplicationTaskResult.getReplicationTask()).thenReturn(replicationTask); when(startReplicationTaskResult.getReplicationTask()).thenReturn(replicationTask);
doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); doReturn(replicationTask).when(dmsHook).describeReplicationTasks();
Assert.assertTrue(dmsHook.startReplicationTask()); Assertions.assertTrue(dmsHook.startReplicationTask());
Assert.assertEquals(replicationTaskArn, dmsHook.getReplicationTaskArn()); Assertions.assertEquals(replicationTaskArn, dmsHook.getReplicationTaskArn());
} }
});
} }
@Test(timeout = 60000) @Test
public void testCheckFinishedReplicationTask() { public void testCheckFinishedReplicationTask() {
Assertions.assertTimeout(Duration.ofMillis(60000), () -> {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) { try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
mockHook.when(DmsHook::createClient).thenReturn(client); mockHook.when(DmsHook::createClient).thenReturn(client);
DmsHook dmsHook = spy(new DmsHook()); DmsHook dmsHook = spy(new DmsHook());
@ -106,15 +112,17 @@ public class DmsHookTest {
doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); doReturn(replicationTask).when(dmsHook).describeReplicationTasks();
when(replicationTask.getStopReason()).thenReturn("*_FINISHED"); when(replicationTask.getStopReason()).thenReturn("*_FINISHED");
Assert.assertTrue(dmsHook.checkFinishedReplicationTask()); Assertions.assertTrue(dmsHook.checkFinishedReplicationTask());
when(replicationTask.getStopReason()).thenReturn("*_ERROR"); when(replicationTask.getStopReason()).thenReturn("*_ERROR");
Assert.assertFalse(dmsHook.checkFinishedReplicationTask()); Assertions.assertFalse(dmsHook.checkFinishedReplicationTask());
} }
});
} }
@Test(timeout = 60000) @Test
public void testDeleteReplicationTask() { public void testDeleteReplicationTask() {
Assertions.assertTimeout(Duration.ofMillis(60000), () -> {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) { try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
mockHook.when(DmsHook::createClient).thenReturn(client); mockHook.when(DmsHook::createClient).thenReturn(client);
@ -123,9 +131,9 @@ public class DmsHookTest {
ReplicationTask replicationTask = mock(ReplicationTask.class); ReplicationTask replicationTask = mock(ReplicationTask.class);
when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.DELETE); when(replicationTask.getStatus()).thenReturn(DmsHook.STATUS.DELETE);
doReturn(replicationTask).when(dmsHook).describeReplicationTasks(); doReturn(replicationTask).when(dmsHook).describeReplicationTasks();
Assert.assertTrue(dmsHook.deleteReplicationTask()); Assertions.assertTrue(dmsHook.deleteReplicationTask());
} }
});
} }
@Test @Test
@ -145,29 +153,27 @@ public class DmsHookTest {
doReturn(false).when(dmsHook).testConnection(replicationInstanceArn, falseSourceEndpointArn); doReturn(false).when(dmsHook).testConnection(replicationInstanceArn, falseSourceEndpointArn);
doReturn(false).when(dmsHook).testConnection(replicationInstanceArn, falseTargetEndpointArn); doReturn(false).when(dmsHook).testConnection(replicationInstanceArn, falseTargetEndpointArn);
dmsHook.setReplicationInstanceArn(replicationInstanceArn); dmsHook.setReplicationInstanceArn(replicationInstanceArn);
dmsHook.setSourceEndpointArn(trueSourceEndpointArn); dmsHook.setSourceEndpointArn(trueSourceEndpointArn);
dmsHook.setTargetEndpointArn(trueTargetEndpointArn); dmsHook.setTargetEndpointArn(trueTargetEndpointArn);
Assert.assertTrue(dmsHook.testConnectionEndpoint()); Assertions.assertTrue(dmsHook.testConnectionEndpoint());
dmsHook.setSourceEndpointArn(falseSourceEndpointArn); dmsHook.setSourceEndpointArn(falseSourceEndpointArn);
dmsHook.setTargetEndpointArn(falseTargetEndpointArn); dmsHook.setTargetEndpointArn(falseTargetEndpointArn);
Assert.assertFalse(dmsHook.testConnectionEndpoint()); Assertions.assertFalse(dmsHook.testConnectionEndpoint());
dmsHook.setSourceEndpointArn(trueSourceEndpointArn); dmsHook.setSourceEndpointArn(trueSourceEndpointArn);
dmsHook.setTargetEndpointArn(falseTargetEndpointArn); dmsHook.setTargetEndpointArn(falseTargetEndpointArn);
Assert.assertFalse(dmsHook.testConnectionEndpoint()); Assertions.assertFalse(dmsHook.testConnectionEndpoint());
dmsHook.setSourceEndpointArn(falseSourceEndpointArn); dmsHook.setSourceEndpointArn(falseSourceEndpointArn);
dmsHook.setTargetEndpointArn(trueTargetEndpointArn); dmsHook.setTargetEndpointArn(trueTargetEndpointArn);
Assert.assertFalse(dmsHook.testConnectionEndpoint()); Assertions.assertFalse(dmsHook.testConnectionEndpoint());
} }
} }
@Test @Test
public void testDescribeReplicationTasks() { public void testDescribeReplicationTasks() {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) { try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
@ -180,7 +186,8 @@ public class DmsHookTest {
when(client.describeReplicationTasks(any())).thenReturn(describeReplicationTasksResult); when(client.describeReplicationTasks(any())).thenReturn(describeReplicationTasksResult);
ReplicationTask replicationTask = mock(ReplicationTask.class); ReplicationTask replicationTask = mock(ReplicationTask.class);
when(replicationTask.getReplicationTaskArn()).thenReturn("arn:aws:dms:ap-southeast-1:123456789012:task:task"); when(replicationTask.getReplicationTaskArn())
.thenReturn("arn:aws:dms:ap-southeast-1:123456789012:task:task");
when(replicationTask.getReplicationTaskIdentifier()).thenReturn("task"); when(replicationTask.getReplicationTaskIdentifier()).thenReturn("task");
final String sourceArn = "arn:aws:dms:ap-southeast-1:123456789012:endpoint:source"; final String sourceArn = "arn:aws:dms:ap-southeast-1:123456789012:endpoint:source";
@ -192,17 +199,17 @@ public class DmsHookTest {
when(describeReplicationTasksResult.getReplicationTasks()).thenReturn(Arrays.asList(replicationTask)); when(describeReplicationTasksResult.getReplicationTasks()).thenReturn(Arrays.asList(replicationTask));
ReplicationTask replicationTaskOut = dmsHook.describeReplicationTasks(); ReplicationTask replicationTaskOut = dmsHook.describeReplicationTasks();
Assert.assertNotEquals(dmsHook.getReplicationInstanceArn(), replicationTaskOut.getReplicationTaskArn()); Assertions.assertNotEquals(dmsHook.getReplicationInstanceArn(), replicationTaskOut.getReplicationTaskArn());
Assert.assertEquals("task", replicationTaskOut.getReplicationTaskIdentifier()); Assertions.assertEquals("task", replicationTaskOut.getReplicationTaskIdentifier());
Assert.assertEquals(sourceArn, replicationTaskOut.getSourceEndpointArn()); Assertions.assertEquals(sourceArn, replicationTaskOut.getSourceEndpointArn());
Assert.assertEquals(targetArn, replicationTaskOut.getTargetEndpointArn()); Assertions.assertEquals(targetArn, replicationTaskOut.getTargetEndpointArn());
} }
} }
@Test
@Test(timeout = 60000)
public void testAwaitReplicationTaskStatus() { public void testAwaitReplicationTaskStatus() {
Assertions.assertTimeout(Duration.ofMillis(60000), () -> {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) { try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
mockHook.when(DmsHook::createClient).thenReturn(client); mockHook.when(DmsHook::createClient).thenReturn(client);
DmsHook dmsHook = spy(new DmsHook()); DmsHook dmsHook = spy(new DmsHook());
@ -215,23 +222,20 @@ public class DmsHookTest {
when(taskStats.getFullLoadProgressPercent()).thenReturn(100); when(taskStats.getFullLoadProgressPercent()).thenReturn(100);
when(replicationTask.getStatus()).thenReturn( when(replicationTask.getStatus()).thenReturn(
DmsHook.STATUS.STOPPED DmsHook.STATUS.STOPPED);
); Assertions.assertTrue(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED));
Assert.assertTrue(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED));
when(replicationTask.getStatus()).thenReturn( when(replicationTask.getStatus()).thenReturn(
DmsHook.STATUS.RUNNING, DmsHook.STATUS.RUNNING,
DmsHook.STATUS.STOPPED DmsHook.STATUS.STOPPED);
); Assertions.assertTrue(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED));
Assert.assertTrue(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED));
when(replicationTask.getStatus()).thenReturn( when(replicationTask.getStatus()).thenReturn(
DmsHook.STATUS.RUNNING, DmsHook.STATUS.RUNNING,
DmsHook.STATUS.STOPPED DmsHook.STATUS.STOPPED);
); Assertions.assertFalse(
Assert.assertFalse(dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED, DmsHook.STATUS.RUNNING)); dmsHook.awaitReplicationTaskStatus(DmsHook.STATUS.STOPPED, DmsHook.STATUS.RUNNING));
} }
});
} }
} }

69
dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/test/java/org/apache/dolphinscheduler/plugin/task/dms/DmsTaskTest.java

@ -26,18 +26,18 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import com.amazonaws.services.databasemigrationservice.model.InvalidResourceStateException; import com.amazonaws.services.databasemigrationservice.model.InvalidResourceStateException;
import com.amazonaws.services.databasemigrationservice.model.ReplicationTask; import com.amazonaws.services.databasemigrationservice.model.ReplicationTask;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class DmsTaskTest { public class DmsTaskTest {
@Mock @Mock
@ -45,7 +45,7 @@ public class DmsTaskTest {
DmsTask dmsTask; DmsTask dmsTask;
@Before @BeforeEach
public void before() throws Exception { public void before() throws Exception {
DmsParameters dmsParameters = new DmsParameters(); DmsParameters dmsParameters = new DmsParameters();
dmsTask = initTask(dmsParameters); dmsTask = initTask(dmsParameters);
@ -57,7 +57,8 @@ public class DmsTaskTest {
public void testCreateTaskJson() { public void testCreateTaskJson() {
String jsonData = "{\n" + String jsonData = "{\n" +
" \"ReplicationTaskIdentifier\":\"task6\",\n" + " \"ReplicationTaskIdentifier\":\"task6\",\n" +
" \"SourceEndpointArn\":\"arn:aws:dms:ap-southeast-1:511640773671:endpoint:Z7SUEAL273SCT7OCPYNF5YNDHJDDFRATGNQISOQ\",\n" + " \"SourceEndpointArn\":\"arn:aws:dms:ap-southeast-1:511640773671:endpoint:Z7SUEAL273SCT7OCPYNF5YNDHJDDFRATGNQISOQ\",\n"
+
" \"TargetEndpointArn\":\"arn:aws:dms:ap-southeast-1:511640773671:endpoint:aws-mysql57-target\",\n" + " \"TargetEndpointArn\":\"arn:aws:dms:ap-southeast-1:511640773671:endpoint:aws-mysql57-target\",\n" +
" \"ReplicationInstanceArn\":\"arn:aws:dms:ap-southeast-1:511640773671:rep:dms2c2g\",\n" + " \"ReplicationInstanceArn\":\"arn:aws:dms:ap-southeast-1:511640773671:rep:dms2c2g\",\n" +
" \"MigrationType\":\"full-load\",\n" + " \"MigrationType\":\"full-load\",\n" +
@ -78,42 +79,45 @@ public class DmsTaskTest {
DmsTask dmsTask = initTask(dmsParameters); DmsTask dmsTask = initTask(dmsParameters);
dmsTask.convertJsonParameters(); dmsTask.convertJsonParameters();
DmsParameters dmsParametersNew = dmsTask.getParameters(); DmsParameters dmsParametersNew = dmsTask.getParameters();
Assert.assertEquals("task6", dmsParametersNew.getReplicationTaskIdentifier()); Assertions.assertEquals("task6", dmsParametersNew.getReplicationTaskIdentifier());
Assert.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:endpoint:Z7SUEAL273SCT7OCPYNF5YNDHJDDFRATGNQISOQ", dmsParametersNew.getSourceEndpointArn()); Assertions.assertEquals(
Assert.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:endpoint:aws-mysql57-target", dmsParametersNew.getTargetEndpointArn()); "arn:aws:dms:ap-southeast-1:511640773671:endpoint:Z7SUEAL273SCT7OCPYNF5YNDHJDDFRATGNQISOQ",
Assert.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:rep:dms2c2g", dmsParametersNew.getReplicationInstanceArn()); dmsParametersNew.getSourceEndpointArn());
Assert.assertEquals("full-load", dmsParametersNew.getMigrationType()); Assertions.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:endpoint:aws-mysql57-target",
Assert.assertEquals("file://table-mapping.json", dmsParametersNew.getTableMappings()); dmsParametersNew.getTargetEndpointArn());
Assert.assertEquals("file://ReplicationTaskSettings.json", dmsParametersNew.getReplicationTaskSettings()); Assertions.assertEquals("arn:aws:dms:ap-southeast-1:511640773671:rep:dms2c2g",
Assert.assertEquals("key1", dmsParametersNew.getTags().get(0).getKey()); dmsParametersNew.getReplicationInstanceArn());
Assert.assertEquals("value1", dmsParametersNew.getTags().get(0).getValue()); Assertions.assertEquals("full-load", dmsParametersNew.getMigrationType());
Assertions.assertEquals("file://table-mapping.json", dmsParametersNew.getTableMappings());
Assertions.assertEquals("file://ReplicationTaskSettings.json", dmsParametersNew.getReplicationTaskSettings());
Assertions.assertEquals("key1", dmsParametersNew.getTags().get(0).getKey());
Assertions.assertEquals("value1", dmsParametersNew.getTags().get(0).getValue());
} }
@Test @Test
public void testCheckCreateReplicationTask() throws Exception { public void testCheckCreateReplicationTask() throws Exception {
DmsParameters dmsParameters = dmsTask.getParameters(); DmsParameters dmsParameters = dmsTask.getParameters();
dmsParameters.setIsRestartTask(true); dmsParameters.setIsRestartTask(true);
Assert.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.checkCreateReplicationTask()); Assertions.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.checkCreateReplicationTask());
dmsParameters.setIsRestartTask(false); dmsParameters.setIsRestartTask(false);
when(dmsHook.createReplicationTask()).thenReturn(true); when(dmsHook.createReplicationTask()).thenReturn(true);
Assert.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.checkCreateReplicationTask()); Assertions.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.checkCreateReplicationTask());
when(dmsHook.createReplicationTask()).thenReturn(false); when(dmsHook.createReplicationTask()).thenReturn(false);
dmsTask.checkCreateReplicationTask(); dmsTask.checkCreateReplicationTask();
Assert.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.checkCreateReplicationTask()); Assertions.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.checkCreateReplicationTask());
} }
@Test @Test
public void testStartReplicationTask() { public void testStartReplicationTask() {
when(dmsHook.startReplicationTask()).thenReturn(true); when(dmsHook.startReplicationTask()).thenReturn(true);
Assert.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.startReplicationTask()); Assertions.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.startReplicationTask());
when(dmsHook.startReplicationTask()).thenReturn(false); when(dmsHook.startReplicationTask()).thenReturn(false);
Assert.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask()); Assertions.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask());
} }
@Test @Test
@ -125,23 +129,21 @@ public class DmsTaskTest {
when(dmsHook.startReplicationTask()) when(dmsHook.startReplicationTask())
.thenThrow(new InvalidResourceStateException("Test connection")) .thenThrow(new InvalidResourceStateException("Test connection"))
.thenReturn(true); .thenReturn(true);
Assert.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.startReplicationTask()); Assertions.assertEquals(TaskConstants.EXIT_CODE_SUCCESS, dmsTask.startReplicationTask());
when(dmsHook.startReplicationTask()) when(dmsHook.startReplicationTask())
.thenThrow(new InvalidResourceStateException("Test connection")) .thenThrow(new InvalidResourceStateException("Test connection"))
.thenReturn(false); .thenReturn(false);
Assert.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask()); Assertions.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask());
} }
@Test @Test
public void testStartReplicationTaskRestartOtherException() { public void testStartReplicationTaskRestartOtherException() {
DmsParameters parameters = dmsTask.getParameters(); DmsParameters parameters = dmsTask.getParameters();
parameters.setIsRestartTask(false); parameters.setIsRestartTask(false);
when(dmsHook.startReplicationTask()).thenThrow(new InvalidResourceStateException("other error")); when(dmsHook.startReplicationTask()).thenThrow(new InvalidResourceStateException("other error"));
Assert.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask()); Assertions.assertEquals(TaskConstants.EXIT_CODE_FAILURE, dmsTask.startReplicationTask());
} }
@Test @Test
@ -154,22 +156,21 @@ public class DmsTaskTest {
when(replicationTask.getMigrationType()).thenReturn("cdc"); when(replicationTask.getMigrationType()).thenReturn("cdc");
parameters.setCdcStopPosition("now"); parameters.setCdcStopPosition("now");
Assert.assertFalse(dmsTask.isStopTaskWhenCdc()); Assertions.assertFalse(dmsTask.isStopTaskWhenCdc());
when(replicationTask.getMigrationType()).thenReturn("full-load-and-cdc"); when(replicationTask.getMigrationType()).thenReturn("full-load-and-cdc");
parameters.setCdcStopPosition("now"); parameters.setCdcStopPosition("now");
Assert.assertFalse(dmsTask.isStopTaskWhenCdc()); Assertions.assertFalse(dmsTask.isStopTaskWhenCdc());
when(replicationTask.getMigrationType()).thenReturn("full-load-and-cdc"); when(replicationTask.getMigrationType()).thenReturn("full-load-and-cdc");
parameters.setCdcStopPosition(null); parameters.setCdcStopPosition(null);
Assert.assertTrue(dmsTask.isStopTaskWhenCdc()); Assertions.assertTrue(dmsTask.isStopTaskWhenCdc());
when(replicationTask.getMigrationType()).thenReturn("full-load"); when(replicationTask.getMigrationType()).thenReturn("full-load");
parameters.setCdcStopPosition(null); parameters.setCdcStopPosition(null);
Assert.assertFalse(dmsTask.isStopTaskWhenCdc()); Assertions.assertFalse(dmsTask.isStopTaskWhenCdc());
} }
private DmsTask initTask(DmsParameters dmsParameters) { private DmsTask initTask(DmsParameters dmsParameters) {
TaskExecutionContext taskExecutionContext = createContext(dmsParameters); TaskExecutionContext taskExecutionContext = createContext(dmsParameters);
DmsTask dmsTask = new DmsTask(taskExecutionContext); DmsTask dmsTask = new DmsTask(taskExecutionContext);
@ -184,5 +185,3 @@ public class DmsTaskTest {
return taskExecutionContext; return taskExecutionContext;
} }
} }

26
dolphinscheduler-task-plugin/dolphinscheduler-task-dvc/src/test/java/org/apache/dolphinscheduler/plugin/task/dvc/DvcTaskTest.java

@ -21,14 +21,13 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContextCacheManager; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContextCacheManager;
import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
@RunWith(MockitoJUnitRunner.class)
public class DvcTaskTest { public class DvcTaskTest {
public TaskExecutionContext createContext(DvcParameters dvcParameters) { public TaskExecutionContext createContext(DvcParameters dvcParameters) {
@ -52,8 +51,9 @@ public class DvcTaskTest {
@Test @Test
public void testDvcUpload() throws Exception { public void testDvcUpload() throws Exception {
DvcTask dvcTask = initTask(createUploadParameters()); DvcTask dvcTask = initTask(createUploadParameters());
Assert.assertEquals(dvcTask.buildCommand(), Assertions.assertEquals(dvcTask.buildCommand(),
"which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:<YOUR-NAME-OR-ORG>/dvc-data-repository-example\n" + "which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:<YOUR-NAME-OR-ORG>/dvc-data-repository-example\n"
+
"DVC_DATA_PATH=/home/<YOUR-NAME-OR-ORG>/test\n" + "DVC_DATA_PATH=/home/<YOUR-NAME-OR-ORG>/test\n" +
"DVC_DATA_LOCATION=test\n" + "DVC_DATA_LOCATION=test\n" +
"DVC_VERSION=iris_v2.3.1\n" + "DVC_VERSION=iris_v2.3.1\n" +
@ -71,8 +71,9 @@ public class DvcTaskTest {
@Test @Test
public void testDvcDownload() throws Exception { public void testDvcDownload() throws Exception {
DvcTask dvcTask = initTask(createDownloadParameters()); DvcTask dvcTask = initTask(createDownloadParameters());
Assert.assertEquals(dvcTask.buildCommand(), Assertions.assertEquals(dvcTask.buildCommand(),
"which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:<YOUR-NAME-OR-ORG>/dvc-data-repository-example\n" + "which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:<YOUR-NAME-OR-ORG>/dvc-data-repository-example\n"
+
"DVC_DATA_PATH=data\n" + "DVC_DATA_PATH=data\n" +
"DVC_DATA_LOCATION=iris\n" + "DVC_DATA_LOCATION=iris\n" +
"DVC_VERSION=iris_v2.3.1\n" + "DVC_VERSION=iris_v2.3.1\n" +
@ -82,8 +83,9 @@ public class DvcTaskTest {
@Test @Test
public void testInitDvc() throws Exception { public void testInitDvc() throws Exception {
DvcTask dvcTask = initTask(createInitDvcParameters()); DvcTask dvcTask = initTask(createInitDvcParameters());
Assert.assertEquals(dvcTask.buildCommand(), Assertions.assertEquals(dvcTask.buildCommand(),
"which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:<YOUR-NAME-OR-ORG>/dvc-data-repository-example\n" + "which dvc || { echo \"dvc does not exist\"; exit 1; }; DVC_REPO=git@github.com:<YOUR-NAME-OR-ORG>/dvc-data-repository-example\n"
+
"git clone $DVC_REPO dvc-repository; cd dvc-repository; pwd\n" + "git clone $DVC_REPO dvc-repository; cd dvc-repository; pwd\n" +
"dvc init || exit 1\n" + "dvc init || exit 1\n" +
"dvc remote add origin ~/.dvc_test -d\n" + "dvc remote add origin ~/.dvc_test -d\n" +

47
dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTaskTest.java

@ -33,12 +33,12 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduce; import com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduce;
import com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsResult; import com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsResult;
@ -53,7 +53,7 @@ import com.amazonaws.services.elasticmapreduce.model.StepStatus;
* *
* @since v3.1.0 * @since v3.1.0
*/ */
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class EmrAddStepsTaskTest { public class EmrAddStepsTaskTest {
private final StepStatus pendingState = private final StepStatus pendingState =
@ -78,7 +78,7 @@ public class EmrAddStepsTaskTest {
}; };
@Before @BeforeEach
public void before() throws Exception { public void before() throws Exception {
// mock EmrParameters and EmrAddStepsTask // mock EmrParameters and EmrAddStepsTask
EmrParameters emrParameters = buildEmrTaskParameters(); EmrParameters emrParameters = buildEmrTaskParameters();
@ -91,27 +91,30 @@ public class EmrAddStepsTaskTest {
emrClient = Mockito.mock(AmazonElasticMapReduce.class); emrClient = Mockito.mock(AmazonElasticMapReduce.class);
AddJobFlowStepsResult addJobFlowStepsResult = Mockito.mock(AddJobFlowStepsResult.class); AddJobFlowStepsResult addJobFlowStepsResult = Mockito.mock(AddJobFlowStepsResult.class);
Mockito.when(emrClient.addJobFlowSteps(any())).thenReturn(addJobFlowStepsResult); Mockito.lenient().when(emrClient.addJobFlowSteps(any())).thenReturn(addJobFlowStepsResult);
Mockito.when(addJobFlowStepsResult.getStepIds()).thenReturn(Collections.singletonList("step-xx")); Mockito.lenient().when(addJobFlowStepsResult.getStepIds()).thenReturn(Collections.singletonList("step-xx"));
Mockito.doReturn(emrClient).when(emrAddStepsTask).createEmrClient(); Mockito.doReturn(emrClient).when(emrAddStepsTask).createEmrClient();
DescribeStepResult describeStepResult = Mockito.mock(DescribeStepResult.class); DescribeStepResult describeStepResult = Mockito.mock(DescribeStepResult.class);
Mockito.when(emrClient.describeStep(any())).thenReturn(describeStepResult); Mockito.lenient().when(emrClient.describeStep(any())).thenReturn(describeStepResult);
// mock step // mock step
step = Mockito.mock(Step.class); step = Mockito.mock(Step.class);
Mockito.when(describeStepResult.getStep()).thenReturn(step); Mockito.lenient().when(describeStepResult.getStep()).thenReturn(step);
emrAddStepsTask.init(); emrAddStepsTask.init();
} }
@Test(expected = TaskException.class) @Test
public void testCanNotParseJson() throws Exception { public void testCanNotParseJson() throws Exception {
Mockito.when(emrAddStepsTask.createAddJobFlowStepsRequest()).thenThrow(new EmrTaskException("can not parse AddJobFlowStepsRequest from json", new Exception("error"))); Mockito.when(emrAddStepsTask.createAddJobFlowStepsRequest()).thenThrow(
new EmrTaskException("can not parse AddJobFlowStepsRequest from json", new Exception("error")));
Assertions.assertThrows(TaskException.class, () -> {
emrAddStepsTask.handle(taskCallBack); emrAddStepsTask.handle(taskCallBack);
});
} }
@Test(expected = TaskException.class) @Test
public void testDefineJsonStepNotOne() throws Exception { public void testDefineJsonStepNotOne() throws Exception {
// mock EmrParameters and EmrAddStepsTask // mock EmrParameters and EmrAddStepsTask
EmrParameters emrParameters = buildErrorEmrTaskParameters(); EmrParameters emrParameters = buildErrorEmrTaskParameters();
@ -120,8 +123,11 @@ public class EmrAddStepsTaskTest {
Mockito.when(taskExecutionContext.getTaskParams()).thenReturn(emrParametersString); Mockito.when(taskExecutionContext.getTaskParams()).thenReturn(emrParametersString);
emrAddStepsTask = Mockito.spy(new EmrAddStepsTask(taskExecutionContext)); emrAddStepsTask = Mockito.spy(new EmrAddStepsTask(taskExecutionContext));
Mockito.doReturn(emrClient).when(emrAddStepsTask).createEmrClient(); Mockito.doReturn(emrClient).when(emrAddStepsTask).createEmrClient();
Assertions.assertThrows(TaskException.class, () -> {
emrAddStepsTask.init(); emrAddStepsTask.init();
emrAddStepsTask.handle(taskCallBack); emrAddStepsTask.handle(taskCallBack);
});
} }
@Test @Test
@ -129,7 +135,7 @@ public class EmrAddStepsTaskTest {
Mockito.when(step.getStatus()).thenReturn(pendingState, runningState, completedState); Mockito.when(step.getStatus()).thenReturn(pendingState, runningState, completedState);
emrAddStepsTask.handle(taskCallBack); emrAddStepsTask.handle(taskCallBack);
Assert.assertEquals(EXIT_CODE_SUCCESS, emrAddStepsTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, emrAddStepsTask.getExitStatusCode());
} }
@Test @Test
@ -137,17 +143,20 @@ public class EmrAddStepsTaskTest {
Mockito.when(step.getStatus()).thenReturn(pendingState, runningState, cancelledState); Mockito.when(step.getStatus()).thenReturn(pendingState, runningState, cancelledState);
emrAddStepsTask.handle(taskCallBack); emrAddStepsTask.handle(taskCallBack);
Assert.assertEquals(EXIT_CODE_KILL, emrAddStepsTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_KILL, emrAddStepsTask.getExitStatusCode());
} }
@Test(expected = TaskException.class) @Test
public void testHandleError() throws Exception { public void testHandleError() throws Exception {
Mockito.when(step.getStatus()).thenReturn(pendingState, runningState, failedState); Mockito.when(step.getStatus()).thenReturn(pendingState, runningState, failedState);
emrAddStepsTask.handle(taskCallBack); emrAddStepsTask.handle(taskCallBack);
Assert.assertEquals(EXIT_CODE_FAILURE, emrAddStepsTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_FAILURE, emrAddStepsTask.getExitStatusCode());
Mockito.when(emrClient.addJobFlowSteps(any())).thenThrow(new AmazonElasticMapReduceException("error"), new EmrTaskException()); Mockito.when(emrClient.addJobFlowSteps(any())).thenThrow(new AmazonElasticMapReduceException("error"),
new EmrTaskException());
Assertions.assertThrows(TaskException.class, () -> {
emrAddStepsTask.handle(taskCallBack); emrAddStepsTask.handle(taskCallBack);
});
} }
private EmrParameters buildEmrTaskParameters() { private EmrParameters buildEmrTaskParameters() {

77
dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/test/java/org/apache/dolphinscheduler/plugin/task/emr/EmrJobFlowTaskTest.java

@ -32,12 +32,12 @@ import org.apache.commons.io.IOUtils;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduce; import com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduce;
import com.amazonaws.services.elasticmapreduce.model.AmazonElasticMapReduceException; import com.amazonaws.services.elasticmapreduce.model.AmazonElasticMapReduceException;
@ -49,7 +49,7 @@ import com.amazonaws.services.elasticmapreduce.model.ClusterStatus;
import com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult; import com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult;
import com.amazonaws.services.elasticmapreduce.model.RunJobFlowResult; import com.amazonaws.services.elasticmapreduce.model.RunJobFlowResult;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class EmrJobFlowTaskTest { public class EmrJobFlowTaskTest {
private final ClusterStatus startingStatus = private final ClusterStatus startingStatus =
@ -60,45 +60,38 @@ public class EmrJobFlowTaskTest {
new ClusterStatus().withState(ClusterState.STARTING) new ClusterStatus().withState(ClusterState.STARTING)
.withStateChangeReason( .withStateChangeReason(
new ClusterStateChangeReason() new ClusterStateChangeReason()
.withMessage("Configuring cluster software") .withMessage("Configuring cluster software"));
);
private final ClusterStatus runningStatus = private final ClusterStatus runningStatus =
new ClusterStatus().withState(ClusterState.RUNNING) new ClusterStatus().withState(ClusterState.RUNNING)
.withStateChangeReason( .withStateChangeReason(
new ClusterStateChangeReason().withMessage("Running step") new ClusterStateChangeReason().withMessage("Running step"));
);
private final ClusterStatus terminatingStatus = private final ClusterStatus terminatingStatus =
new ClusterStatus().withState(ClusterState.TERMINATING.toString()) new ClusterStatus().withState(ClusterState.TERMINATING.toString())
.withStateChangeReason( .withStateChangeReason(
new ClusterStateChangeReason() new ClusterStateChangeReason()
.withCode(ClusterStateChangeReasonCode.ALL_STEPS_COMPLETED) .withCode(ClusterStateChangeReasonCode.ALL_STEPS_COMPLETED)
.withMessage("Steps completed") .withMessage("Steps completed"));
);
private final ClusterStatus waitingStatus = private final ClusterStatus waitingStatus =
new ClusterStatus().withState(ClusterState.WAITING) new ClusterStatus().withState(ClusterState.WAITING)
.withStateChangeReason( .withStateChangeReason(
new ClusterStateChangeReason() new ClusterStateChangeReason()
.withMessage("Cluster ready after last step completed.") .withMessage("Cluster ready after last step completed."));
);
private final ClusterStatus userRequestTerminateStatus = private final ClusterStatus userRequestTerminateStatus =
new ClusterStatus().withState(ClusterState.TERMINATING) new ClusterStatus().withState(ClusterState.TERMINATING)
.withStateChangeReason( .withStateChangeReason(
new ClusterStateChangeReason() new ClusterStateChangeReason()
.withCode(ClusterStateChangeReasonCode.USER_REQUEST) .withCode(ClusterStateChangeReasonCode.USER_REQUEST)
.withMessage("Terminated by user request") .withMessage("Terminated by user request"));
);
private final ClusterStatus terminatedWithErrorsStatus = private final ClusterStatus terminatedWithErrorsStatus =
new ClusterStatus().withState(ClusterState.TERMINATED_WITH_ERRORS) new ClusterStatus().withState(ClusterState.TERMINATED_WITH_ERRORS)
.withStateChangeReason( .withStateChangeReason(
new ClusterStateChangeReason() new ClusterStateChangeReason()
.withCode(ClusterStateChangeReasonCode.STEP_FAILURE) .withCode(ClusterStateChangeReasonCode.STEP_FAILURE));
);
private EmrJobFlowTask emrJobFlowTask; private EmrJobFlowTask emrJobFlowTask;
private AmazonElasticMapReduce emrClient; private AmazonElasticMapReduce emrClient;
@ -107,7 +100,7 @@ public class EmrJobFlowTaskTest {
}; };
@Before @BeforeEach
public void before() throws Exception { public void before() throws Exception {
String emrParameters = buildEmrTaskParameters(); String emrParameters = buildEmrTaskParameters();
TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class); TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class);
@ -117,15 +110,15 @@ public class EmrJobFlowTaskTest {
// mock emrClient and behavior // mock emrClient and behavior
emrClient = Mockito.mock(AmazonElasticMapReduce.class); emrClient = Mockito.mock(AmazonElasticMapReduce.class);
RunJobFlowResult runJobFlowResult = Mockito.mock(RunJobFlowResult.class); RunJobFlowResult runJobFlowResult = Mockito.mock(RunJobFlowResult.class);
Mockito.when(emrClient.runJobFlow(any())).thenReturn(runJobFlowResult); Mockito.lenient().when(emrClient.runJobFlow(any())).thenReturn(runJobFlowResult);
Mockito.when(runJobFlowResult.getJobFlowId()).thenReturn("xx"); Mockito.lenient().when(runJobFlowResult.getJobFlowId()).thenReturn("xx");
Mockito.doReturn(emrClient).when(emrJobFlowTask).createEmrClient(); Mockito.doReturn(emrClient).when(emrJobFlowTask).createEmrClient();
DescribeClusterResult describeClusterResult = Mockito.mock(DescribeClusterResult.class); DescribeClusterResult describeClusterResult = Mockito.mock(DescribeClusterResult.class);
Mockito.when(emrClient.describeCluster(any())).thenReturn(describeClusterResult); Mockito.lenient().when(emrClient.describeCluster(any())).thenReturn(describeClusterResult);
// mock cluster // mock cluster
cluster = Mockito.mock(Cluster.class); cluster = Mockito.mock(Cluster.class);
Mockito.when(describeClusterResult.getCluster()).thenReturn(cluster); Mockito.lenient().when(describeClusterResult.getCluster()).thenReturn(cluster);
emrJobFlowTask.init(); emrJobFlowTask.init();
} }
@ -133,19 +126,21 @@ public class EmrJobFlowTaskTest {
@Test @Test
public void testHandle() throws Exception { public void testHandle() throws Exception {
Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus, terminatingStatus); Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus,
terminatingStatus);
emrJobFlowTask.handle(taskCallBack); emrJobFlowTask.handle(taskCallBack);
Assert.assertEquals(EXIT_CODE_SUCCESS, emrJobFlowTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, emrJobFlowTask.getExitStatusCode());
} }
@Test @Test
public void testHandleAliveWhenNoSteps() throws Exception { public void testHandleAliveWhenNoSteps() throws Exception {
Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus, waitingStatus); Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus,
waitingStatus);
emrJobFlowTask.handle(taskCallBack); emrJobFlowTask.handle(taskCallBack);
Assert.assertEquals(EXIT_CODE_SUCCESS, emrJobFlowTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, emrJobFlowTask.getExitStatusCode());
} }
@Test @Test
@ -153,34 +148,42 @@ public class EmrJobFlowTaskTest {
Mockito.when(cluster.getStatus()).thenReturn(startingStatus, userRequestTerminateStatus); Mockito.when(cluster.getStatus()).thenReturn(startingStatus, userRequestTerminateStatus);
emrJobFlowTask.handle(taskCallBack); emrJobFlowTask.handle(taskCallBack);
Assert.assertEquals(EXIT_CODE_KILL, emrJobFlowTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_KILL, emrJobFlowTask.getExitStatusCode());
} }
@Test @Test
public void testHandleTerminatedWithError() throws Exception { public void testHandleTerminatedWithError() throws Exception {
Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus, terminatedWithErrorsStatus); Mockito.when(cluster.getStatus()).thenReturn(startingStatus, softwareConfigStatus, runningStatus,
terminatedWithErrorsStatus);
emrJobFlowTask.handle(taskCallBack); emrJobFlowTask.handle(taskCallBack);
Assert.assertEquals(EXIT_CODE_FAILURE, emrJobFlowTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_FAILURE, emrJobFlowTask.getExitStatusCode());
} }
@Test(expected = TaskException.class) @Test
public void testCanNotParseJson() throws Exception { public void testCanNotParseJson() throws Exception {
Mockito.when(emrJobFlowTask.createRunJobFlowRequest()).thenThrow(new EmrTaskException("can not parse RunJobFlowRequest from json", new Exception("error"))); Mockito.when(emrJobFlowTask.createRunJobFlowRequest())
.thenThrow(new EmrTaskException("can not parse RunJobFlowRequest from json", new Exception("error")));
Assertions.assertThrows(TaskException.class, () -> {
emrJobFlowTask.handle(taskCallBack); emrJobFlowTask.handle(taskCallBack);
});
} }
@Test(expected = TaskException.class) @Test
public void testClusterStatusNull() throws Exception { public void testClusterStatusNull() throws Exception {
Mockito.when(emrClient.describeCluster(any())).thenReturn(null); Mockito.when(emrClient.describeCluster(any())).thenReturn(null);
Assertions.assertThrows(TaskException.class, () -> {
emrJobFlowTask.handle(taskCallBack); emrJobFlowTask.handle(taskCallBack);
});
} }
@Test(expected = TaskException.class) @Test
public void testRunJobFlowError() throws Exception { public void testRunJobFlowError() throws Exception {
Mockito.when(emrClient.runJobFlow(any())).thenThrow(new AmazonElasticMapReduceException("error"), new EmrTaskException()); Mockito.when(emrClient.runJobFlow(any())).thenThrow(new AmazonElasticMapReduceException("error"),
new EmrTaskException());
Assertions.assertThrows(TaskException.class, () -> {
emrJobFlowTask.handle(taskCallBack); emrJobFlowTask.handle(taskCallBack);
});
} }
private String buildEmrTaskParameters() { private String buildEmrTaskParameters() {

52
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java

@ -19,11 +19,12 @@ package org.apache.dolphinscheduler.plugin.task.flink;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.junit.Assert;
import org.junit.Test;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class FlinkArgsUtilsTest { public class FlinkArgsUtilsTest {
private String joinStringListWithSpace(List<String> stringList) { private String joinStringListWithSpace(List<String> stringList) {
@ -60,7 +61,7 @@ public class FlinkArgsUtilsTest {
FlinkStreamParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION); FlinkStreamParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION);
List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run-application -t yarn-application -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", "flink run-application -t yarn-application -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine)); joinStringListWithSpace(commandLine));
} }
@ -69,23 +70,26 @@ public class FlinkArgsUtilsTest {
public void testRunJarInClusterMode() throws Exception { public void testRunJarInClusterMode() throws Exception {
FlinkStreamParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER); FlinkStreamParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER);
flinkParameters.setFlinkVersion("1.11"); flinkParameters.setFlinkVersion("1.11");
List<String> commandLine1 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine1 =
FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", "flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine1)); joinStringListWithSpace(commandLine1));
flinkParameters.setFlinkVersion("<1.10"); flinkParameters.setFlinkVersion("<1.10");
List<String> commandLine2 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine2 =
FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", "flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine2)); joinStringListWithSpace(commandLine2));
flinkParameters.setFlinkVersion(">=1.12"); flinkParameters.setFlinkVersion(">=1.12");
List<String> commandLine3 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine3 =
FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run -t yarn-per-job -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", "flink run -t yarn-per-job -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine3)); joinStringListWithSpace(commandLine3));
} }
@ -95,7 +99,7 @@ public class FlinkArgsUtilsTest {
FlinkStreamParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.LOCAL); FlinkStreamParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.LOCAL);
List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run -p 4 -sae -c org.example.Main /opt/job.jar", "flink run -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine)); joinStringListWithSpace(commandLine));
} }
@ -106,27 +110,29 @@ public class FlinkArgsUtilsTest {
flinkParameters.setProgramType(ProgramType.SQL); flinkParameters.setProgramType(ProgramType.SQL);
List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals("sql-client.sh -i /tmp/execution/app-id_init.sql -f /tmp/execution/app-id_node.sql", Assertions.assertEquals("sql-client.sh -i /tmp/execution/app-id_init.sql -f /tmp/execution/app-id_node.sql",
joinStringListWithSpace(commandLine)); joinStringListWithSpace(commandLine));
} }
@Test @Test
public void testInitOptionsInClusterMode() throws Exception { public void testInitOptionsInClusterMode() throws Exception {
List<String> initOptions = FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER)); List<String> initOptions =
Assert.assertEquals(2, initOptions.size()); FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER));
Assert.assertTrue(initOptions.contains("set execution.target=local")); Assertions.assertEquals(2, initOptions.size());
Assert.assertTrue(initOptions.contains("set parallelism.default=4")); Assertions.assertTrue(initOptions.contains("set execution.target=local"));
Assertions.assertTrue(initOptions.contains("set parallelism.default=4"));
} }
@Test @Test
public void testInitOptionsInApplicationMode() throws Exception { public void testInitOptionsInApplicationMode() throws Exception {
List<String> initOptions = FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION)); List<String> initOptions = FlinkArgsUtils
Assert.assertEquals(6, initOptions.size()); .buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION));
Assert.assertTrue(initOptions.contains("set execution.target=yarn-per-job")); Assertions.assertEquals(6, initOptions.size());
Assert.assertTrue(initOptions.contains("set taskmanager.numberOfTaskSlots=4")); Assertions.assertTrue(initOptions.contains("set execution.target=yarn-per-job"));
Assert.assertTrue(initOptions.contains("set yarn.application.name=demo-app-name")); Assertions.assertTrue(initOptions.contains("set taskmanager.numberOfTaskSlots=4"));
Assert.assertTrue(initOptions.contains("set jobmanager.memory.process.size=1024m")); Assertions.assertTrue(initOptions.contains("set yarn.application.name=demo-app-name"));
Assert.assertTrue(initOptions.contains("set taskmanager.memory.process.size=1024m")); Assertions.assertTrue(initOptions.contains("set jobmanager.memory.process.size=1024m"));
Assert.assertTrue(initOptions.contains("set parallelism.default=4")); Assertions.assertTrue(initOptions.contains("set taskmanager.memory.process.size=1024m"));
Assertions.assertTrue(initOptions.contains("set parallelism.default=4"));
} }
} }

15
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java

@ -22,14 +22,15 @@ import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class FlinkParametersTest { public class FlinkParametersTest {
@Test @Test
public void getResourceFilesList() { public void getResourceFilesList() {
FlinkStreamParameters flinkParameters = new FlinkStreamParameters(); FlinkStreamParameters flinkParameters = new FlinkStreamParameters();
Assert.assertTrue(flinkParameters.getResourceFilesList().isEmpty()); Assertions.assertTrue(flinkParameters.getResourceFilesList().isEmpty());
ResourceInfo mainResource = new ResourceInfo(); ResourceInfo mainResource = new ResourceInfo();
mainResource.setRes("testFlinkMain-1.0.0-SNAPSHOT.jar"); mainResource.setRes("testFlinkMain-1.0.0-SNAPSHOT.jar");
@ -42,8 +43,8 @@ public class FlinkParametersTest {
flinkParameters.setResourceList(resourceInfos); flinkParameters.setResourceList(resourceInfos);
List<ResourceInfo> resourceFilesList = flinkParameters.getResourceFilesList(); List<ResourceInfo> resourceFilesList = flinkParameters.getResourceFilesList();
Assert.assertNotNull(resourceFilesList); Assertions.assertNotNull(resourceFilesList);
Assert.assertEquals(2, resourceFilesList.size()); Assertions.assertEquals(2, resourceFilesList.size());
ResourceInfo resourceInfo2 = new ResourceInfo(); ResourceInfo resourceInfo2 = new ResourceInfo();
resourceInfo2.setRes("testFlinkParameters2.jar"); resourceInfo2.setRes("testFlinkParameters2.jar");
@ -51,7 +52,7 @@ public class FlinkParametersTest {
flinkParameters.setResourceList(resourceInfos); flinkParameters.setResourceList(resourceInfos);
resourceFilesList = flinkParameters.getResourceFilesList(); resourceFilesList = flinkParameters.getResourceFilesList();
Assert.assertNotNull(resourceFilesList); Assertions.assertNotNull(resourceFilesList);
Assert.assertEquals(3, resourceFilesList.size()); Assertions.assertEquals(3, resourceFilesList.size());
} }
} }

52
dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkArgsUtilsTest.java

@ -19,11 +19,12 @@ package org.apache.dolphinscheduler.plugin.task.flink;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.junit.Assert;
import org.junit.Test;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class FlinkArgsUtilsTest { public class FlinkArgsUtilsTest {
private String joinStringListWithSpace(List<String> stringList) { private String joinStringListWithSpace(List<String> stringList) {
@ -60,7 +61,7 @@ public class FlinkArgsUtilsTest {
FlinkParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION); FlinkParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION);
List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run-application -t yarn-application -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", "flink run-application -t yarn-application -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine)); joinStringListWithSpace(commandLine));
} }
@ -69,23 +70,26 @@ public class FlinkArgsUtilsTest {
public void testRunJarInClusterMode() throws Exception { public void testRunJarInClusterMode() throws Exception {
FlinkParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER); FlinkParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER);
flinkParameters.setFlinkVersion("1.11"); flinkParameters.setFlinkVersion("1.11");
List<String> commandLine1 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine1 =
FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", "flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine1)); joinStringListWithSpace(commandLine1));
flinkParameters.setFlinkVersion("<1.10"); flinkParameters.setFlinkVersion("<1.10");
List<String> commandLine2 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine2 =
FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", "flink run -m yarn-cluster -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine2)); joinStringListWithSpace(commandLine2));
flinkParameters.setFlinkVersion(">=1.12"); flinkParameters.setFlinkVersion(">=1.12");
List<String> commandLine3 = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine3 =
FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run -t yarn-per-job -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar", "flink run -t yarn-per-job -ys 4 -ynm demo-app-name -yjm 1024m -ytm 1024m -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine3)); joinStringListWithSpace(commandLine3));
} }
@ -95,7 +99,7 @@ public class FlinkArgsUtilsTest {
FlinkParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.LOCAL); FlinkParameters flinkParameters = buildTestFlinkParametersWithDeployMode(FlinkDeployMode.LOCAL);
List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals( Assertions.assertEquals(
"flink run -p 4 -sae -c org.example.Main /opt/job.jar", "flink run -p 4 -sae -c org.example.Main /opt/job.jar",
joinStringListWithSpace(commandLine)); joinStringListWithSpace(commandLine));
} }
@ -106,27 +110,29 @@ public class FlinkArgsUtilsTest {
flinkParameters.setProgramType(ProgramType.SQL); flinkParameters.setProgramType(ProgramType.SQL);
List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters); List<String> commandLine = FlinkArgsUtils.buildRunCommandLine(buildTestTaskExecutionContext(), flinkParameters);
Assert.assertEquals("sql-client.sh -i /tmp/execution/app-id_init.sql -f /tmp/execution/app-id_node.sql", Assertions.assertEquals("sql-client.sh -i /tmp/execution/app-id_init.sql -f /tmp/execution/app-id_node.sql",
joinStringListWithSpace(commandLine)); joinStringListWithSpace(commandLine));
} }
@Test @Test
public void testInitOptionsInClusterMode() throws Exception { public void testInitOptionsInClusterMode() throws Exception {
List<String> initOptions = FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER)); List<String> initOptions =
Assert.assertEquals(2, initOptions.size()); FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.CLUSTER));
Assert.assertTrue(initOptions.contains("set execution.target=local")); Assertions.assertEquals(2, initOptions.size());
Assert.assertTrue(initOptions.contains("set parallelism.default=4")); Assertions.assertTrue(initOptions.contains("set execution.target=local"));
Assertions.assertTrue(initOptions.contains("set parallelism.default=4"));
} }
@Test @Test
public void testInitOptionsInApplicationMode() throws Exception { public void testInitOptionsInApplicationMode() throws Exception {
List<String> initOptions = FlinkArgsUtils.buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION)); List<String> initOptions = FlinkArgsUtils
Assert.assertEquals(6, initOptions.size()); .buildInitOptionsForSql(buildTestFlinkParametersWithDeployMode(FlinkDeployMode.APPLICATION));
Assert.assertTrue(initOptions.contains("set execution.target=yarn-per-job")); Assertions.assertEquals(6, initOptions.size());
Assert.assertTrue(initOptions.contains("set taskmanager.numberOfTaskSlots=4")); Assertions.assertTrue(initOptions.contains("set execution.target=yarn-per-job"));
Assert.assertTrue(initOptions.contains("set yarn.application.name=demo-app-name")); Assertions.assertTrue(initOptions.contains("set taskmanager.numberOfTaskSlots=4"));
Assert.assertTrue(initOptions.contains("set jobmanager.memory.process.size=1024m")); Assertions.assertTrue(initOptions.contains("set yarn.application.name=demo-app-name"));
Assert.assertTrue(initOptions.contains("set taskmanager.memory.process.size=1024m")); Assertions.assertTrue(initOptions.contains("set jobmanager.memory.process.size=1024m"));
Assert.assertTrue(initOptions.contains("set parallelism.default=4")); Assertions.assertTrue(initOptions.contains("set taskmanager.memory.process.size=1024m"));
Assertions.assertTrue(initOptions.contains("set parallelism.default=4"));
} }
} }

15
dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkParametersTest.java

@ -22,14 +22,15 @@ import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class FlinkParametersTest { public class FlinkParametersTest {
@Test @Test
public void getResourceFilesList() { public void getResourceFilesList() {
FlinkParameters flinkParameters = new FlinkParameters(); FlinkParameters flinkParameters = new FlinkParameters();
Assert.assertTrue(flinkParameters.getResourceFilesList().isEmpty()); Assertions.assertTrue(flinkParameters.getResourceFilesList().isEmpty());
ResourceInfo mainResource = new ResourceInfo(); ResourceInfo mainResource = new ResourceInfo();
mainResource.setRes("testFlinkMain-1.0.0-SNAPSHOT.jar"); mainResource.setRes("testFlinkMain-1.0.0-SNAPSHOT.jar");
@ -42,8 +43,8 @@ public class FlinkParametersTest {
flinkParameters.setResourceList(resourceInfos); flinkParameters.setResourceList(resourceInfos);
List<ResourceInfo> resourceFilesList = flinkParameters.getResourceFilesList(); List<ResourceInfo> resourceFilesList = flinkParameters.getResourceFilesList();
Assert.assertNotNull(resourceFilesList); Assertions.assertNotNull(resourceFilesList);
Assert.assertEquals(2, resourceFilesList.size()); Assertions.assertEquals(2, resourceFilesList.size());
ResourceInfo resourceInfo2 = new ResourceInfo(); ResourceInfo resourceInfo2 = new ResourceInfo();
resourceInfo2.setRes("testFlinkParameters2.jar"); resourceInfo2.setRes("testFlinkParameters2.jar");
@ -51,7 +52,7 @@ public class FlinkParametersTest {
flinkParameters.setResourceList(resourceInfos); flinkParameters.setResourceList(resourceInfos);
resourceFilesList = flinkParameters.getResourceFilesList(); resourceFilesList = flinkParameters.getResourceFilesList();
Assert.assertNotNull(resourceFilesList); Assertions.assertNotNull(resourceFilesList);
Assert.assertEquals(3, resourceFilesList.size()); Assertions.assertEquals(3, resourceFilesList.size());
} }
} }

16
dolphinscheduler-task-plugin/dolphinscheduler-task-hivecli/src/test/java/org/apache/dolphinscheduler/plugin/task/hivecli/HiveCliTaskTest.java

@ -27,13 +27,13 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class HiveCliTaskTest { public class HiveCliTaskTest {
public static final String EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_SCRIPT_COMMAND = public static final String EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_SCRIPT_COMMAND =
@ -50,7 +50,7 @@ public class HiveCliTaskTest {
String hiveCliTaskParameters = buildHiveCliTaskExecuteSqlFromScriptParameters(); String hiveCliTaskParameters = buildHiveCliTaskExecuteSqlFromScriptParameters();
HiveCliTask hiveCliTask = prepareHiveCliTaskForTest(hiveCliTaskParameters); HiveCliTask hiveCliTask = prepareHiveCliTaskForTest(hiveCliTaskParameters);
hiveCliTask.init(); hiveCliTask.init();
Assert.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_SCRIPT_COMMAND); Assertions.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_SCRIPT_COMMAND);
} }
@Test @Test
@ -58,7 +58,7 @@ public class HiveCliTaskTest {
String hiveCliTaskParameters = buildHiveCliTaskExecuteSqlFromFileParameters(); String hiveCliTaskParameters = buildHiveCliTaskExecuteSqlFromFileParameters();
HiveCliTask hiveCliTask = prepareHiveCliTaskForTest(hiveCliTaskParameters); HiveCliTask hiveCliTask = prepareHiveCliTaskForTest(hiveCliTaskParameters);
hiveCliTask.init(); hiveCliTask.init();
Assert.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_FILE_COMMAND); Assertions.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_FROM_FILE_COMMAND);
} }
@Test @Test
@ -66,7 +66,7 @@ public class HiveCliTaskTest {
String hiveCliTaskParameters = buildHiveCliTaskExecuteWithOptionsParameters(); String hiveCliTaskParameters = buildHiveCliTaskExecuteWithOptionsParameters();
HiveCliTask hiveCliTask = prepareHiveCliTaskForTest(hiveCliTaskParameters); HiveCliTask hiveCliTask = prepareHiveCliTaskForTest(hiveCliTaskParameters);
hiveCliTask.init(); hiveCliTask.init();
Assert.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_WITH_OPTIONS); Assertions.assertEquals(hiveCliTask.buildCommand(), EXPECTED_HIVE_CLI_TASK_EXECUTE_WITH_OPTIONS);
} }
private HiveCliTask prepareHiveCliTaskForTest(final String hiveCliTaskParameters) { private HiveCliTask prepareHiveCliTaskForTest(final String hiveCliTaskParameters) {

48
dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java

@ -19,8 +19,8 @@ package org.apache.dolphinscheduler.plugin.task.http;
import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* http parameter * http parameter
@ -33,12 +33,12 @@ public class HttpParametersTest {
+ "\"httpMethod\":\"GET\",\"httpCheckCondition\":\"STATUS_CODE_DEFAULT\",\"condition\":\"\",\"connectTimeout\":\"10000\",\"socketTimeout\":\"10000\"}"; + "\"httpMethod\":\"GET\",\"httpCheckCondition\":\"STATUS_CODE_DEFAULT\",\"condition\":\"\",\"connectTimeout\":\"10000\",\"socketTimeout\":\"10000\"}";
HttpParameters httpParameters = JSONUtils.parseObject(paramData, HttpParameters.class); HttpParameters httpParameters = JSONUtils.parseObject(paramData, HttpParameters.class);
Assert.assertEquals(10000, httpParameters.getConnectTimeout()); Assertions.assertEquals(10000, httpParameters.getConnectTimeout());
Assert.assertEquals(10000, httpParameters.getSocketTimeout()); Assertions.assertEquals(10000, httpParameters.getSocketTimeout());
Assert.assertEquals("https://www.baidu.com/", httpParameters.getUrl()); Assertions.assertEquals("https://www.baidu.com/", httpParameters.getUrl());
Assert.assertEquals(HttpMethod.GET, httpParameters.getHttpMethod()); Assertions.assertEquals(HttpMethod.GET, httpParameters.getHttpMethod());
Assert.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT, httpParameters.getHttpCheckCondition()); Assertions.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT, httpParameters.getHttpCheckCondition());
Assert.assertEquals("", httpParameters.getCondition()); Assertions.assertEquals("", httpParameters.getCondition());
} }
@ -48,13 +48,13 @@ public class HttpParametersTest {
+ "\"httpMethod\":\"GET\",\"httpCheckCondition\":\"STATUS_CODE_DEFAULT\",\"condition\":\"\",\"connectTimeout\":\"10000\",\"socketTimeout\":\"10000\"}"; + "\"httpMethod\":\"GET\",\"httpCheckCondition\":\"STATUS_CODE_DEFAULT\",\"condition\":\"\",\"connectTimeout\":\"10000\",\"socketTimeout\":\"10000\"}";
HttpParameters httpParameters = JSONUtils.parseObject(paramData, HttpParameters.class); HttpParameters httpParameters = JSONUtils.parseObject(paramData, HttpParameters.class);
Assert.assertTrue(httpParameters.checkParameters()); Assertions.assertTrue(httpParameters.checkParameters());
Assert.assertEquals(10000,httpParameters.getConnectTimeout()); Assertions.assertEquals(10000, httpParameters.getConnectTimeout());
Assert.assertEquals(10000,httpParameters.getSocketTimeout()); Assertions.assertEquals(10000, httpParameters.getSocketTimeout());
Assert.assertEquals("https://www.baidu.com/",httpParameters.getUrl()); Assertions.assertEquals("https://www.baidu.com/", httpParameters.getUrl());
Assert.assertEquals(HttpMethod.GET,httpParameters.getHttpMethod()); Assertions.assertEquals(HttpMethod.GET, httpParameters.getHttpMethod());
Assert.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT,httpParameters.getHttpCheckCondition()); Assertions.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT, httpParameters.getHttpCheckCondition());
Assert.assertEquals("",httpParameters.getCondition()); Assertions.assertEquals("", httpParameters.getCondition());
} }
@ -64,15 +64,15 @@ public class HttpParametersTest {
+ "\"httpMethod\":\"GET\",\"httpCheckCondition\":\"STATUS_CODE_DEFAULT\",\"condition\":\"\",\"connectTimeout\":\"10000\",\"socketTimeout\":\"10000\"}"; + "\"httpMethod\":\"GET\",\"httpCheckCondition\":\"STATUS_CODE_DEFAULT\",\"condition\":\"\",\"connectTimeout\":\"10000\",\"socketTimeout\":\"10000\"}";
HttpParameters httpParameters = JSONUtils.parseObject(paramData, HttpParameters.class); HttpParameters httpParameters = JSONUtils.parseObject(paramData, HttpParameters.class);
Assert.assertTrue(httpParameters.checkParameters()); Assertions.assertTrue(httpParameters.checkParameters());
Assert.assertEquals(10000,httpParameters.getConnectTimeout()); Assertions.assertEquals(10000, httpParameters.getConnectTimeout());
Assert.assertEquals(10000,httpParameters.getSocketTimeout()); Assertions.assertEquals(10000, httpParameters.getSocketTimeout());
Assert.assertEquals("https://www.baidu.com/",httpParameters.getUrl()); Assertions.assertEquals("https://www.baidu.com/", httpParameters.getUrl());
Assert.assertEquals(HttpMethod.GET,httpParameters.getHttpMethod()); Assertions.assertEquals(HttpMethod.GET, httpParameters.getHttpMethod());
Assert.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT,httpParameters.getHttpCheckCondition()); Assertions.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT, httpParameters.getHttpCheckCondition());
Assert.assertEquals("",httpParameters.getCondition()); Assertions.assertEquals("", httpParameters.getCondition());
Assert.assertEquals(0,httpParameters.getLocalParametersMap().size()); Assertions.assertEquals(0, httpParameters.getLocalParametersMap().size());
Assert.assertEquals(0,httpParameters.getResourceFilesList().size()); Assertions.assertEquals(0, httpParameters.getResourceFilesList().size());
} }
} }

42
dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpTaskTest.java

@ -39,12 +39,12 @@ import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest; import okhttp3.mockwebserver.RecordedRequest;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -52,7 +52,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
/** /**
* Test HttpTask * Test HttpTask
*/ */
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class HttpTaskTest { public class HttpTaskTest {
private static final String CONTENT_TYPE = "Content-Type"; private static final String CONTENT_TYPE = "Content-Type";
@ -65,7 +65,7 @@ public class HttpTaskTest {
private final List<MockWebServer> mockWebServers = new ArrayList<>(); private final List<MockWebServer> mockWebServers = new ArrayList<>();
@After @AfterEach
public void after() { public void after() {
mockWebServers.forEach(IOUtils::closeQuietly); mockWebServers.forEach(IOUtils::closeQuietly);
mockWebServers.clear(); mockWebServers.clear();
@ -83,18 +83,18 @@ public class HttpTaskTest {
headHttpTask.handle(null); headHttpTask.handle(null);
putHttpTask.handle(null); putHttpTask.handle(null);
deleteHttpTask.handle(null); deleteHttpTask.handle(null);
Assert.assertEquals(EXIT_CODE_SUCCESS, getHttpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, getHttpTask.getExitStatusCode());
Assert.assertEquals(EXIT_CODE_SUCCESS, postHttpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, postHttpTask.getExitStatusCode());
Assert.assertEquals(EXIT_CODE_SUCCESS, headHttpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, headHttpTask.getExitStatusCode());
Assert.assertEquals(EXIT_CODE_SUCCESS, putHttpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, putHttpTask.getExitStatusCode());
Assert.assertEquals(EXIT_CODE_SUCCESS, deleteHttpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, deleteHttpTask.getExitStatusCode());
} }
@Test @Test
public void testHandleCheckCodeDefaultError() throws Exception { public void testHandleCheckCodeDefaultError() throws Exception {
HttpTask getHttpTask = generateHttpTask(HttpMethod.GET, HttpStatus.SC_BAD_REQUEST); HttpTask getHttpTask = generateHttpTask(HttpMethod.GET, HttpStatus.SC_BAD_REQUEST);
getHttpTask.handle(null); getHttpTask.handle(null);
Assert.assertEquals(EXIT_CODE_FAILURE, getHttpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_FAILURE, getHttpTask.getExitStatusCode());
} }
@Test @Test
@ -106,8 +106,8 @@ public class HttpTaskTest {
condition, HttpStatus.SC_OK, ""); condition, HttpStatus.SC_OK, "");
httpTask.handle(null); httpTask.handle(null);
httpErrorTask.handle(null); httpErrorTask.handle(null);
Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode());
Assert.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode());
} }
@Test @Test
@ -118,8 +118,8 @@ public class HttpTaskTest {
"success", HttpStatus.SC_OK, "{\"status\": \"failed\"}"); "success", HttpStatus.SC_OK, "{\"status\": \"failed\"}");
httpTask.handle(null); httpTask.handle(null);
httpErrorTask.handle(null); httpErrorTask.handle(null);
Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode());
Assert.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode());
} }
@Test @Test
@ -130,8 +130,8 @@ public class HttpTaskTest {
"failed", HttpStatus.SC_OK, "{\"status\": \"failed\"}"); "failed", HttpStatus.SC_OK, "{\"status\": \"failed\"}");
httpTask.handle(null); httpTask.handle(null);
httpErrorTask.handle(null); httpErrorTask.handle(null);
Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode());
Assert.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_FAILURE, httpErrorTask.getExitStatusCode());
} }
@Test @Test
@ -151,7 +151,7 @@ public class HttpTaskTest {
httpParams, prepareParamsMap, HttpCheckCondition.BODY_CONTAINS, "20220812", httpParams, prepareParamsMap, HttpCheckCondition.BODY_CONTAINS, "20220812",
HttpStatus.SC_OK, ""); HttpStatus.SC_OK, "");
httpTask.handle(null); httpTask.handle(null);
Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode());
} }
@Test @Test
@ -171,7 +171,7 @@ public class HttpTaskTest {
httpParams, prepareParamsMap, HttpCheckCondition.BODY_CONTAINS, "20220812", httpParams, prepareParamsMap, HttpCheckCondition.BODY_CONTAINS, "20220812",
HttpStatus.SC_OK, ""); HttpStatus.SC_OK, "");
httpTask.handle(null); httpTask.handle(null);
Assert.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode());
} }
private String withMockWebServer(String path, int actualResponseCode, private String withMockWebServer(String path, int actualResponseCode,

42
dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/test/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java → dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/test/java/org/apache/dolphinscheduler/plugin/task/java/JavaTaskTest.java

@ -22,6 +22,7 @@ import static org.apache.dolphinscheduler.plugin.task.api.enums.Direct.IN;
import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAR; import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAR;
import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAVA; import static org.apache.dolphinscheduler.plugin.task.java.JavaConstants.RUN_TYPE_JAVA;
import org.apache.dolphinscheduler.plugin.task.api.TaskCallBack;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.model.Property; import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
@ -38,15 +39,19 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class JavaTaskTest { public class JavaTaskTest {
private TaskCallBack taskCallBack = (taskInstanceId, appIds) -> {
};
@Test @Test
public void testGetPubllicClassName() { public void testGetPubllicClassName() {
JavaTask javaTask = runJavaType(); JavaTask javaTask = runJavaType();
Assert.assertEquals(javaTask.getPublicClassName("import java.io.IOException;\n" + Assertions.assertEquals(javaTask.getPublicClassName("import java.io.IOException;\n" +
"public class JavaTaskTest {\n" + "public class JavaTaskTest {\n" +
" public static void main(String[] args) throws IOException {\n" + " public static void main(String[] args) throws IOException {\n" +
" StringBuilder builder = new StringBuilder(\"Hello: \");\n" + " StringBuilder builder = new StringBuilder(\"Hello: \");\n" +
@ -67,7 +72,7 @@ public class JavaTaskTest {
public void buildJarCommand() { public void buildJarCommand() {
String homeBinPath = JavaConstants.JAVA_HOME_VAR + File.separator + "bin" + File.separator; String homeBinPath = JavaConstants.JAVA_HOME_VAR + File.separator + "bin" + File.separator;
JavaTask javaTask = runJarType(); JavaTask javaTask = runJarType();
Assert.assertEquals(javaTask.buildJarCommand(), homeBinPath Assertions.assertEquals(javaTask.buildJarCommand(), homeBinPath
+ "java --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar -jar /tmp/dolphinscheduler/test/executepath/opt/share/jar/main.jar -host 127.0.0.1 -port 8080 -xms:50m"); + "java --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar -jar /tmp/dolphinscheduler/test/executepath/opt/share/jar/main.jar -host 127.0.0.1 -port 8080 -xms:50m");
} }
@ -81,7 +86,7 @@ public class JavaTaskTest {
JavaTask javaTask = runJavaType(); JavaTask javaTask = runJavaType();
String sourceCode = javaTask.buildJavaSourceContent(); String sourceCode = javaTask.buildJavaSourceContent();
String publicClassName = javaTask.getPublicClassName(sourceCode); String publicClassName = javaTask.getPublicClassName(sourceCode);
Assert.assertEquals("JavaTaskTest", publicClassName); Assertions.assertEquals("JavaTaskTest", publicClassName);
String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName);
try { try {
String homeBinPath = JavaConstants.JAVA_HOME_VAR + File.separator + "bin" + File.separator; String homeBinPath = JavaConstants.JAVA_HOME_VAR + File.separator + "bin" + File.separator;
@ -89,7 +94,7 @@ public class JavaTaskTest {
if (Files.exists(path)) { if (Files.exists(path)) {
Files.delete(path); Files.delete(path);
} }
Assert.assertEquals(homeBinPath Assertions.assertEquals(homeBinPath
+ "javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java", + "javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java",
javaTask.buildJavaCompileCommand(sourceCode)); javaTask.buildJavaCompileCommand(sourceCode));
} finally { } finally {
@ -108,17 +113,18 @@ public class JavaTaskTest {
**/ **/
@Test @Test
public void buildJavaCommand() throws Exception { public void buildJavaCommand() throws Exception {
String wantJavaCommand = "${JAVA_HOME}/bin/javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java;${JAVA_HOME}/bin/java --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar JavaTaskTest -host 127.0.0.1 -port 8080 -xms:50m"; String wantJavaCommand =
"${JAVA_HOME}/bin/javac --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar /tmp/dolphinscheduler/test/executepath/JavaTaskTest.java;${JAVA_HOME}/bin/java --class-path .:/tmp/dolphinscheduler/test/executepath:/tmp/dolphinscheduler/test/executepath/opt/share/jar/resource2.jar JavaTaskTest -host 127.0.0.1 -port 8080 -xms:50m";
JavaTask javaTask = runJavaType(); JavaTask javaTask = runJavaType();
String sourceCode = javaTask.buildJavaSourceContent(); String sourceCode = javaTask.buildJavaSourceContent();
String publicClassName = javaTask.getPublicClassName(sourceCode); String publicClassName = javaTask.getPublicClassName(sourceCode);
Assert.assertEquals("JavaTaskTest", publicClassName); Assertions.assertEquals("JavaTaskTest", publicClassName);
String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName);
Path path = Paths.get(fileName); Path path = Paths.get(fileName);
if (Files.exists(path)) { if (Files.exists(path)) {
Files.delete(path); Files.delete(path);
} }
Assert.assertEquals(wantJavaCommand, javaTask.buildJavaCommand()); Assertions.assertEquals(wantJavaCommand, javaTask.buildJavaCommand());
} }
/** /**
@ -126,13 +132,15 @@ public class JavaTaskTest {
* @return void * @return void
* @throws IOException * @throws IOException
**/ **/
@Test(expected = JavaSourceFileExistException.class) @Test
public void coverJavaSourceFileExistException() throws IOException { public void coverJavaSourceFileExistException() throws IOException {
JavaTask javaTask = runJavaType(); JavaTask javaTask = runJavaType();
String sourceCode = javaTask.buildJavaSourceContent(); String sourceCode = javaTask.buildJavaSourceContent();
String publicClassName = javaTask.getPublicClassName(sourceCode); String publicClassName = javaTask.getPublicClassName(sourceCode);
Assert.assertEquals("JavaTaskTest", publicClassName); Assertions.assertEquals("JavaTaskTest", publicClassName);
String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName); String fileName = javaTask.buildJavaSourceCodeFileFullName(publicClassName);
Assertions.assertThrows(JavaSourceFileExistException.class, () -> {
try { try {
Path path = Paths.get(fileName); Path path = Paths.get(fileName);
if (!Files.exists(path)) { if (!Files.exists(path)) {
@ -145,6 +153,7 @@ public class JavaTaskTest {
Files.delete(path); Files.delete(path);
} }
} }
});
} }
/** /**
@ -152,10 +161,12 @@ public class JavaTaskTest {
* *
* @return void * @return void
**/ **/
@Test(expected = PublicClassNotFoundException.class) @Test
public void coverPublicClassNotFoundException() { public void coverPublicClassNotFoundException() {
Assertions.assertThrows(PublicClassNotFoundException.class, () -> {
JavaTask javaTask = runJavaType(); JavaTask javaTask = runJavaType();
javaTask.getPublicClassName(""); javaTask.getPublicClassName("");
});
} }
/** /**
@ -164,14 +175,17 @@ public class JavaTaskTest {
* @return void * @return void
* @throws Exception * @throws Exception
**/ **/
@Test(expected = RunTypeNotFoundException.class) @Test
public void coverRunTypeNotFoundException() throws Exception { public void coverRunTypeNotFoundException() throws Exception {
JavaTask javaTask = runJavaType(); JavaTask javaTask = runJavaType();
Field javaParameters = JavaTask.class.getDeclaredField("javaParameters"); Field javaParameters = JavaTask.class.getDeclaredField("javaParameters");
javaParameters.setAccessible(true); javaParameters.setAccessible(true);
((JavaParameters) (javaParameters.get(javaTask))).setRunType(""); ((JavaParameters) (javaParameters.get(javaTask))).setRunType("");
javaTask.handle();
Assertions.assertThrows(RunTypeNotFoundException.class, () -> {
javaTask.handle(taskCallBack);
javaTask.getPublicClassName(""); javaTask.getPublicClassName("");
});
} }
/** /**

16
dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/test/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTaskTest.java

@ -25,13 +25,13 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.spi.utils.DateUtils; import org.apache.dolphinscheduler.spi.utils.DateUtils;
import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class JupyterTaskTest { public class JupyterTaskTest {
private static final String EXPECTED_JUPYTER_TASK_COMMAND_USE_LOCAL_CONDA_ENV = private static final String EXPECTED_JUPYTER_TASK_COMMAND_USE_LOCAL_CONDA_ENV =
@ -93,7 +93,7 @@ public class JupyterTaskTest {
String jupyterTaskParameters = buildJupyterTaskUseLocalCondaEnvCommand(); String jupyterTaskParameters = buildJupyterTaskUseLocalCondaEnvCommand();
JupyterTask jupyterTask = prepareJupyterTaskForTest(jupyterTaskParameters); JupyterTask jupyterTask = prepareJupyterTaskForTest(jupyterTaskParameters);
jupyterTask.init(); jupyterTask.init();
Assert.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_LOCAL_CONDA_ENV); Assertions.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_LOCAL_CONDA_ENV);
} }
@Test @Test
@ -101,7 +101,7 @@ public class JupyterTaskTest {
String jupyterTaskParameters = buildJupyterTaskUsePackedCondaEnvCommand(); String jupyterTaskParameters = buildJupyterTaskUsePackedCondaEnvCommand();
JupyterTask jupyterTask = prepareJupyterTaskForTest(jupyterTaskParameters); JupyterTask jupyterTask = prepareJupyterTaskForTest(jupyterTaskParameters);
jupyterTask.init(); jupyterTask.init();
Assert.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_PACKED_CONDA_ENV); Assertions.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_PACKED_CONDA_ENV);
} }
@Test @Test
@ -111,7 +111,7 @@ public class JupyterTaskTest {
Mockito.mockStatic(DateUtils.class); Mockito.mockStatic(DateUtils.class);
when(DateUtils.getTimestampString()).thenReturn("123456789"); when(DateUtils.getTimestampString()).thenReturn("123456789");
jupyterTask.init(); jupyterTask.init();
Assert.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_PIP_REQUIREMENTS); Assertions.assertEquals(jupyterTask.buildCommand(), EXPECTED_JUPYTER_TASK_COMMAND_USE_PIP_REQUIREMENTS);
} }
private JupyterTask prepareJupyterTaskForTest(final String jupyterTaskParameters) { private JupyterTask prepareJupyterTaskForTest(final String jupyterTaskParameters) {

24
dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sParametersTest.java

@ -16,20 +16,22 @@
*/ */
package org.apache.dolphinscheduler.plugin.task.k8s; package org.apache.dolphinscheduler.plugin.task.k8s;
import org.apache.dolphinscheduler.plugin.task.api.parameters.K8sTaskParameters; import org.apache.dolphinscheduler.plugin.task.api.parameters.K8sTaskParameters;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class K8sParametersTest { public class K8sParametersTest {
private K8sTaskParameters k8sTaskParameters = null; private K8sTaskParameters k8sTaskParameters = null;
private final String image = "ds-dev"; private final String image = "ds-dev";
private final String namespace = "{\"name\":\"default\",\"cluster\":\"lab\"}"; private final String namespace = "{\"name\":\"default\",\"cluster\":\"lab\"}";
private final double minCpuCores = 2; private final double minCpuCores = 2;
private final double minMemorySpace = 10; private final double minMemorySpace = 10;
@Before @BeforeEach
public void before() { public void before() {
k8sTaskParameters = new K8sTaskParameters(); k8sTaskParameters = new K8sTaskParameters();
k8sTaskParameters.setImage(image); k8sTaskParameters.setImage(image);
@ -40,21 +42,21 @@ public class K8sParametersTest {
@Test @Test
public void testCheckParameterNormal() { public void testCheckParameterNormal() {
Assert.assertTrue(k8sTaskParameters.checkParameters()); Assertions.assertTrue(k8sTaskParameters.checkParameters());
} }
@Test @Test
public void testGetResourceFilesListNormal() { public void testGetResourceFilesListNormal() {
Assert.assertNotNull(k8sTaskParameters.getResourceFilesList()); Assertions.assertNotNull(k8sTaskParameters.getResourceFilesList());
Assert.assertEquals(0, k8sTaskParameters.getResourceFilesList().size()); Assertions.assertEquals(0, k8sTaskParameters.getResourceFilesList().size());
} }
@Test @Test
public void testK8sParameters() { public void testK8sParameters() {
Assert.assertEquals(image, k8sTaskParameters.getImage()); Assertions.assertEquals(image, k8sTaskParameters.getImage());
Assert.assertEquals(namespace, k8sTaskParameters.getNamespace()); Assertions.assertEquals(namespace, k8sTaskParameters.getNamespace());
Assert.assertEquals(0, Double.compare(minCpuCores, k8sTaskParameters.getMinCpuCores())); Assertions.assertEquals(0, Double.compare(minCpuCores, k8sTaskParameters.getMinCpuCores()));
Assert.assertEquals(0,Double.compare(minMemorySpace, k8sTaskParameters.getMinMemorySpace())); Assertions.assertEquals(0, Double.compare(minMemorySpace, k8sTaskParameters.getMinMemorySpace()));
} }
} }

19
dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java

@ -27,11 +27,12 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class K8sTaskTest { public class K8sTaskTest {
private K8sTaskParameters k8sTaskParameters = null; private K8sTaskParameters k8sTaskParameters = null;
private K8sTask k8sTask = null; private K8sTask k8sTask = null;
@ -47,7 +48,7 @@ public class K8sTaskTest {
private final String DAY = "day"; private final String DAY = "day";
private final String date = "20220507"; private final String date = "20220507";
@Before @BeforeEach
public void before() { public void before() {
k8sTaskParameters = new K8sTaskParameters(); k8sTaskParameters = new K8sTaskParameters();
k8sTaskParameters.setImage(image); k8sTaskParameters.setImage(image);
@ -78,16 +79,18 @@ public class K8sTaskTest {
@Test @Test
public void testBuildCommandNormal() { public void testBuildCommandNormal() {
String expectedStr = "{\"image\":\"ds-dev\",\"namespaceName\":\"default\",\"clusterName\":\"lab\",\"minCpuCores\":2.0,\"minMemorySpace\":10.0,\"paramsMap\":{\"day\":\"20220507\"}}"; String expectedStr =
"{\"image\":\"ds-dev\",\"namespaceName\":\"default\",\"clusterName\":\"lab\",\"minCpuCores\":2.0,\"minMemorySpace\":10.0,\"paramsMap\":{\"day\":\"20220507\"}}";
String commandStr = k8sTask.buildCommand(); String commandStr = k8sTask.buildCommand();
Assert.assertEquals(expectedStr, commandStr); Assertions.assertEquals(expectedStr, commandStr);
} }
@Test @Test
public void testGetParametersNormal() { public void testGetParametersNormal() {
String expectedStr = "K8sTaskParameters{image='ds-dev', namespace='{\"name\":\"default\",\"cluster\":\"lab\"}', minCpuCores=2.0, minMemorySpace=10.0}"; String expectedStr =
"K8sTaskParameters{image='ds-dev', namespace='{\"name\":\"default\",\"cluster\":\"lab\"}', minCpuCores=2.0, minMemorySpace=10.0}";
String result = k8sTask.getParameters().toString(); String result = k8sTask.getParameters().toString();
Assert.assertEquals(expectedStr, result); Assertions.assertEquals(expectedStr, result);
} }
} }

66
dolphinscheduler-task-plugin/dolphinscheduler-task-mlflow/src/test/java/org/apache/dolphinler/plugin/task/mlflow/MlflowTaskTest.java

@ -25,29 +25,31 @@ import org.apache.dolphinscheduler.plugin.task.mlflow.MlflowTask;
import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.utils.PropertyUtils; import org.apache.dolphinscheduler.spi.utils.PropertyUtils;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedStatic; import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class MlflowTaskTest { public class MlflowTaskTest {
private static final Logger logger = LoggerFactory.getLogger(MlflowTask.class); private static final Logger logger = LoggerFactory.getLogger(MlflowTask.class);
private MockedStatic<PropertyUtils> propertyUtilsMockedStatic; private MockedStatic<PropertyUtils> propertyUtilsMockedStatic;
@Before @BeforeEach
public void init() { public void init() {
propertyUtilsMockedStatic = Mockito.mockStatic(PropertyUtils.class); propertyUtilsMockedStatic = Mockito.mockStatic(PropertyUtils.class);
propertyUtilsMockedStatic.when(() -> PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_VERSION_KEY)).thenReturn("main"); propertyUtilsMockedStatic.when(() -> PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_VERSION_KEY))
.thenReturn("main");
} }
@After @AfterEach
public void clean() { public void clean() {
propertyUtilsMockedStatic.close(); propertyUtilsMockedStatic.close();
} }
@ -62,33 +64,39 @@ public class MlflowTaskTest {
@Test @Test
public void testGetPresetRepositoryData() { public void testGetPresetRepositoryData() {
Assert.assertEquals("https://github.com/apache/dolphinscheduler-mlflow", MlflowTask.getPresetRepository()); Assertions.assertEquals("https://github.com/apache/dolphinscheduler-mlflow", MlflowTask.getPresetRepository());
Assert.assertEquals("main", MlflowTask.getPresetRepositoryVersion()); Assertions.assertEquals("main", MlflowTask.getPresetRepositoryVersion());
String definedRepository = "https://github.com/<MY-ID>/dolphinscheduler-mlflow"; String definedRepository = "https://github.com/<MY-ID>/dolphinscheduler-mlflow";
Mockito.when(PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_KEY)).thenAnswer(invocation -> definedRepository); Mockito.when(PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_KEY))
Assert.assertEquals(definedRepository, MlflowTask.getPresetRepository()); .thenAnswer(invocation -> definedRepository);
Assertions.assertEquals(definedRepository, MlflowTask.getPresetRepository());
String definedRepositoryVersion = "dev"; String definedRepositoryVersion = "dev";
Mockito.when(PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_VERSION_KEY)).thenAnswer(invocation -> definedRepositoryVersion); Mockito.when(PropertyUtils.getString(MlflowConstants.PRESET_REPOSITORY_VERSION_KEY))
Assert.assertEquals(definedRepositoryVersion, MlflowTask.getPresetRepositoryVersion()); .thenAnswer(invocation -> definedRepositoryVersion);
Assertions.assertEquals(definedRepositoryVersion, MlflowTask.getPresetRepositoryVersion());
} }
@Test @Test
public void testGetVersionString() { public void testGetVersionString() {
Assert.assertEquals("--version=main", MlflowTask.getVersionString("main", "https://github.com/apache/dolphinscheduler-mlflow")); Assertions.assertEquals("--version=main",
Assert.assertEquals("--version=master", MlflowTask.getVersionString("master", "https://github.com/apache/dolphinscheduler-mlflow")); MlflowTask.getVersionString("main", "https://github.com/apache/dolphinscheduler-mlflow"));
Assert.assertEquals("--version=main", MlflowTask.getVersionString("main", "git@github.com:apache/dolphinscheduler-mlflow.git")); Assertions.assertEquals("--version=master",
Assert.assertEquals("--version=master", MlflowTask.getVersionString("master", "git@github.com:apache/dolphinscheduler-mlflow.git")); MlflowTask.getVersionString("master", "https://github.com/apache/dolphinscheduler-mlflow"));
Assert.assertEquals("", MlflowTask.getVersionString("main", "/tmp/dolphinscheduler-mlflow")); Assertions.assertEquals("--version=main",
Assert.assertEquals("", MlflowTask.getVersionString("master", "/tmp/dolphinscheduler-mlflow")); MlflowTask.getVersionString("main", "git@github.com:apache/dolphinscheduler-mlflow.git"));
Assertions.assertEquals("--version=master",
MlflowTask.getVersionString("master", "git@github.com:apache/dolphinscheduler-mlflow.git"));
Assertions.assertEquals("", MlflowTask.getVersionString("main", "/tmp/dolphinscheduler-mlflow"));
Assertions.assertEquals("", MlflowTask.getVersionString("master", "/tmp/dolphinscheduler-mlflow"));
} }
@Test @Test
public void testInitBasicAlgorithmTask() { public void testInitBasicAlgorithmTask() {
MlflowTask mlflowTask = initTask(createBasicAlgorithmParameters()); MlflowTask mlflowTask = initTask(createBasicAlgorithmParameters());
Assert.assertEquals(mlflowTask.buildCommand(), Assertions.assertEquals(mlflowTask.buildCommand(),
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n"
+ "data_path=/data/iris.csv\n" + "data_path=/data/iris.csv\n"
+ "repo=https://github.com/apache/dolphinscheduler-mlflow#Project-BasicAlgorithm\n" + "repo=https://github.com/apache/dolphinscheduler-mlflow#Project-BasicAlgorithm\n"
@ -105,7 +113,7 @@ public class MlflowTaskTest {
@Test @Test
public void testInitAutoMLTask() { public void testInitAutoMLTask() {
MlflowTask mlflowTask = initTask(createAutoMLParameters()); MlflowTask mlflowTask = initTask(createAutoMLParameters());
Assert.assertEquals(mlflowTask.buildCommand(), Assertions.assertEquals(mlflowTask.buildCommand(),
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n"
+ "data_path=/data/iris.csv\n" + "data_path=/data/iris.csv\n"
+ "repo=https://github.com/apache/dolphinscheduler-mlflow#Project-AutoML\n" + "repo=https://github.com/apache/dolphinscheduler-mlflow#Project-AutoML\n"
@ -123,7 +131,7 @@ public class MlflowTaskTest {
MlflowTask mlflowTask = initTask(createCustomProjectParameters()); MlflowTask mlflowTask = initTask(createCustomProjectParameters());
// Version will be set if parameter.mlflowProjectVersion is empty // Version will be set if parameter.mlflowProjectVersion is empty
Assert.assertEquals(mlflowTask.buildCommand(), Assertions.assertEquals(mlflowTask.buildCommand(),
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n"
+ "repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n" + "repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n"
+ "mlflow run $repo " + "mlflow run $repo "
@ -134,7 +142,7 @@ public class MlflowTaskTest {
// Version will be set if repository is remote path // Version will be set if repository is remote path
mlflowTask.getParameters().setMlflowProjectVersion("dev"); mlflowTask.getParameters().setMlflowProjectVersion("dev");
Assert.assertEquals(mlflowTask.buildCommand(), Assertions.assertEquals(mlflowTask.buildCommand(),
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n"
+ "repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n" + "repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n"
+ "mlflow run $repo " + "mlflow run $repo "
@ -146,7 +154,7 @@ public class MlflowTaskTest {
// Version will not be set if repository is local path // Version will not be set if repository is local path
mlflowTask.getParameters().setMlflowProjectRepository("/tmp/dolphinscheduler-mlflow"); mlflowTask.getParameters().setMlflowProjectRepository("/tmp/dolphinscheduler-mlflow");
Assert.assertEquals(mlflowTask.buildCommand(), Assertions.assertEquals(mlflowTask.buildCommand(),
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n"
+ "repo=/tmp/dolphinscheduler-mlflow\n" + "repo=/tmp/dolphinscheduler-mlflow\n"
+ "mlflow run $repo " + "mlflow run $repo "
@ -160,7 +168,7 @@ public class MlflowTaskTest {
@Test @Test
public void testModelsDeployMlflow() { public void testModelsDeployMlflow() {
MlflowTask mlflowTask = initTask(createModelDeplyMlflowParameters()); MlflowTask mlflowTask = initTask(createModelDeplyMlflowParameters());
Assert.assertEquals(mlflowTask.buildCommand(), Assertions.assertEquals(mlflowTask.buildCommand(),
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n"
+ "mlflow models serve -m models:/model/1 --port 7000 -h 0.0.0.0"); + "mlflow models serve -m models:/model/1 --port 7000 -h 0.0.0.0");
} }
@ -168,7 +176,7 @@ public class MlflowTaskTest {
@Test @Test
public void testModelsDeployDocker() { public void testModelsDeployDocker() {
MlflowTask mlflowTask = initTask(createModelDeplyDockerParameters()); MlflowTask mlflowTask = initTask(createModelDeplyDockerParameters());
Assert.assertEquals(mlflowTask.buildCommand(), Assertions.assertEquals(mlflowTask.buildCommand(),
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" "export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n"
+ "mlflow models build-docker -m models:/model/1 -n mlflow/model:1 --enable-mlserver\n" + "mlflow models build-docker -m models:/model/1 -n mlflow/model:1 --enable-mlserver\n"
+ "docker rm -f ds-mlflow-model-1\n" + "docker rm -f ds-mlflow-model-1\n"

17
dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java

@ -25,12 +25,14 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
public class OpenmldbTaskTest { public class OpenmldbTaskTest {
static class MockOpenmldbTask extends OpenmldbTask { static class MockOpenmldbTask extends OpenmldbTask {
/** /**
* constructor * constructor
* *
@ -55,7 +57,7 @@ public class OpenmldbTaskTest {
OpenmldbTask openmldbTask = createOpenmldbTask(); OpenmldbTask openmldbTask = createOpenmldbTask();
String pythonFile = "test.py"; String pythonFile = "test.py";
String result1 = openmldbTask.buildPythonExecuteCommand(pythonFile); String result1 = openmldbTask.buildPythonExecuteCommand(pythonFile);
Assert.assertEquals("python3 test.py", result1); Assertions.assertEquals("python3 test.py", result1);
} }
@Test @Test
@ -74,11 +76,11 @@ public class OpenmldbTaskTest {
OpenmldbTask openmldbTask = new OpenmldbTask(taskExecutionContext); OpenmldbTask openmldbTask = new OpenmldbTask(taskExecutionContext);
openmldbTask.init(); openmldbTask.init();
OpenmldbParameters internal = (OpenmldbParameters) openmldbTask.getParameters(); OpenmldbParameters internal = (OpenmldbParameters) openmldbTask.getParameters();
Assert.assertNotNull(internal); Assertions.assertNotNull(internal);
Assert.assertEquals(internal.getExecuteMode(), "offline"); Assertions.assertEquals(internal.getExecuteMode(), "offline");
String result1 = openmldbTask.buildPythonScriptContent(); String result1 = openmldbTask.buildPythonScriptContent();
Assert.assertEquals("import openmldb\n" Assertions.assertEquals("import openmldb\n"
+ "import sqlalchemy as db\n" + "import sqlalchemy as db\n"
+ "engine = db.create_engine('openmldb:///?zk=localhost:2181&zkPath=dolphinscheduler')\n" + "engine = db.create_engine('openmldb:///?zk=localhost:2181&zkPath=dolphinscheduler')\n"
+ "con = engine.connect()\n" + "con = engine.connect()\n"
@ -87,8 +89,7 @@ public class OpenmldbTaskTest {
+ "con.execute(\"set @@job_timeout=1800000\")\n" + "con.execute(\"set @@job_timeout=1800000\")\n"
+ "con.execute(\"select * from users\\n-- some comment\\ninner join order on users.order_id = " + "con.execute(\"select * from users\\n-- some comment\\ninner join order on users.order_id = "
+ "order.id\")\n" + "order.id\")\n"
+ "con.execute(\"select * from users\")\n" + "con.execute(\"select * from users\")\n", result1);
, result1);
} }
} }

29
dolphinscheduler-task-plugin/dolphinscheduler-task-pigeon/src/test/java/org/apache/dolphinscheduler/plugin/task/pigeon/PigeonTaskTest.java

@ -22,21 +22,20 @@ import static com.github.dreamhead.moco.MocoJsonRunner.jsonHttpServer;
import static com.github.dreamhead.moco.Runner.running; import static com.github.dreamhead.moco.Runner.running;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.junit.jupiter.api.Assertions;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -50,7 +49,7 @@ public class PigeonTaskTest {
private TaskExecutionContext taskExecutionContext; private TaskExecutionContext taskExecutionContext;
@Before @BeforeEach
public void before() throws Exception { public void before() throws Exception {
String taskParams = "{\"targetJobName\":\"mysql_elastic\"}"; String taskParams = "{\"targetJobName\":\"mysql_elastic\"}";
@ -80,22 +79,22 @@ public class PigeonTaskTest {
public void testGetTISConfigParams() { public void testGetTISConfigParams() {
PigeonConfig cfg = PigeonConfig.getInstance(); PigeonConfig cfg = PigeonConfig.getInstance();
String tisHost = "127.0.0.1:8080"; String tisHost = "127.0.0.1:8080";
Assert.assertEquals("http://127.0.0.1:8080/tjs/coredefine/coredefine.ajax", cfg.getJobTriggerUrl(tisHost)); Assertions.assertEquals("http://127.0.0.1:8080/tjs/coredefine/coredefine.ajax", cfg.getJobTriggerUrl(tisHost));
String jobName = "mysql_elastic"; String jobName = "mysql_elastic";
int taskId = 123; int taskId = 123;
Assert.assertEquals( Assertions.assertEquals(
"ws://" + tisHost + "/tjs/download/logfeedback?logtype=full&collection=mysql_elastic&taskid=" + taskId, "ws://" + tisHost + "/tjs/download/logfeedback?logtype=full&collection=mysql_elastic&taskid=" + taskId,
cfg.getJobLogsFetchUrl(tisHost, jobName, taskId)); cfg.getJobLogsFetchUrl(tisHost, jobName, taskId));
Assert.assertEquals("action=datax_action&emethod=trigger_fullbuild_task", cfg.getJobTriggerPostBody()); Assertions.assertEquals("action=datax_action&emethod=trigger_fullbuild_task", cfg.getJobTriggerPostBody());
Assert.assertEquals( Assertions.assertEquals(
"http://127.0.0.1:8080/tjs/config/config.ajax?action=collection_action&emethod=get_task_status", "http://127.0.0.1:8080/tjs/config/config.ajax?action=collection_action&emethod=get_task_status",
cfg.getJobStatusUrl(tisHost)); cfg.getJobStatusUrl(tisHost));
Assert.assertEquals("{\n taskid: " + taskId + "\n, log: false }", cfg.getJobStatusPostBody(taskId)); Assertions.assertEquals("{\n taskid: " + taskId + "\n, log: false }", cfg.getJobStatusPostBody(taskId));
Assert.assertEquals("action=core_action&event_submit_do_cancel_task=y&taskid=" + taskId, Assertions.assertEquals("action=core_action&event_submit_do_cancel_task=y&taskid=" + taskId,
cfg.getJobCancelPostBody(taskId)); cfg.getJobCancelPostBody(taskId));
} }
@ -104,7 +103,7 @@ public class PigeonTaskTest {
try { try {
pigeonTask.init(); pigeonTask.init();
} catch (Exception e) { } catch (Exception e) {
Assert.fail(e.getMessage()); Assertions.fail(e.getMessage());
} }
} }
@ -116,7 +115,7 @@ public class PigeonTaskTest {
running(server, () -> { running(server, () -> {
pigeonTask.handle(null); pigeonTask.handle(null);
Assert.assertEquals("PIGEON execute be success", TaskExecutionStatus.SUCCESS, pigeonTask.getExitStatus()); Assertions.assertEquals(TaskExecutionStatus.SUCCESS, pigeonTask.getExitStatus());
}); });
} }
@ -137,7 +136,7 @@ public class PigeonTaskTest {
// try { // try {
// tisTask.cancelApplication(true); // tisTask.cancelApplication(true);
// } catch (Exception e) { // } catch (Exception e) {
// Assert.fail(e.getMessage()); // Assertions.fail(e.getMessage());
// } // }
// } // }

6
dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java

@ -17,15 +17,15 @@
package org.apache.dolphinscheduler.plugin.task.python; package org.apache.dolphinscheduler.plugin.task.python;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PythonTaskTest { public class PythonTaskTest {
@Test @Test
public void buildPythonExecuteCommand() throws Exception { public void buildPythonExecuteCommand() throws Exception {
PythonTask pythonTask = createPythonTask(); PythonTask pythonTask = createPythonTask();
Assert.assertEquals("${PYTHON_HOME} test.py", pythonTask.buildPythonExecuteCommand("test.py")); Assertions.assertEquals("${PYTHON_HOME} test.py", pythonTask.buildPythonExecuteCommand("test.py"));
} }
private PythonTask createPythonTask() { private PythonTask createPythonTask() {

72
dolphinscheduler-task-plugin/dolphinscheduler-task-pytorch/src/test/java/org/apache/dolphinscheduler/plugin/task/pytorch/PytorchTaskTest.java

@ -18,13 +18,10 @@
package org.apache.dolphinscheduler.plugin.task.pytorch; package org.apache.dolphinscheduler.plugin.task.pytorch;
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.RWXR_XR_X; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.RWXR_XR_X;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContextCacheManager; import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContextCacheManager;
import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.utils.PropertyUtils;
import org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.SystemUtils;
@ -36,18 +33,16 @@ import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.PosixFilePermissions;
import java.util.Date;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class PytorchTaskTest { public class PytorchTaskTest {
private final String pythonPath = "."; private final String pythonPath = ".";
@ -60,37 +55,42 @@ public class PytorchTaskTest {
envManager.setPythonEnvTool(PythonEnvManager.ENV_TOOL_CONDA); envManager.setPythonEnvTool(PythonEnvManager.ENV_TOOL_CONDA);
envManager.setCondaPythonVersion("3.9"); envManager.setCondaPythonVersion("3.9");
String condaEnvCommand39 = envManager.getBuildEnvCommand(requirementPath); String condaEnvCommand39 = envManager.getBuildEnvCommand(requirementPath);
Assert.assertEquals(condaEnvCommand39, "conda create -y python=3.9 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r " + requirementPath); Assertions.assertEquals(condaEnvCommand39,
"conda create -y python=3.9 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r "
+ requirementPath);
envManager.setCondaPythonVersion("3.8"); envManager.setCondaPythonVersion("3.8");
String condaEnvCommand38 = envManager.getBuildEnvCommand(requirementPath); String condaEnvCommand38 = envManager.getBuildEnvCommand(requirementPath);
Assert.assertEquals(condaEnvCommand38, "conda create -y python=3.8 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r " + requirementPath); Assertions.assertEquals(condaEnvCommand38,
"conda create -y python=3.8 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r "
+ requirementPath);
envManager.setPythonEnvTool(PythonEnvManager.ENV_TOOL_VENV); envManager.setPythonEnvTool(PythonEnvManager.ENV_TOOL_VENV);
String venvEnvCommand = envManager.getBuildEnvCommand(requirementPath); String venvEnvCommand = envManager.getBuildEnvCommand(requirementPath);
Assert.assertEquals(venvEnvCommand, "virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r " + requirementPath); Assertions.assertEquals(venvEnvCommand,
"virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r "
+ requirementPath);
} }
@Test @Test
public void testGitProject() { public void testGitProject() {
assertFalse(GitProjectManager.isGitPath("dolphinscheduler/test")); Assertions.assertFalse(GitProjectManager.isGitPath("dolphinscheduler/test"));
assertFalse(GitProjectManager.isGitPath("/dolphinscheduler/test")); Assertions.assertFalse(GitProjectManager.isGitPath("/dolphinscheduler/test"));
assertTrue(GitProjectManager.isGitPath("https://github.com/apache/dolphinscheduler.git")); Assertions.assertTrue(GitProjectManager.isGitPath("https://github.com/apache/dolphinscheduler.git"));
assertTrue(GitProjectManager.isGitPath("git@github.com:apache/dolphinscheduler.git")); Assertions.assertTrue(GitProjectManager.isGitPath("git@github.com:apache/dolphinscheduler.git"));
assertTrue(GitProjectManager.isGitPath("git@github.com:apache/dolphinscheduler.git#doc")); Assertions.assertTrue(GitProjectManager.isGitPath("git@github.com:apache/dolphinscheduler.git#doc"));
GitProjectManager gpm1 = new GitProjectManager(); GitProjectManager gpm1 = new GitProjectManager();
gpm1.setPath("git@github.com:apache/dolphinscheduler.git#doc"); gpm1.setPath("git@github.com:apache/dolphinscheduler.git#doc");
Assert.assertEquals("git@github.com:apache/dolphinscheduler.git", gpm1.getGitUrl()); Assertions.assertEquals("git@github.com:apache/dolphinscheduler.git", gpm1.getGitUrl());
Assert.assertEquals("./GIT_PROJECT/doc", gpm1.getGitLocalPath()); Assertions.assertEquals("./GIT_PROJECT/doc", gpm1.getGitLocalPath());
GitProjectManager gpm2 = new GitProjectManager(); GitProjectManager gpm2 = new GitProjectManager();
gpm2.setPath("git@github.com:apache/dolphinscheduler.git"); gpm2.setPath("git@github.com:apache/dolphinscheduler.git");
Assert.assertEquals("git@github.com:apache/dolphinscheduler.git", gpm2.getGitUrl()); Assertions.assertEquals("git@github.com:apache/dolphinscheduler.git", gpm2.getGitUrl());
Assert.assertEquals("./GIT_PROJECT", gpm2.getGitLocalPath()); Assertions.assertEquals("./GIT_PROJECT", gpm2.getGitLocalPath());
} }
@ -101,25 +101,24 @@ public class PytorchTaskTest {
parameters.setScriptParams("--epochs=1 --dry-run"); parameters.setScriptParams("--epochs=1 --dry-run");
PytorchTask task1 = initTask(parameters); PytorchTask task1 = initTask(parameters);
Assert.assertEquals(task1.buildPythonExecuteCommand(), Assertions.assertEquals(task1.buildPythonExecuteCommand(),
"export PYTHONPATH=.\n" + "export PYTHONPATH=.\n" +
"${PYTHON_HOME} main.py --epochs=1 --dry-run"); "${PYTHON_HOME} main.py --epochs=1 --dry-run");
parameters.setPythonCommand(""); parameters.setPythonCommand("");
PytorchTask task2 = initTask(parameters); PytorchTask task2 = initTask(parameters);
Assert.assertEquals(task2.buildPythonExecuteCommand(), Assertions.assertEquals(task2.buildPythonExecuteCommand(),
"export PYTHONPATH=.\n" + "export PYTHONPATH=.\n" +
"${PYTHON_HOME} main.py --epochs=1 --dry-run"); "${PYTHON_HOME} main.py --epochs=1 --dry-run");
parameters.setPythonCommand("/usr/bin/python"); parameters.setPythonCommand("/usr/bin/python");
PytorchTask task3 = initTask(parameters); PytorchTask task3 = initTask(parameters);
Assert.assertEquals(task3.buildPythonExecuteCommand(), Assertions.assertEquals(task3.buildPythonExecuteCommand(),
"export PYTHONPATH=.\n" + "export PYTHONPATH=.\n" +
"/usr/bin/python main.py --epochs=1 --dry-run"); "/usr/bin/python main.py --epochs=1 --dry-run");
} }
@Test @Test
public void testBuildPythonCommandWithCreateCondeEnv() throws Exception { public void testBuildPythonCommandWithCreateCondeEnv() throws Exception {
PytorchParameters parameters = new PytorchParameters(); PytorchParameters parameters = new PytorchParameters();
@ -132,9 +131,10 @@ public class PytorchTaskTest {
parameters.setScriptParams("--epochs=1 --dry-run"); parameters.setScriptParams("--epochs=1 --dry-run");
PytorchTask task = initTask(parameters); PytorchTask task = initTask(parameters);
Assert.assertEquals(task.buildPythonExecuteCommand(), Assertions.assertEquals(task.buildPythonExecuteCommand(),
"export PYTHONPATH=.\n" + "export PYTHONPATH=.\n" +
"conda create -y python=3.6 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r requirements.txt\n" + "conda create -y python=3.6 -p ./venv && source activate ./venv && ./venv/bin/python -m pip install -r requirements.txt\n"
+
"./venv/bin/python main.py --epochs=1 --dry-run"); "./venv/bin/python main.py --epochs=1 --dry-run");
} }
@ -149,9 +149,10 @@ public class PytorchTaskTest {
parameters.setScriptParams("--epochs=1 --dry-run"); parameters.setScriptParams("--epochs=1 --dry-run");
PytorchTask task = initTask(parameters); PytorchTask task = initTask(parameters);
Assert.assertEquals(task.buildPythonExecuteCommand(), Assertions.assertEquals(task.buildPythonExecuteCommand(),
"export PYTHONPATH=.\n" + "export PYTHONPATH=.\n" +
"virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r requirements.txt\n" + "virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r requirements.txt\n"
+
"./venv/bin/python main.py --epochs=1 --dry-run"); "./venv/bin/python main.py --epochs=1 --dry-run");
} }
@ -177,14 +178,15 @@ public class PytorchTaskTest {
createFile(scriptFile); createFile(scriptFile);
String expected = "export PYTHONPATH=%s\n" + String expected = "export PYTHONPATH=%s\n" +
"virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r %s\n" + "virtualenv -p ${PYTHON_HOME} ./venv && source ./venv/bin/activate && ./venv/bin/python -m pip install -r %s\n"
+
"./venv/bin/python %s"; "./venv/bin/python %s";
System.out.println(task.buildPythonExecuteCommand()); System.out.println(task.buildPythonExecuteCommand());
Assert.assertEquals(String.format(expected, pythonPath, requirementFile, scriptFile), task.buildPythonExecuteCommand()); Assertions.assertEquals(String.format(expected, pythonPath, requirementFile, scriptFile),
task.buildPythonExecuteCommand());
} }
private PytorchTask initTask(PytorchParameters pytorchParameters) { private PytorchTask initTask(PytorchParameters pytorchParameters) {
TaskExecutionContext taskExecutionContext = createContext(pytorchParameters); TaskExecutionContext taskExecutionContext = createContext(pytorchParameters);
PytorchTask task = new PytorchTask(taskExecutionContext); PytorchTask task = new PytorchTask(taskExecutionContext);
@ -221,5 +223,3 @@ public class PytorchTaskTest {
} }
} }

45
dolphinscheduler-task-plugin/dolphinscheduler-task-sagemaker/src/test/java/org/apache/dolphinscheduler/plugin/task/sagemaker/SagemakerTaskTest.java

@ -27,12 +27,12 @@ import org.apache.commons.io.IOUtils;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import com.amazonaws.services.sagemaker.AmazonSageMaker; import com.amazonaws.services.sagemaker.AmazonSageMaker;
import com.amazonaws.services.sagemaker.model.DescribePipelineExecutionResult; import com.amazonaws.services.sagemaker.model.DescribePipelineExecutionResult;
@ -40,7 +40,7 @@ import com.amazonaws.services.sagemaker.model.StartPipelineExecutionRequest;
import com.amazonaws.services.sagemaker.model.StartPipelineExecutionResult; import com.amazonaws.services.sagemaker.model.StartPipelineExecutionResult;
import com.amazonaws.services.sagemaker.model.StopPipelineExecutionResult; import com.amazonaws.services.sagemaker.model.StopPipelineExecutionResult;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class SagemakerTaskTest { public class SagemakerTaskTest {
private final String pipelineExecutionArn = "test-pipeline-arn"; private final String pipelineExecutionArn = "test-pipeline-arn";
@ -49,7 +49,7 @@ public class SagemakerTaskTest {
private AmazonSageMaker client; private AmazonSageMaker client;
private PipelineUtils pipelineUtils = new PipelineUtils(); private PipelineUtils pipelineUtils = new PipelineUtils();
@Before @BeforeEach
public void before() { public void before() {
String parameters = buildParameters(); String parameters = buildParameters();
TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class); TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class);
@ -60,35 +60,38 @@ public class SagemakerTaskTest {
sagemakerTask.init(); sagemakerTask.init();
StartPipelineExecutionResult startPipelineExecutionResult = Mockito.mock(StartPipelineExecutionResult.class); StartPipelineExecutionResult startPipelineExecutionResult = Mockito.mock(StartPipelineExecutionResult.class);
Mockito.when(startPipelineExecutionResult.getPipelineExecutionArn()).thenReturn(pipelineExecutionArn); Mockito.lenient().when(startPipelineExecutionResult.getPipelineExecutionArn()).thenReturn(pipelineExecutionArn);
StopPipelineExecutionResult stopPipelineExecutionResult = Mockito.mock(StopPipelineExecutionResult.class); StopPipelineExecutionResult stopPipelineExecutionResult = Mockito.mock(StopPipelineExecutionResult.class);
Mockito.when(stopPipelineExecutionResult.getPipelineExecutionArn()).thenReturn(pipelineExecutionArn); Mockito.lenient().when(stopPipelineExecutionResult.getPipelineExecutionArn()).thenReturn(pipelineExecutionArn);
DescribePipelineExecutionResult describePipelineExecutionResult = Mockito.mock(DescribePipelineExecutionResult.class); DescribePipelineExecutionResult describePipelineExecutionResult =
Mockito.when(describePipelineExecutionResult.getPipelineExecutionStatus()).thenReturn("Executing", "Succeeded"); Mockito.mock(DescribePipelineExecutionResult.class);
Mockito.lenient().when(describePipelineExecutionResult.getPipelineExecutionStatus()).thenReturn("Executing",
"Succeeded");
Mockito.when(client.startPipelineExecution(any())).thenReturn(startPipelineExecutionResult); Mockito.lenient().when(client.startPipelineExecution(any())).thenReturn(startPipelineExecutionResult);
Mockito.when(client.stopPipelineExecution(any())).thenReturn(stopPipelineExecutionResult); Mockito.lenient().when(client.stopPipelineExecution(any())).thenReturn(stopPipelineExecutionResult);
Mockito.when(client.describePipelineExecution(any())).thenReturn(describePipelineExecutionResult); Mockito.lenient().when(client.describePipelineExecution(any())).thenReturn(describePipelineExecutionResult);
} }
@Test @Test
public void testStartPipelineRequest() throws Exception { public void testStartPipelineRequest() throws Exception {
StartPipelineExecutionRequest request = sagemakerTask.createStartPipelineRequest(); StartPipelineExecutionRequest request = sagemakerTask.createStartPipelineRequest();
Assert.assertEquals("AbalonePipeline", request.getPipelineName()); Assertions.assertEquals("AbalonePipeline", request.getPipelineName());
Assert.assertEquals("test Pipeline", request.getPipelineExecutionDescription()); Assertions.assertEquals("test Pipeline", request.getPipelineExecutionDescription());
Assert.assertEquals("AbalonePipeline", request.getPipelineExecutionDisplayName()); Assertions.assertEquals("AbalonePipeline", request.getPipelineExecutionDisplayName());
Assert.assertEquals("AbalonePipeline", request.getPipelineName()); Assertions.assertEquals("AbalonePipeline", request.getPipelineName());
Assert.assertEquals(new Integer(1), request.getParallelismConfiguration().getMaxParallelExecutionSteps()); Assertions.assertEquals(Integer.valueOf(1),
request.getParallelismConfiguration().getMaxParallelExecutionSteps());
} }
@Test @Test
public void testPipelineExecution() throws Exception { public void testPipelineExecution() throws Exception {
PipelineUtils.PipelineId pipelineId = PipelineUtils.PipelineId pipelineId =
pipelineUtils.startPipelineExecution(client, sagemakerTask.createStartPipelineRequest()); pipelineUtils.startPipelineExecution(client, sagemakerTask.createStartPipelineRequest());
Assert.assertEquals(pipelineExecutionArn, pipelineId.getPipelineExecutionArn()); Assertions.assertEquals(pipelineExecutionArn, pipelineId.getPipelineExecutionArn());
Assert.assertEquals(0, pipelineUtils.checkPipelineExecutionStatus(client, pipelineId)); Assertions.assertEquals(0, pipelineUtils.checkPipelineExecutionStatus(client, pipelineId));
pipelineUtils.stopPipelineExecution(client, pipelineId); pipelineUtils.stopPipelineExecution(client, pipelineId);
} }

14
dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkParametersTest.java

@ -22,15 +22,15 @@ import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class SparkParametersTest { public class SparkParametersTest {
@Test @Test
public void getResourceFilesList() { public void getResourceFilesList() {
SparkParameters sparkParameters = new SparkParameters(); SparkParameters sparkParameters = new SparkParameters();
Assert.assertTrue(sparkParameters.getResourceFilesList().isEmpty()); Assertions.assertTrue(sparkParameters.getResourceFilesList().isEmpty());
ResourceInfo mainResource = new ResourceInfo(); ResourceInfo mainResource = new ResourceInfo();
mainResource.setRes("testSparkMain-1.0.0-SNAPSHOT.jar\""); mainResource.setRes("testSparkMain-1.0.0-SNAPSHOT.jar\"");
@ -43,8 +43,8 @@ public class SparkParametersTest {
sparkParameters.setResourceList(resourceInfos); sparkParameters.setResourceList(resourceInfos);
List<ResourceInfo> resourceFilesList = sparkParameters.getResourceFilesList(); List<ResourceInfo> resourceFilesList = sparkParameters.getResourceFilesList();
Assert.assertNotNull(resourceFilesList); Assertions.assertNotNull(resourceFilesList);
Assert.assertEquals(2, resourceFilesList.size()); Assertions.assertEquals(2, resourceFilesList.size());
ResourceInfo resourceInfo2 = new ResourceInfo(); ResourceInfo resourceInfo2 = new ResourceInfo();
resourceInfo2.setRes("testSparkParameters2.jar"); resourceInfo2.setRes("testSparkParameters2.jar");
@ -52,8 +52,8 @@ public class SparkParametersTest {
sparkParameters.setResourceList(resourceInfos); sparkParameters.setResourceList(resourceInfos);
resourceFilesList = sparkParameters.getResourceFilesList(); resourceFilesList = sparkParameters.getResourceFilesList();
Assert.assertNotNull(resourceFilesList); Assertions.assertNotNull(resourceFilesList);
Assert.assertEquals(3, resourceFilesList.size()); Assertions.assertEquals(3, resourceFilesList.size());
} }
} }

14
dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/test/java/org/apache/dolphinscheduler/plugin/task/spark/SparkTaskTest.java

@ -23,13 +23,13 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import java.util.Collections; import java.util.Collections;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class SparkTaskTest { public class SparkTaskTest {
@Test @Test
@ -42,7 +42,7 @@ public class SparkTaskTest {
SparkTask sparkTask = Mockito.spy(new SparkTask(taskExecutionContext)); SparkTask sparkTask = Mockito.spy(new SparkTask(taskExecutionContext));
sparkTask.init(); sparkTask.init();
Assert.assertEquals(sparkTask.buildCommand(), Assertions.assertEquals(sparkTask.buildCommand(),
"${SPARK_HOME}/bin/spark-sql " + "${SPARK_HOME}/bin/spark-sql " +
"--master yarn " + "--master yarn " +
"--deploy-mode client " + "--deploy-mode client " +
@ -62,7 +62,7 @@ public class SparkTaskTest {
Mockito.when(taskExecutionContext.getTaskParams()).thenReturn(parameters); Mockito.when(taskExecutionContext.getTaskParams()).thenReturn(parameters);
SparkTask sparkTask = Mockito.spy(new SparkTask(taskExecutionContext)); SparkTask sparkTask = Mockito.spy(new SparkTask(taskExecutionContext));
sparkTask.init(); sparkTask.init();
Assert.assertEquals(sparkTask.buildCommand(), Assertions.assertEquals(sparkTask.buildCommand(),
"${SPARK_HOME}/bin/spark-submit " + "${SPARK_HOME}/bin/spark-submit " +
"--master yarn " + "--master yarn " +
"--deploy-mode client " + "--deploy-mode client " +

4
dolphinscheduler-task-plugin/dolphinscheduler-task-sqoop/src/test/java/org/apache/dolphinscheduler/plugin/task/sqoop/SqoopParameterEntityTest.java

@ -24,12 +24,12 @@ import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.sources.SourceMys
import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.targets.TargetHdfsParameter; import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.targets.TargetHdfsParameter;
import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.targets.TargetHiveParameter; import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.targets.TargetHiveParameter;
import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.targets.TargetMysqlParameter; import org.apache.dolphinscheduler.plugin.task.sqoop.parameter.targets.TargetMysqlParameter;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
/** /**
* sqoop parameter entity test * sqoop parameter entity test

52
dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/test/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTaskTest.java

@ -39,16 +39,16 @@ import org.apache.zeppelin.client.ZeppelinClient;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class ZeppelinTaskTest { public class ZeppelinTaskTest {
private static final String MOCK_NOTE_ID = "2GYJR92R7"; private static final String MOCK_NOTE_ID = "2GYJR92R7";
@ -67,7 +67,7 @@ public class ZeppelinTaskTest {
}; };
@Before @BeforeEach
public void before() throws Exception { public void before() throws Exception {
String zeppelinParameters = buildZeppelinTaskParameters(); String zeppelinParameters = buildZeppelinTaskParameters();
TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class); TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class);
@ -78,13 +78,14 @@ public class ZeppelinTaskTest {
this.paragraphResult = mock(ParagraphResult.class); this.paragraphResult = mock(ParagraphResult.class);
doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient(); doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient();
when(this.zClient.executeParagraph(any(), any(), any(Map.class))).thenReturn(this.paragraphResult);
when(paragraphResult.getResultInText()).thenReturn("mock-zeppelin-paragraph-execution-result");
this.zeppelinTask.init(); this.zeppelinTask.init();
} }
@Test @Test
public void testHandleWithParagraphExecutionSuccess() throws Exception { public void testHandleWithParagraphExecutionSuccess() throws Exception {
when(this.zClient.executeParagraph(any(), any(), any(Map.class))).thenReturn(this.paragraphResult);
when(paragraphResult.getResultInText()).thenReturn("mock-zeppelin-paragraph-execution-result");
when(this.paragraphResult.getStatus()).thenReturn(Status.FINISHED); when(this.paragraphResult.getStatus()).thenReturn(Status.FINISHED);
this.zeppelinTask.handle(taskCallBack); this.zeppelinTask.handle(taskCallBack);
Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID,
@ -92,45 +93,56 @@ public class ZeppelinTaskTest {
(Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class)); (Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class));
Mockito.verify(this.paragraphResult).getResultInText(); Mockito.verify(this.paragraphResult).getResultInText();
Mockito.verify(this.paragraphResult).getStatus(); Mockito.verify(this.paragraphResult).getStatus();
Assert.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode());
} }
@Test @Test
public void testHandleWithParagraphExecutionAborted() throws Exception { public void testHandleWithParagraphExecutionAborted() throws Exception {
when(this.zClient.executeParagraph(any(), any(), any(Map.class))).thenReturn(this.paragraphResult);
when(paragraphResult.getResultInText()).thenReturn("mock-zeppelin-paragraph-execution-result");
when(this.paragraphResult.getStatus()).thenReturn(Status.ABORT); when(this.paragraphResult.getStatus()).thenReturn(Status.ABORT);
this.zeppelinTask.handle(taskCallBack); this.zeppelinTask.handle(taskCallBack);
Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID,
MOCK_PARAGRAPH_ID, MOCK_PARAGRAPH_ID,
(Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class)); (Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class));
Mockito.verify(this.paragraphResult).getResultInText(); Mockito.verify(this.paragraphResult).getResultInText();
Mockito.verify(this.paragraphResult).getStatus(); Mockito.verify(this.paragraphResult).getStatus();
Assert.assertEquals(EXIT_CODE_KILL, this.zeppelinTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_KILL, this.zeppelinTask.getExitStatusCode());
} }
@Test @Test
public void testHandleWithParagraphExecutionError() throws Exception { public void testHandleWithParagraphExecutionError() throws Exception {
when(this.zClient.executeParagraph(any(), any(), any(Map.class))).thenReturn(this.paragraphResult);
when(paragraphResult.getResultInText()).thenReturn("mock-zeppelin-paragraph-execution-result");
when(this.paragraphResult.getStatus()).thenReturn(Status.ERROR); when(this.paragraphResult.getStatus()).thenReturn(Status.ERROR);
this.zeppelinTask.handle(taskCallBack); this.zeppelinTask.handle(taskCallBack);
Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID,
MOCK_PARAGRAPH_ID, MOCK_PARAGRAPH_ID,
(Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class)); (Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class));
Mockito.verify(this.paragraphResult).getResultInText(); Mockito.verify(this.paragraphResult).getResultInText();
Mockito.verify(this.paragraphResult).getStatus(); Mockito.verify(this.paragraphResult).getStatus();
Assert.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode());
} }
@Test(expected = TaskException.class) @Test
public void testHandleWithParagraphExecutionException() throws Exception { public void testHandleWithParagraphExecutionException() throws Exception {
when(this.zClient.executeParagraph(any(), any(), any(Map.class))) when(this.zClient.executeParagraph(any(), any(), any(Map.class)))
.thenThrow(new TaskException("Something wrong happens from zeppelin side")); .thenThrow(new TaskException("Something wrong happens from zeppelin side"));
Assertions.assertThrows(TaskException.class, () -> {
this.zeppelinTask.handle(taskCallBack); this.zeppelinTask.handle(taskCallBack);
});
Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID, Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID,
MOCK_PARAGRAPH_ID, MOCK_PARAGRAPH_ID,
(Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class)); (Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class));
Mockito.verify(this.paragraphResult, Mockito.times(0)).getResultInText(); Mockito.verify(this.paragraphResult, Mockito.times(0)).getResultInText();
Mockito.verify(this.paragraphResult, Mockito.times(0)).getStatus(); Mockito.verify(this.paragraphResult, Mockito.times(0)).getStatus();
Assert.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_FAILURE, this.zeppelinTask.getExitStatusCode());
} }
@Test @Test
@ -139,19 +151,18 @@ public class ZeppelinTaskTest {
TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class); TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class);
when(taskExecutionContext.getTaskParams()).thenReturn(zeppelinParametersWithNoParagraphId); when(taskExecutionContext.getTaskParams()).thenReturn(zeppelinParametersWithNoParagraphId);
this.zeppelinTask = spy(new ZeppelinTask(taskExecutionContext)); this.zeppelinTask = spy(new ZeppelinTask(taskExecutionContext));
this.zClient = mock(ZeppelinClient.class); this.zClient = mock(ZeppelinClient.class);
this.noteResult = mock(NoteResult.class); this.noteResult = mock(NoteResult.class);
doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient(); doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient();
when(this.zClient.executeNote(any(), any(Map.class))).thenReturn(this.noteResult); when(this.zClient.executeNote(any(), any(Map.class))).thenReturn(this.noteResult);
this.zeppelinTask.init(); this.zeppelinTask.init();
this.zeppelinTask.handle(taskCallBack); this.zeppelinTask.handle(taskCallBack);
Mockito.verify(this.zClient).executeNote(MOCK_NOTE_ID, Mockito.verify(this.zClient).executeNote(MOCK_NOTE_ID,
(Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class)); (Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class));
Mockito.verify(this.noteResult).getParagraphResultList(); Mockito.verify(this.noteResult).getParagraphResultList();
Assert.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode());
} }
@Test @Test
@ -159,18 +170,19 @@ public class ZeppelinTaskTest {
String zeppelinParametersWithNoParagraphId = buildZeppelinTaskParametersWithProductionSetting(); String zeppelinParametersWithNoParagraphId = buildZeppelinTaskParametersWithProductionSetting();
TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class); TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class);
Mockito.mockStatic(DateUtils.class); Mockito.mockStatic(DateUtils.class);
when(DateUtils.getTimestampString()).thenReturn("123456789");
when(taskExecutionContext.getTaskParams()).thenReturn(zeppelinParametersWithNoParagraphId); when(taskExecutionContext.getTaskParams()).thenReturn(zeppelinParametersWithNoParagraphId);
this.zeppelinTask = spy(new ZeppelinTask(taskExecutionContext)); this.zeppelinTask = spy(new ZeppelinTask(taskExecutionContext));
this.zClient = mock(ZeppelinClient.class); this.zClient = mock(ZeppelinClient.class);
this.noteResult = mock(NoteResult.class); this.noteResult = mock(NoteResult.class);
doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient(); doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient();
when(this.zClient.cloneNote(any(String.class), any(String.class))).thenReturn(MOCK_CLONE_NOTE_ID); when(this.zClient.cloneNote(any(String.class), any(String.class))).thenReturn(MOCK_CLONE_NOTE_ID);
when(this.zClient.executeNote(any(), any(Map.class))).thenReturn(this.noteResult); when(this.zClient.executeNote(any(), any(Map.class))).thenReturn(this.noteResult);
this.zeppelinTask.init(); this.zeppelinTask.init();
when(DateUtils.getTimestampString()).thenReturn("123456789");
this.zeppelinTask.handle(taskCallBack); this.zeppelinTask.handle(taskCallBack);
Mockito.verify(this.zClient).cloneNote( Mockito.verify(this.zClient).cloneNote(
MOCK_NOTE_ID, MOCK_NOTE_ID,
String.format("%s%s_%s", MOCK_PRODUCTION_DIRECTORY, MOCK_NOTE_ID, "123456789")); String.format("%s%s_%s", MOCK_PRODUCTION_DIRECTORY, MOCK_NOTE_ID, "123456789"));
@ -178,7 +190,7 @@ public class ZeppelinTaskTest {
(Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class)); (Map<String, String>) mapper.readValue(MOCK_PARAMETERS, Map.class));
Mockito.verify(this.noteResult).getParagraphResultList(); Mockito.verify(this.noteResult).getParagraphResultList();
Mockito.verify(this.zClient).deleteNote(MOCK_CLONE_NOTE_ID); Mockito.verify(this.zClient).deleteNote(MOCK_CLONE_NOTE_ID);
Assert.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode()); Assertions.assertEquals(EXIT_CODE_SUCCESS, this.zeppelinTask.getExitStatusCode());
} }
private String buildZeppelinTaskParameters() { private String buildZeppelinTaskParameters() {

Loading…
Cancel
Save