Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.net.Socket;
import java.net.SocketAddress;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.apache.zeppelin.interpreter.InterpreterResult;
import org.junit.Before;
Expand Down Expand Up @@ -110,13 +111,10 @@ public void testPy4jIsNotInstalled() {

/**
* If Py4J installed, bootstrap_input.py
* is sent to interpreter and JavaGateway is
* running
*
* @throws IOException
* is sent to interpreter and JavaGateway is running
*/
@Test
public void testPy4jInstalled() throws IOException {
public void testPy4jInstalled() throws IOException, InterruptedException {
when(mockPythonProcess.sendAndGetResult(eq("\n\nimport py4j\n"))).thenReturn(">>>");

pythonInterpreter.open();
Expand All @@ -131,6 +129,9 @@ public void testPy4jInstalled() throws IOException {
assertTrue(cmdHistory.contains("org.apache.zeppelin.display.Input"));

assertTrue(serverIsListeningOn(py4jPort));
pythonInterpreter.close();
TimeUnit.MILLISECONDS.sleep(100);
assertFalse(serverIsListeningOn(py4jPort));
}

@Test
Expand All @@ -144,6 +145,7 @@ public void testClose() throws IOException, InterruptedException {

//when
pythonInterpreter.close();
TimeUnit.MILLISECONDS.sleep(100);

//then
assertFalse(serverIsListeningOn(py4jPort));
Expand All @@ -164,13 +166,16 @@ public void testInterpret() {
* @param port
*/
private boolean serverIsListeningOn(Integer port) {
boolean serverIsListening = false;
Socket s = new Socket();
boolean serverIsListening = false;

boolean connected = tryToConnect(s, port);
if (connected) {
serverIsListening = true;
int retryCount = 0;
boolean connected = false;
while (connected = tryToConnect(s, port) && retryCount < 10) {
serverIsListening = connected;
tryToClose(s);
retryCount++;
s = new Socket();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put a sleep(1) before retry?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep added inside the client code in tests, where we know that it's needed to wait for something to startup\shutdown

}
return serverIsListening;
}
Expand Down