Skip to content

Commit

Permalink
Connect socket to loopback address.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jun 18, 2020
1 parent 2b584f3 commit fe46761
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.mockito.stubbing.Answer;

import java.io.*;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
Expand All @@ -28,13 +27,20 @@ public class VirtualMachineForOpenJ9Test {

private File temporaryFolder, attachFolder;

private InetAddress loopback;

@Before
public void setUp() throws Exception {
temporaryFolder = File.createTempFile("ibm", "temporary");
assertThat(temporaryFolder.delete(), is(true));
assertThat(temporaryFolder.mkdir(), is(true));
attachFolder = new File(temporaryFolder, ".com_ibm_tools_attach");
assertThat(attachFolder.mkdir(), is(true));
try {
loopback = (InetAddress) InetAddress.class.getMethod("getLoopbackAddress").invoke(null);
} catch (Exception ignored) {
/* do nothing */
}
}

@After
Expand Down Expand Up @@ -90,7 +96,7 @@ public void run() {
}
Socket socket = new Socket();
try {
socket.connect(new InetSocketAddress(InetAddress.getLocalHost(), port), 5000);
socket.connect(new InetSocketAddress(loopback, port), 5000);
socket.getOutputStream().write((' ' + key + ' ').getBytes("UTF-8"));
socket.getOutputStream().write(0);
socket.getOutputStream().flush();
Expand Down

0 comments on commit fe46761

Please sign in to comment.