From 2213a40f3098eba523ce41e848fbf23e3fe3a849 Mon Sep 17 00:00:00 2001 From: Naganarasimha Date: Fri, 15 Apr 2016 23:37:05 +0530 Subject: [PATCH] YARN-4909. Fix intermittent failures of TestRMWebServices And TestRMWithCSRFFilter. Contributed by Bibin A Chundatt (cherry picked from commit fdbafbc9e59314d9f9f75e615de9d2dfdced017b) --- .../hadoop/yarn/webapp/JerseyTestBase.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/JerseyTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/JerseyTestBase.java index 7a225a3999e..d537fa748f9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/JerseyTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/JerseyTestBase.java @@ -19,9 +19,10 @@ package org.apache.hadoop.yarn.webapp; import java.io.IOException; +import java.util.Random; import org.apache.hadoop.net.ServerSocketUtil; -import org.junit.Before; + import com.sun.jersey.test.framework.JerseyTest; import com.sun.jersey.test.framework.WebAppDescriptor; @@ -30,9 +31,16 @@ public abstract class JerseyTestBase extends JerseyTest { super(appDescriptor); } - @Before - public void initializeJerseyPort() throws IOException { - int jerseyPort = ServerSocketUtil.getPort(9998, 10); - System.setProperty("jersey.test.port", Integer.toString(jerseyPort)); + @Override + protected int getPort(int port) { + Random rand = new Random(); + int jerseyPort = port + rand.nextInt(1000); + try { + jerseyPort = ServerSocketUtil.getPort(jerseyPort, 10); + } catch (IOException e) { + // Ignore exception even after 10 times free port is + // not received. + } + return super.getPort(jerseyPort); } }