Shiwen Cheng
3 years ago
committed by
GitHub
6 changed files with 152 additions and 123 deletions
@ -1,80 +0,0 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.worker; |
||||
|
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.junit.Test; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.FileInputStream; |
||||
import java.io.IOException; |
||||
import java.io.InputStreamReader; |
||||
|
||||
|
||||
public class EnvFileTest { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EnvFileTest.class); |
||||
|
||||
@Test |
||||
public void test() { |
||||
String path = System.getProperty("user.dir")+"/script/env/dolphinscheduler_env.sh"; |
||||
String pythonHome = getPythonHome(path); |
||||
logger.info(pythonHome); |
||||
} |
||||
|
||||
/** |
||||
* get python home |
||||
* @param path |
||||
* @return |
||||
*/ |
||||
private static String getPythonHome(String path){ |
||||
BufferedReader br = null; |
||||
String line = null; |
||||
StringBuilder sb = new StringBuilder(); |
||||
try { |
||||
br = new BufferedReader(new InputStreamReader(new FileInputStream(path))); |
||||
while ((line = br.readLine()) != null){ |
||||
if (line.contains("PYTHON_HOME")){ |
||||
sb.append(line); |
||||
break; |
||||
} |
||||
} |
||||
String result = sb.toString(); |
||||
if (StringUtils.isEmpty(result)){ |
||||
return null; |
||||
} |
||||
String[] arrs = result.split("="); |
||||
if (arrs.length == 2){ |
||||
return arrs[1]; |
||||
} |
||||
|
||||
}catch (IOException e){ |
||||
logger.error("read file failed",e); |
||||
}finally { |
||||
try { |
||||
if (br != null){ |
||||
br.close(); |
||||
} |
||||
} catch (IOException e) { |
||||
logger.error(e.getMessage(),e); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,58 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.worker.task; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
public class PythonCommandExecutorTest { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PythonCommandExecutorTest.class); |
||||
|
||||
@Test |
||||
public void testGetPythonHome() { |
||||
String path = System.getProperty("user.dir") + "/script/env/dolphinscheduler_env.sh"; |
||||
if (path.contains("dolphinscheduler-server/")) { |
||||
path = path.replace("dolphinscheduler-server/", ""); |
||||
} |
||||
String pythonHome = PythonCommandExecutor.getPythonHome(path); |
||||
logger.info(pythonHome); |
||||
Assert.assertNotNull(pythonHome); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetPythonCommand() { |
||||
String pythonCommand = PythonCommandExecutor.getPythonCommand(null); |
||||
Assert.assertEquals(PythonCommandExecutor.PYTHON, pythonCommand); |
||||
pythonCommand = PythonCommandExecutor.getPythonCommand(""); |
||||
Assert.assertEquals(PythonCommandExecutor.PYTHON, pythonCommand); |
||||
pythonCommand = PythonCommandExecutor.getPythonCommand("/usr/bin/python"); |
||||
Assert.assertEquals("/usr/bin/python", pythonCommand); |
||||
pythonCommand = PythonCommandExecutor.getPythonCommand("/usr/local/bin/python2"); |
||||
Assert.assertEquals("/usr/local/bin/python2", pythonCommand); |
||||
pythonCommand = PythonCommandExecutor.getPythonCommand("/opt/python/bin/python3.8"); |
||||
Assert.assertEquals("/opt/python/bin/python3.8", pythonCommand); |
||||
pythonCommand = PythonCommandExecutor.getPythonCommand("/opt/soft/python"); |
||||
Assert.assertEquals("/opt/soft/python/bin/python", pythonCommand); |
||||
pythonCommand = PythonCommandExecutor.getPythonCommand("/opt/soft/python-3.8"); |
||||
Assert.assertEquals("/opt/soft/python-3.8/bin/python", pythonCommand); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue