OOZIE-3633 TestIntegrationGitActionExecutor can fail due to "Address already in use" (dionusos via asalamon74)
diff --git a/release-log.txt b/release-log.txt
index 1fa6d56..2a48d30 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 5.3.0 release (trunk - unreleased)
 
+OOZIE-3633 TestIntegrationGitActionExecutor can fail due to "Address already in use" (dionusos via asalamon74)
 OOZIE-3631 Small typo error in WorkflowJob.java (lyoungzzz via dionusos)
 OOZIE-3630 Small typo in README (ajs6f via asalamon74)
 OOZIE-2136 Oozie server startup error when JDBC URL for a MySql DB with HA is used (dionusos)
diff --git a/sharelib/git/src/test/java/org/apache/oozie/action/hadoop/GitServer.java b/sharelib/git/src/test/java/org/apache/oozie/action/hadoop/GitServer.java
index 8398e5f..cf89c53 100644
--- a/sharelib/git/src/test/java/org/apache/oozie/action/hadoop/GitServer.java
+++ b/sharelib/git/src/test/java/org/apache/oozie/action/hadoop/GitServer.java
@@ -51,14 +51,10 @@
      */
     private final Map<String, Repository> repositories = new HashMap<>();
     private Daemon server;
-    private final int localPort;
+    private int localPort;
 
     GitServer() throws IOException {
         LOG.info("Creating Git server");
-
-        this.localPort = findAvailablePort();
-
-        LOG.info("Git server created, port {0} will be used", this.localPort);
     }
 
     void start() throws IOException {
@@ -68,28 +64,19 @@
             return;
         }
 
-        LOG.info("Starting Git server on port {0}", this.localPort);
-
-        this.server = new Daemon(new InetSocketAddress(this.localPort));
+        this.server = new Daemon();
         this.server.getService("git-receive-pack").setEnabled(true);
         this.server.setRepositoryResolver(new EmptyRepositoryResolverImplementation());
         this.server.start();
+        this.localPort = this.server.getAddress().getPort();
 
-        LOG.info("Git server started");
+        LOG.info("Git server started and port {0} will be used", this.localPort);
     }
 
     int getLocalPort() {
         return localPort;
     }
 
-    private int findAvailablePort() throws IOException {
-        try (final ServerSocket serverSocket = new ServerSocket(0)) {
-            final int availablePort = serverSocket.getLocalPort();
-            LOG.info("Found available port {0}", availablePort);
-            return availablePort;
-        }
-    }
-
     void stopAndCleanupReposServer() {
         cleanUpRepos();
         if (this.server == null || !this.server.isRunning()) {
diff --git a/sharelib/git/src/test/java/org/apache/oozie/action/hadoop/TestIntegrationGitActionExecutor.java b/sharelib/git/src/test/java/org/apache/oozie/action/hadoop/TestIntegrationGitActionExecutor.java
index 20368da..a1f83f5 100644
--- a/sharelib/git/src/test/java/org/apache/oozie/action/hadoop/TestIntegrationGitActionExecutor.java
+++ b/sharelib/git/src/test/java/org/apache/oozie/action/hadoop/TestIntegrationGitActionExecutor.java
@@ -46,21 +46,22 @@
         final Path gitIndex = Path.mergePaths(gitRepo, new Path("/.git/config"));
 
         final GitServer gitServer = new GitServer();
-
-        final String localRepo = String.format("git://127.0.0.1:%s/repo.git", gitServer.getLocalPort());
-        final String actionXml = "<git>" +
-                "<resource-manager>" + getJobTrackerUri() + "</resource-manager>" +
-                "<name-node>" + getNameNodeUri() + "</name-node>" +
-                "<git-uri>" + localRepo + "</git-uri>"+
-                "<destination-uri>" + gitRepo + "</destination-uri>" +
-                "</git>";
-
-        final Context context = createContext(actionXml);
-        final String launcherId = submitAction(context);
-
+        final Context context;
+        final String launcherId;
         try {
             gitServer.start();
 
+            final String localRepo = String.format("git://127.0.0.1:%s/repo.git", gitServer.getLocalPort());
+            final String actionXml = "<git>" +
+                    "<resource-manager>" + getJobTrackerUri() + "</resource-manager>" +
+                    "<name-node>" + getNameNodeUri() + "</name-node>" +
+                    "<git-uri>" + localRepo + "</git-uri>"+
+                    "<destination-uri>" + gitRepo + "</destination-uri>" +
+                    "</git>";
+
+            context = createContext(actionXml);
+            launcherId = submitAction(context);
+
             waitUntilYarnAppDoneAndAssertSuccess(launcherId);
         }
         finally {