mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 23:42:06 +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:
parent
52673bad3c
commit
fe9606adb2
1 changed files with 19 additions and 0 deletions
|
@ -55,6 +55,8 @@ public class Socks5TestProxy {
|
||||||
/* port of the test proxy */
|
/* port of the test proxy */
|
||||||
private int port = 7777;
|
private int port = 7777;
|
||||||
|
|
||||||
|
private boolean startupComplete;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private constructor.
|
* Private constructor.
|
||||||
*/
|
*/
|
||||||
|
@ -169,6 +171,19 @@ public class Socks5TestProxy {
|
||||||
* @return socket or null if there is no socket for the given digest
|
* @return socket or null if there is no socket for the given digest
|
||||||
*/
|
*/
|
||||||
public Socket getSocket(String 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);
|
return this.connectionMap.get(digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +220,10 @@ public class Socks5TestProxy {
|
||||||
// initialize connection
|
// initialize connection
|
||||||
establishConnection(socket);
|
establishConnection(socket);
|
||||||
|
|
||||||
|
synchronized (this) {
|
||||||
|
startupComplete = true;
|
||||||
|
notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (SocketException e) {
|
catch (SocketException e) {
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
|
|
Loading…
Reference in a new issue