info: java: fix tests by letting mock bind to localhost
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 3 Jul 2017 13:01:24 +0000 (15:01 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 3 Jul 2017 13:02:42 +0000 (15:02 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/info.java/org.olsr.v1.info.proxy/test/org/olsr/v1/info/proxy/MockOlsrdInfo.java

index c6d49f2..8dd8ff4 100644 (file)
@@ -8,8 +8,10 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.SocketAddress;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -35,7 +37,9 @@ public class MockOlsrdInfo extends Thread {
   public Map<String, List<File>> responses                        = new HashMap<>();
 
   public MockOlsrdInfo() throws IOException {
-    this.socket = new ServerSocket(0);
+    final SocketAddress sa = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0);
+    this.socket = new ServerSocket();
+    this.socket.bind(sa);
     this.socket.setSoTimeout(100);
     this.address = this.socket.getInetAddress();
     this.port = this.socket.getLocalPort();