You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/08/22 11:27:12 UTC
[incubator-linkis] branch dev-1.3.0 updated: add test case for python executor (#2924)
This is an automated email from the ASF dual-hosted git repository.
peacewong pushed a commit to branch dev-1.3.0
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.3.0 by this push:
new 4a0b4a2d8 add test case for python executor (#2924)
4a0b4a2d8 is described below
commit 4a0b4a2d804e0a8e39949b55197ddaedcfdde618
Author: QuintinTao <72...@users.noreply.github.com>
AuthorDate: Mon Aug 22 19:27:08 2022 +0800
add test case for python executor (#2924)
* add test case for python executor
---
.../executor/TestPythonEngineConnExecutor.scala | 89 ++++++++++++++++++++++
1 file changed, 89 insertions(+)
diff --git a/linkis-engineconn-plugins/python/src/test/scala/org/apache/linkis/manager/engineplugin/python/executor/TestPythonEngineConnExecutor.scala b/linkis-engineconn-plugins/python/src/test/scala/org/apache/linkis/manager/engineplugin/python/executor/TestPythonEngineConnExecutor.scala
new file mode 100644
index 000000000..295b30078
--- /dev/null
+++ b/linkis-engineconn-plugins/python/src/test/scala/org/apache/linkis/manager/engineplugin/python/executor/TestPythonEngineConnExecutor.scala
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.manager.engineplugin.python.executor
+
+import org.apache.linkis.DataWorkCloudApplication
+import org.apache.linkis.common.conf.DWCArgumentsParser
+import org.apache.linkis.common.utils.Utils
+import org.apache.linkis.engineconn.common.creation.{
+ DefaultEngineCreationContext,
+ EngineCreationContext
+}
+import org.apache.linkis.engineconn.computation.executor.execute.EngineExecutionContext
+import org.apache.linkis.engineconn.launch.EngineConnServer
+import org.apache.linkis.manager.engineplugin.python.factory.PythonEngineConnFactory
+import org.apache.linkis.manager.engineplugin.python.hook.PythonVersionEngineHook
+
+import scala.collection.mutable
+
+import org.junit.jupiter.api.{Assertions, Test}
+
+class TestPythonEngineConnExecutor {
+
+ def initService(port: String): Unit = {
+ System.setProperty("wds.linkis.server.version", "v1")
+ System.setProperty(
+ "wds.linkis.engineconn.plugin.default.class",
+ "org.apache.linkis.manager.engineplugin.python.PythonEngineConnPlugin"
+ )
+ val map = new mutable.HashMap[String, String]()
+ map.put("spring.mvc.servlet.path", "/api/rest_j/v1")
+ map.put("server.port", port)
+ map.put("spring.application.name", "SparkSqlExecutor")
+ map.put("eureka.client.register-with-eureka", "false")
+ map.put("eureka.client.fetch-registry", "false")
+ DataWorkCloudApplication.main(DWCArgumentsParser.formatSpringOptions(map.toMap))
+ }
+
+ @Test
+ def testExecuteLine: Unit = {
+ initService("26381")
+ val hookPre = new PythonVersionEngineHook
+ val engineConnFactory: PythonEngineConnFactory = new PythonEngineConnFactory
+ val engineCreationContext: EngineCreationContext = new DefaultEngineCreationContext
+ val path = this.getClass.getResource("/").getPath
+ System.setProperty("pythonVersion", "python")
+ System.setProperty("HADOOP_CONF_DIR", "./")
+ System.setProperty(
+ "wds.linkis.python.py4j.home",
+ path.substring(0, path.indexOf("/target")) + "/src/main/py4j"
+ )
+ val jMap = new java.util.HashMap[String, String]()
+ jMap.put("python.version", "python")
+ engineCreationContext.setOptions(jMap)
+ val engineConn = engineConnFactory.createEngineConn(engineCreationContext)
+ EngineConnServer.getEngineCreationContext.setOptions(jMap)
+ hookPre.beforeCreateEngineConn(engineCreationContext)
+ val executor = engineConnFactory
+ .newExecutor(1, engineCreationContext, engineConn)
+ .asInstanceOf[PythonEngineConnExecutor]
+ executor.init()
+ Assertions.assertTrue(executor.isEngineInitialized)
+ if (!System.getProperty("os.name").startsWith("Windows")) {
+// engineConn.getEngineConnSession.asInstanceOf[PythonSession].onPythonScriptInitialized(1)
+// hookPre.beforeExecutionExecute(engineCreationContext, engineConn)
+ val engineExecutionContext = new EngineExecutionContext(executor, Utils.getJvmUser)
+ engineExecutionContext.addProperty("python.version", "python")
+ val code = "for i in range(10):\n print(i)"
+ val response = executor.executeLine(engineExecutionContext, code)
+ Assertions.assertNotNull(response)
+ executor.close()
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org