int findAvailablePort(int minPort, int maxPort) {
            isTrue(minPort > 0, "'minPort' must be greater than 0");
            isTrue(maxPort > minPort, "'maxPort' must be greater than 'minPort'");
            isTrue(maxPort <= PORT_RANGE_MAX, "'maxPort' must be less than or equal to " + PORT_RANGE_MAX);

            int portRange = maxPort - minPort;
            int candidatePort;
            int searchCounter = 0;
            do {
                if (++searchCounter > portRange) {
                    throw new IllegalStateException(String.format(
                            "Could not find an available %s port in the range [%d, %d] after %d attempts", name(), minPort,
                            maxPort, searchCounter));
                }
                candidatePort = findRandomPort(minPort, maxPort);
            }
            while (!isPortAvailable(candidatePort));

            return candidatePort;
        }
Find an available port for this {@code SocketType}, randomly selected
from the range [{@code minPort}, {@code maxPort}].
@param minPort the minimum port number
@param maxPort the maximum port number
@return an available port number for this socket type
@throws IllegalStateException if no available port could be found
agent-module/plugins-test-module/testcase/src/main/java/com/navercorp/pinpoint/testcase/util/SocketUtils.java