Skip to content

Commit

Permalink
[0.3.2] 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoldu committed May 27, 2018
1 parent 9cebf5a commit 3b63a99
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SqsMockUtils {
public static int findAvailablePort() {
for (int port = 10000; port <= 65535; port++) {
try {
if(!isRunning(String.valueOf(port))){
if(!isRunning(executeGrepProcessCommand(port))){
return port;
}
} catch (IOException ex) {
Expand All @@ -32,10 +32,9 @@ public static int findAvailablePort() {
throw new SqsMockException(message);
}

private static boolean isRunning(String port) throws IOException{
private static boolean isRunning(Process p){
String line;
StringBuilder pidInfo = new StringBuilder();
Process p = executeGrepProcessCommand(port);

try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) {

Expand All @@ -49,8 +48,8 @@ private static boolean isRunning(String port) throws IOException{
return !StringUtils.isEmpty(pidInfo.toString());
}

private static Process executeGrepProcessCommand(String port) throws IOException {
String command = String.format("netstat -nat | grep LISTEN|grep %s", port);
private static Process executeGrepProcessCommand(int port) throws IOException {
String command = String.format("netstat -nat | grep LISTEN|grep %d", port);
String[] shell = {"/bin/sh", "-c", command};
return Runtime.getRuntime().exec(shell);
}
Expand Down

0 comments on commit 3b63a99

Please sign in to comment.