Acceptance-tests: Fix 'Address already in use' bug

This change fixes ephemeral port assignment for HTTP and SSH daemons.

Current implementation is broken: it assigns a random port in GerritServer,
closes the socket and effectively freeing it for the kernel to recycle to
another thread, and store that port in gerrit.config file for reuse. Some
time later in HTTP and SSH daemons the port number get read from the config
file and the ports are bound.  The problem is, that during this "think time"
another test got the same port assigned and bind attempt is failing with:

  Caused by: java.net.BindException: Address already in use

To rectify it, set port to 0 in gerrit.config for both HTTP and SSH daemons
and let the daemons to do the ephemeral port assignments.  In SSH and HTTP
daemons this special case is recognized and the assigned ports are written
back to gerrit.config to pass to the test harness side.

Change-Id: Ib4971b200d6dc86268674398fe590137ae35b6f3
diff --git a/Documentation/dev-buck.txt b/Documentation/dev-buck.txt
index 8a45bb4..88a9aa0 100644
--- a/Documentation/dev-buck.txt
+++ b/Documentation/dev-buck.txt
@@ -478,34 +478,17 @@
   EOF
 ----
 
-== Sporadic failures of unit tests
+== Rerun unit tests
 
-Due to implementation of ephemeral port assignment for HTTP and SSH daemons,
-(the reason is explained in depth in this thread:
-https://groups.google.com/forum/#!topic/repo-discuss/db14RJ59ubs),
-unit tests can randomly fail with "BindException: Address already in use".
-In this case, failed tests need to be repeated:
-
-----
-FAIL  32,0s  7 Passed   1 Failed   com.google.gerrit.acceptance.rest.group.AddRemoveGroupMembersIT
-FAILURE includeRemoveGroup: Cannot bind to localhost:40955
-        at com.google.gerrit.sshd.SshDaemon.start(SshDaemon.java:281)
-        at com.google.gerrit.lifecycle.LifecycleManager.start(LifecycleManager.java:74)
-        at com.google.gerrit.pgm.Daemon.start(Daemon.java:288)
-        at com.google.gerrit.acceptance.GerritServer.start(GerritServer.java:81)
-[...]
-Caused by: java.net.BindException: Address already in use
-        at sun.nio.ch.Net.bind0(Native Method)
-----
-
-Because the test execution results are cached by Buck, they must be removed
-before retrying:
+If for some reasons tests, that were already run must be repeated, unit test
+cache must be removed fist. That's because the test execution results are
+cached by Buck:
 
 ----
   $ rm -rf buck-out/bin/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/group/.AddRemoveGroupMembersIT/
 ----
 
-After clearing the cache and repeating of the failed tests, they are successful:
+After clearing the cache test can be rerun again:
 
 ----
   $ buck test //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/group:AddRemoveGroupMembersIT