public int getPort() {
    return this.socket.getLocalPort();
  }
Utility to generate a bound socket. Useful testing for BindException. Use one of the Constructors
to create an instance of this class. On creation it will have put up a ServerSocket on a random
port. Get the port it is bound to using {@link #getPort()}. In your test, then try to start a
Server using same port to generate a BindException. Call {@link #close()} when done to shut down
the Socket.
hbase-common/src/test/java/org/apache/hadoop/hbase/net/BoundSocketMaker.java