private boolean isPortAvailable(int port) {
    try (ServerSocket socket = new ServerSocket(port, 0,
        InetAddress.getByName(HiveSamlUtils.LOOP_BACK_INTERFACE))) {
      return true;
    } catch (IOException e) {
      return false;
    }
  }
Make sure that the given port is free by binding to it and then releasing it.
@param port
itests/hive-unit/src/test/java/org/apache/hive/service/auth/saml/TestHttpSamlAuthentication.java