1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-10-31 17:25:58 +01:00

Wait for Socks5TestProxy initialization

to prevent

org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiatorTest
  > shouldSuccessfullyEstablishConnectionAndActivateSocks5Proxy
    FAILED
    java.lang.NullPointerException at Socks5ClientForInitiatorTest.java:292
This commit is contained in:
Florian Schmaus 2014-08-16 08:51:13 +02:00
parent 52673bad3c
commit fe9606adb2

View file

@ -55,6 +55,8 @@ public class Socks5TestProxy {
/* port of the test proxy */
private int port = 7777;
private boolean startupComplete;
/**
* Private constructor.
*/
@ -169,6 +171,19 @@ public class Socks5TestProxy {
* @return socket or null if there is no socket for the given digest
*/
public Socket getSocket(String digest) {
synchronized(this) {
if (!startupComplete) {
try {
wait(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (!startupComplete) {
throw new IllegalStateException("Startup of Socks5TestProxy failed within 5 seconds");
}
}
}
}
return this.connectionMap.get(digest);
}
@ -205,6 +220,10 @@ public class Socks5TestProxy {
// initialize connection
establishConnection(socket);
synchronized (this) {
startupComplete = true;
notify();
}
}
catch (SocketException e) {
/* do nothing */