Browse Source

fix OpenmldbTaskTest test class error

3.1.3-release
zhuangchong 2 years ago
parent
commit
e1e36f5aa4
  1. 27
      dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/test/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTaskTest.java

27
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.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.powermock.reflect.Whitebox; import org.mockito.Mockito;
public class OpenmldbTaskTest { public class OpenmldbTaskTest {
static class MockOpenmldbTask extends OpenmldbTask { static class MockOpenmldbTask extends OpenmldbTask {
@ -55,36 +55,39 @@ 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
public void buildSQLWithComment() throws Exception { public void buildSQLWithComment() throws Exception {
OpenmldbTask openmldbTask = createOpenmldbTask(); TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class);
OpenmldbParameters openmldbParameters = new OpenmldbParameters(); OpenmldbParameters openmldbParameters = new OpenmldbParameters();
openmldbParameters.setExecuteMode("offline"); openmldbParameters.setExecuteMode("offline");
openmldbParameters.setZk("localhost:2181");
openmldbParameters.setZkPath("dolphinscheduler");
String rawSQLScript = "select * from users\r\n" String rawSQLScript = "select * from users\r\n"
+ "-- some comment\n" + "-- some comment\n"
+ "inner join order on users.order_id = order.id; \n\n;" + "inner join order on users.order_id = order.id; \n\n;"
+ "select * from users;"; + "select * from users;";
openmldbParameters.setSql(rawSQLScript); 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(); 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=null&zkPath=null')\n" + "engine = db.create_engine('openmldb:///?zk=localhost:2181&zkPath=dolphinscheduler')\n"
+ "con = engine.connect()\n" + "con = engine.connect()\n"
+ "con.execute(\"set @@execute_mode='offline';\")\n" + "con.execute(\"set @@execute_mode='offline';\")\n"
+ "con.execute(\"set @@sync_job=true\")\n" + "con.execute(\"set @@sync_job=true\")\n"
+ "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);
} }
} }
Loading…
Cancel
Save