diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestHedgingRequestRMFailoverProxyProvider.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestHedgingRequestRMFailoverProxyProvider.java index 6fd6591..0850b33 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestHedgingRequestRMFailoverProxyProvider.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestHedgingRequestRMFailoverProxyProvider.java @@ -32,8 +32,6 @@ @Test public void testHedgingRequestProxyProvider() throws Exception { - final MiniYARNCluster cluster = - new MiniYARNCluster("testHedgingRequestProxyProvider", 5, 0, 1, 1); Configuration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); @@ -42,42 +40,45 @@ public void testHedgingRequestProxyProvider() throws Exception { conf.set(YarnConfiguration.RM_HA_IDS, "rm1,rm2,rm3,rm4,rm5"); conf.set(YarnConfiguration.CLIENT_FAILOVER_PROXY_PROVIDER, - RequestHedgingRMFailoverProxyProvider.class.getName()); + RequestHedgingRMFailoverProxyProvider.class.getName()); conf.setLong(YarnConfiguration.RESOURCEMANAGER_CONNECT_RETRY_INTERVAL_MS, - 2000); + 2000); - HATestUtil.setRpcAddressForRM("rm1", 10000, conf); - HATestUtil.setRpcAddressForRM("rm2", 20000, conf); - HATestUtil.setRpcAddressForRM("rm3", 30000, conf); - HATestUtil.setRpcAddressForRM("rm4", 40000, conf); - HATestUtil.setRpcAddressForRM("rm5", 50000, conf); - conf.setBoolean(YarnConfiguration.YARN_MINICLUSTER_FIXED_PORTS, true); + try (MiniYARNCluster cluster = + new MiniYARNCluster("testHedgingRequestProxyProvider", 5, 0, 1, 1)) { - cluster.init(conf); - cluster.start(); + HATestUtil.setRpcAddressForRM("rm1", 10000, conf); + HATestUtil.setRpcAddressForRM("rm2", 20000, conf); + HATestUtil.setRpcAddressForRM("rm3", 30000, conf); + HATestUtil.setRpcAddressForRM("rm4", 40000, conf); + HATestUtil.setRpcAddressForRM("rm5", 50000, conf); + conf.setBoolean(YarnConfiguration.YARN_MINICLUSTER_FIXED_PORTS, true); - final YarnClient client = YarnClient.createYarnClient(); - client.init(conf); - client.start(); + cluster.init(conf); + cluster.start(); - // Transition rm5 to active; - long start = System.currentTimeMillis(); - makeRMActive(cluster, 4); - // client will retry until the rm becomes active. - client.getAllQueues(); - long end = System.currentTimeMillis(); - System.out.println("Client call succeeded at " + end); - // should return the response fast - Assert.assertTrue(end - start <= 10000); + final YarnClient client = YarnClient.createYarnClient(); + client.init(conf); + client.start(); - // transition rm5 to standby - cluster.getResourceManager(4).getRMContext().getRMAdminService() - .transitionToStandby(new HAServiceProtocol.StateChangeRequestInfo( - HAServiceProtocol.RequestSource.REQUEST_BY_USER)); + // Transition rm5 to active; + long start = System.currentTimeMillis(); + makeRMActive(cluster, 4); + // client will retry until the rm becomes active. + client.getAllQueues(); + long end = System.currentTimeMillis(); + System.out.println("Client call succeeded at " + end); + // should return the response fast + Assert.assertTrue(end - start <= 10000); - makeRMActive(cluster, 2); - client.getAllQueues(); - cluster.stop(); + // transition rm5 to standby + cluster.getResourceManager(4).getRMContext().getRMAdminService() + .transitionToStandby(new HAServiceProtocol.StateChangeRequestInfo( + HAServiceProtocol.RequestSource.REQUEST_BY_USER)); + + makeRMActive(cluster, 2); + client.getAllQueues(); + } } private void makeRMActive(final MiniYARNCluster cluster, final int index) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMProxy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMProxy.java index b92538a..15b789f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMProxy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMProxy.java @@ -86,11 +86,10 @@ */ @Test(timeout = 60000) public void testAMRMProxyE2E() throws Exception { - MiniYARNCluster cluster = new MiniYARNCluster("testAMRMProxyE2E", 1, 1, 1); YarnClient rmClient = null; ApplicationMasterProtocol client; - try { + try (MiniYARNCluster cluster = new MiniYARNCluster("testAMRMProxyE2E", 1, 1, 1)) { Configuration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.AMRM_PROXY_ENABLED, true); cluster.init(conf); @@ -164,7 +163,6 @@ public void testAMRMProxyE2E() throws Exception { if (rmClient != null) { rmClient.stop(); } - cluster.stop(); } } @@ -175,12 +173,11 @@ public void testAMRMProxyE2E() throws Exception { */ @Test(timeout = 60000) public void testE2ETokenRenewal() throws Exception { - MiniYARNCluster cluster = - new MiniYARNCluster("testE2ETokenRenewal", 1, 1, 1); YarnClient rmClient = null; ApplicationMasterProtocol client; - try { + try (MiniYARNCluster cluster = + new MiniYARNCluster("testE2ETokenRenewal", 1, 1, 1)) { Configuration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.AMRM_PROXY_ENABLED, true); conf.setInt(YarnConfiguration.RM_NM_EXPIRY_INTERVAL_MS, 1500); @@ -244,7 +241,6 @@ public void testE2ETokenRenewal() throws Exception { if (rmClient != null) { rmClient.stop(); } - cluster.stop(); } } @@ -254,11 +250,10 @@ public void testE2ETokenRenewal() throws Exception { */ @Test(timeout = 60000) public void testE2ETokenSwap() throws Exception { - MiniYARNCluster cluster = new MiniYARNCluster("testE2ETokenSwap", 1, 1, 1); YarnClient rmClient = null; ApplicationMasterProtocol client; - try { + try (MiniYARNCluster cluster = new MiniYARNCluster("testE2ETokenSwap", 1, 1, 1)) { Configuration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.AMRM_PROXY_ENABLED, true); cluster.init(conf); @@ -287,7 +282,6 @@ public void testE2ETokenSwap() throws Exception { if (rmClient != null) { rmClient.stop(); } - cluster.stop(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java index 5bef691..44e6aec 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java @@ -1558,11 +1558,10 @@ public void testGetQueueInfoPreemptionDisabled() throws Exception { conf.setBoolean(YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS, true); conf.setBoolean( "yarn.scheduler.capacity.root.a.a1.disable_preemption", true); - MiniYARNCluster cluster = - new MiniYARNCluster("testReservationAPIs", 2, 1, 1); YarnClient yarnClient = null; - try { + try (MiniYARNCluster cluster = + new MiniYARNCluster("testReservationAPIs", 2, 1, 1)) { cluster.init(conf); cluster.start(); final Configuration yarnConf = cluster.getConfig(); @@ -1584,8 +1583,6 @@ public void testGetQueueInfoPreemptionDisabled() throws Exception { if (yarnClient != null) { yarnClient.stop(); } - cluster.stop(); - cluster.close(); } }