From d1b4ac3ad14334cce8006ef37f5117e36037307f Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 1 Apr 2010 14:53:57 +0400 Subject: [PATCH] junit: blocking read replaces another pair of sockets --- .../intellij/execution/junit/TestPackage.java | 20 +++++++------------ .../rt/execution/junit/JUnitStarter.java | 13 +++--------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java index b3d82199c344..e500df20e125 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java @@ -40,7 +40,7 @@ import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.DataInputStream; +import java.io.DataOutputStream; import java.io.File; import java.io.IOException; import java.net.InetAddress; @@ -189,19 +189,12 @@ public class TestPackage extends TestObject { final boolean[] isJunit4 = new boolean[1]; final Task.Backgroundable task = new Task.Backgroundable(classFilter.getProject(), ExecutionBundle.message("seaching.test.progress.title"), true) { - int myPort = -1; + private Socket mySocket; @Override public void run(@NotNull ProgressIndicator indicator) { try { - final Socket socket = serverSocket.accept(); - final DataInputStream is = new DataInputStream(socket.getInputStream()); - try { - myPort = is.readInt(); - } - finally { - is.close(); - } + mySocket = serverSocket.accept(); } catch (IOException e) { LOG.info(e); @@ -226,16 +219,17 @@ public class TestPackage extends TestObject { } private void connect() { - Socket socket = null; + DataOutputStream os = null; try { - socket = new Socket(InetAddress.getLocalHost(), myPort); + os = new DataOutputStream(mySocket.getOutputStream()); + os.writeBoolean(true); } catch (Throwable e) { LOG.info(e); } finally { try { - if (socket != null) socket.close(); + if (os != null) os.close(); } catch (Throwable e) { LOG.info(e); diff --git a/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java b/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java index e0fb91861271..22316b22b124 100644 --- a/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java +++ b/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java @@ -98,19 +98,12 @@ public class JUnitStarter { final int port = Integer.parseInt(arg.substring(SOCKET.length())); try { final Socket socket = new Socket(InetAddress.getLocalHost(), port); //start collecting tests - final ServerSocket serverSocket = new ServerSocket(0); + final DataInputStream os = new DataInputStream(socket.getInputStream()); try { - final DataOutputStream os = new DataOutputStream(socket.getOutputStream()); - try { - os.writeInt(serverSocket.getLocalPort()); //write port to sync - } - finally { - os.close(); - } - serverSocket.accept(); + os.readBoolean();//wait for ready flag } finally { - serverSocket.close(); + os.close(); } } catch (IOException e) {