This is an automated email from the ASF dual-hosted git repository.
kerwin pushed a commit to branch 3.1.3-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/3.1.3-prepare by this push:
new e1e36f5aa4 fix OpenmldbTaskTest test class error
e1e36f5aa4 is described below
commit e1e36f5aa4b2c9dc4222d79e169ec7c0e97c9c0b
Author: zhuangchong <[email protected]>
AuthorDate: Wed Jan 4 09:25:37 2023 +0800
fix OpenmldbTaskTest test class error
---
.../plugin/task/openmldb/OpenmldbTaskTest.java | 41 ++++++++++++----------
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git
a/dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java
b/dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java
index ac17696c63..c608fa8fb3 100644
---
a/dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java
+++
b/dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java
@@ -25,9 +25,9 @@ import
org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters
import java.util.HashMap;
import java.util.Map;
-import org.junit.Assert;
-import org.junit.Test;
-import org.powermock.reflect.Whitebox;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
public class OpenmldbTaskTest {
static class MockOpenmldbTask extends OpenmldbTask {
@@ -55,36 +55,39 @@ public class OpenmldbTaskTest {
OpenmldbTask openmldbTask = createOpenmldbTask();
String pythonFile = "test.py";
String result1 = openmldbTask.buildPythonExecuteCommand(pythonFile);
- Assert.assertEquals("python3 test.py", result1);
+ Assertions.assertEquals("python3 test.py", result1);
}
@Test
public void buildSQLWithComment() throws Exception {
- OpenmldbTask openmldbTask = createOpenmldbTask();
+ TaskExecutionContext taskExecutionContext =
Mockito.mock(TaskExecutionContext.class);
OpenmldbParameters openmldbParameters = new OpenmldbParameters();
openmldbParameters.setExecuteMode("offline");
+ openmldbParameters.setZk("localhost:2181");
+ openmldbParameters.setZkPath("dolphinscheduler");
String rawSQLScript = "select * from users\r\n"
+ "-- some comment\n"
+ "inner join order on users.order_id = order.id; \n\n;"
+ "select * from users;";
openmldbParameters.setSql(rawSQLScript);
- Whitebox.setInternalState(openmldbTask, "openmldbParameters",
openmldbParameters);
+
Mockito.when(taskExecutionContext.getTaskParams()).thenReturn(JSONUtils.toJsonString(openmldbParameters));
+ OpenmldbTask openmldbTask = new OpenmldbTask(taskExecutionContext);
+ openmldbTask.init();
OpenmldbParameters internal = (OpenmldbParameters)
openmldbTask.getParameters();
- Assert.assertNotNull(internal);
- Assert.assertEquals(internal.getExecuteMode(), "offline");
+ Assertions.assertNotNull(internal);
+ Assertions.assertEquals(internal.getExecuteMode(), "offline");
String result1 = openmldbTask.buildPythonScriptContent();
- Assert.assertEquals("import openmldb\n"
- + "import sqlalchemy as db\n"
- + "engine =
db.create_engine('openmldb:///?zk=null&zkPath=null')\n"
- + "con = engine.connect()\n"
- + "con.execute(\"set @@execute_mode='offline';\")\n"
- + "con.execute(\"set @@sync_job=true\")\n"
- + "con.execute(\"set @@job_timeout=1800000\")\n"
- + "con.execute(\"select * from users\\n-- some
comment\\ninner join order on users.order_id = "
- + "order.id\")\n"
- + "con.execute(\"select * from users\")\n"
- , result1);
+ Assertions.assertEquals("import openmldb\n"
+ + "import sqlalchemy as db\n"
+ + "engine =
db.create_engine('openmldb:///?zk=localhost:2181&zkPath=dolphinscheduler')\n"
+ + "con = engine.connect()\n"
+ + "con.execute(\"set @@execute_mode='offline';\")\n"
+ + "con.execute(\"set @@sync_job=true\")\n"
+ + "con.execute(\"set @@job_timeout=1800000\")\n"
+ + "con.execute(\"select * from users\\n-- some comment\\ninner
join order on users.order_id = "
+ + "order.id\")\n"
+ + "con.execute(\"select * from users\")\n", result1);
}
}
\ No newline at end of file