PythonInterpreter extends Interpreter { @Override public void close() { logger.info("closing Python interpreter ....."); try { if (process != null) { process.close(); } if (gatewayServer != null) { gatewayServer.shutdown(); } } catch (IOException e) { logger.error("Can't close the interpreter", e); } } PythonInterpreter(Properties property); @Override void open(); @Override void close(); @Override InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter); @Override void cancel(InterpreterContext context); @Override FormType getFormType(); @Override int getProgress(InterpreterContext context); @Override Scheduler getScheduler(); @Override List<InterpreterCompletion> completion(String buf, int cursor); PythonProcess getPythonProcess(); GUI getGui(); Integer getPy4JPort(); Boolean isPy4jInstalled(); static final String BOOTSTRAP_PY; static final String BOOTSTRAP_INPUT_PY; static final String ZEPPELIN_PYTHON; static final String DEFAULT_ZEPPELIN_PYTHON; }
@Test public void testClose() { try { when(mockPythonProcess.sendAndGetResult(eq("\n\nimport py4j\n"))).thenReturn(">>>"); } catch (IOException e) { e.printStackTrace(); } pythonInterpreter.open(); Integer py4jPort = pythonInterpreter.getPy4JPort(); assertNotNull(py4jPort); pythonInterpreter.close(); assertFalse(checkSocketAdress(py4jPort)); try { verify(mockPythonProcess, times(1)).close(); } catch (IOException e) { e.printStackTrace(); } }