Skip to content

Commit

Permalink
removed unused field
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed May 8, 2013
1 parent fa9a648 commit 0b238a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Expand Up @@ -59,7 +59,6 @@ public class SocketReceiverTest {
private static final String TEST_HOST_NAME = "NOT.A.VALID.HOST.NAME";

private ServerSocket serverSocket;
private Socket socket;
private MockSocketFactory socketFactory = new MockSocketFactory();
private MockAppender mockAppender = new MockAppender();
private LoggerContext receiversLoggerContext = new LoggerContext();
Expand All @@ -75,8 +74,6 @@ public void setUp() throws Exception {

serverSocket = ServerSocketUtil.createServerSocket();
port = serverSocket.getLocalPort();
socket = new Socket(serverSocket.getInetAddress(), port);

mockAppender.start();
logger = receiversLoggerContext.getLogger(getClass());
logger.addAppender(mockAppender);
Expand All @@ -89,7 +86,6 @@ public void tearDown() throws Exception {
ExecutorService executor = receiversLoggerContext.getExecutorService();
executor.shutdownNow();
assertTrue(executor.awaitTermination(DELAY, TimeUnit.MILLISECONDS));
socket.close();
serverSocket.close();
receiversLoggerContext.stop();
}
Expand Down
Expand Up @@ -49,21 +49,21 @@ public static ServerSocket createServerSocket() throws IOException {
*/
public static ServerSocket createServerSocket(
ServerSocketFactory socketFactory) throws IOException {
ServerSocket socket = null;
ServerSocket serverSocket = null;
int retries = 10;
while (retries-- > 0 && socket == null) {
while (retries-- > 0 && serverSocket == null) {
int port = (int)((65536 - 1024) * Math.random()) + 1024;
try {
socket = socketFactory.createServerSocket(port);
serverSocket = socketFactory.createServerSocket(port);
}
catch (BindException ex) {
// try again with different port
}
}
if (socket == null) {
if (serverSocket == null) {
throw new BindException("cannot find an unused port to bind");
}
return socket;
return serverSocket;
}

}

0 comments on commit 0b238a4

Please sign in to comment.