fix OpenmldbTaskTest test class error
This commit is contained in:
parent
b75f241d97
commit
e1e36f5aa4
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue