GitHub PullRequestReviewCommentEvent at 2014-03-28 22:47:56
Repository: loom
Actor: albertshau
Payload: {"comment":{"url":"https://api.github.com/repos/continuuity/loom/pulls/comments/11088965","id":11088965,"diff_hunk":"@@ -97,15 +99,44 @@\n \n   public static final String ACTION_TABLE_CLASSNAME = \".node-actions-table\";\n \n-  public static int getPort() {\n-    int port = -1;\n+  // the ports below 1024 are system ports\n+  private static final int MIN_PORT_NUMBER = 1024;\n+\n+  // the ports above 49151 are dynamic and/or private\n+  private static final int MAX_PORT_NUMBER = 49151;\n+\n+  public static int findFreePort() {\n+    for (int i = MIN_PORT_NUMBER; i <= MAX_PORT_NUMBER; i++) {\n+      if (available(i)) {\n+        return i;\n+      }\n+    }\n+    throw new RuntimeException(\"Could not find an available port between \" +\n+                                 MIN_PORT_NUMBER + \" and \" + MAX_PORT_NUMBER);\n+  }\n+\n+  private static boolean available(final int port) {\n+    ServerSocket serverSocket = null;\n+    DatagramSocket dataSocket = null;\n     try {\n-      ServerSocket s = new ServerSocket(0);\n-      port = s.getLocalPort();","path":"integration-testing/src/test/java/com/continuuity/test/Constants.java","position":45,"original_position":45,"commit_id":"f5073e407cbb828a1f3527c2f55a2581177625ef","original_commit_id":"f5073e407cbb828a1f3527c2f55a2581177625ef","user":{"login":"albertshau","id":5215004,"avatar_url":"https://avatars.githubusercontent.com/u/5215004?","gravatar_id":"3e72ca893286eef388d87ed0f25c10e0","url":"https://api.github.com/users/albertshau","html_url":"https://github.com/albertshau","followers_url":"https://api.github.com/users/albertshau/followers","following_url":"https://api.github.com/users/albertshau/following{/other_user}","gists_url":"https://api.github.com/users/albertshau/gists{/gist_id}","starred_url":"https://api.github.com/users/albertshau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/albertshau/subscriptions","organizations_url":"https://api.github.com/users/albertshau/orgs","repos_url":"https://api.github.com/users/albertshau/repos","events_url":"https://api.github.com/users/albertshau/events{/privacy}","received_events_url":"https://api.github.com/users/albertshau/received_events","type":"User","site_admin":false},"body":"just need a s.close() here instead of all the other changes","created_at":"2014-03-28T22:47:56Z","updated_at":"2014-03-28T22:47:56Z","html_url":"https://github.com/continuuity/loom/pull/26#discussion_r11088965","pull_request_url":"https://api.github.com/repos/continuuity/loom/pulls/26","_links":{"self":{"href":"https://api.github.com/repos/continuuity/loom/pulls/comments/11088965"},"html":{"href":"https://github.com/continuuity/loom/pull/26#discussion_r11088965"},"pull_request":{"href":"https://api.github.com/repos/continuuity/loom/pulls/26"}}}}