mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
[ZEPPELIN-502] Formatting code to respect project convention
This commit is contained in:
parent
54ec4f1092
commit
3252353e28
3 changed files with 36 additions and 23 deletions
|
|
@ -44,12 +44,12 @@
|
|||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-exec</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-exec</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.py4j</groupId>
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ public class PythonInterpreter extends Interpreter {
|
|||
else
|
||||
return process;
|
||||
}
|
||||
|
||||
|
||||
private Job getRunningJob(String paragraphId) {
|
||||
Job foundJob = null;
|
||||
Collection<Job> jobsRunning = getScheduler().getJobsRunning();
|
||||
|
|
@ -215,12 +215,13 @@ public class PythonInterpreter extends Interpreter {
|
|||
PythonInterpreter.class.getResourceAsStream(file)));
|
||||
String line = null;
|
||||
String bootstrapCode = "";
|
||||
|
||||
while ((line = bootstrapReader.readLine()) != null) {
|
||||
bootstrapCode += line + "\n";
|
||||
}
|
||||
|
||||
if (py4J && port != null && port != -1)
|
||||
if (py4J && port != null && port != -1) {
|
||||
bootstrapCode = bootstrapCode.replaceAll("\\%PORT\\%", port.toString());
|
||||
}
|
||||
logger.info("Bootstrap python interpreter with \n " + bootstrapCode);
|
||||
sendCommandToPython(bootstrapCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,9 @@ import java.net.Socket;
|
|||
import java.net.SocketAddress;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Python interpreter unit test
|
||||
*/
|
||||
public class PythonInterpreterTest {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(PythonProcess.class);
|
||||
|
|
@ -65,21 +68,11 @@ public class PythonInterpreterTest {
|
|||
mockPythonProcess = mock(PythonProcess.class);
|
||||
when(mockPythonProcess.getPid()).thenReturn((long) 1);
|
||||
try {
|
||||
when(mockPythonProcess.sendAndGetResult(anyString())).thenAnswer(new Answer<String>() {
|
||||
when(mockPythonProcess.sendAndGetResult(anyString())).thenAnswer(
|
||||
new Answer<String>() {
|
||||
@Override
|
||||
public String answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
Object[] args = invocationOnMock.getArguments();
|
||||
String cmd = (String) args[0];
|
||||
if (cmd != null) {
|
||||
cmdHistory += cmd;
|
||||
String[] lines = cmd.split("\\n");
|
||||
String output = "";
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
output += ">>>" + lines[i];
|
||||
}
|
||||
return output;
|
||||
|
||||
} else return ">>>";
|
||||
return answerFromPythonMock(invocationOnMock);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
|
|
@ -102,7 +95,6 @@ public class PythonInterpreterTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOpenInterpreter() {
|
||||
pythonInterpreter.open();
|
||||
|
|
@ -218,4 +210,24 @@ public class PythonInterpreterTest {
|
|||
return working;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String answerFromPythonMock(InvocationOnMock invocationOnMock) {
|
||||
Object[] inputs = invocationOnMock.getArguments();
|
||||
String cmdToExecute = (String) inputs[0];
|
||||
|
||||
if (cmdToExecute != null) {
|
||||
cmdHistory += cmdToExecute;
|
||||
String[] lines = cmdToExecute.split("\\n");
|
||||
String output = "";
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
output += ">>>" + lines[i];
|
||||
}
|
||||
return output;
|
||||
} else {
|
||||
return ">>>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue