You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by su...@apache.org on 2020/05/02 07:29:37 UTC

[hadoop] branch trunk updated: YARN-6553. Replace MockResourceManagerFacade with MockRM for AMRMProxy/Router tests. Contributed by Bilwa S T.

This is an automated email from the ASF dual-hosted git repository.

surendralilhore pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 257b04c  YARN-6553. Replace MockResourceManagerFacade with MockRM for AMRMProxy/Router tests. Contributed by Bilwa S T.
257b04c is described below

commit 257b04ce4e153cb88dfc59eab63625909efdd56b
Author: Surendra Singh Lilhore <su...@apache.org>
AuthorDate: Sat May 2 12:43:20 2020 +0530

    YARN-6553. Replace MockResourceManagerFacade with MockRM for AMRMProxy/Router tests. Contributed by Bilwa S T.
---
 .../hadoop-yarn-server-router/pom.xml              |  7 +++
 .../router/clientrm/BaseRouterClientRMTest.java    | 49 ++++++++++++-----
 .../clientrm/MockClientRequestInterceptor.java     | 45 ++++++++++++++--
 .../clientrm/TestFederationClientInterceptor.java  | 51 ++++++++++--------
 .../TestFederationClientInterceptorRetry.java      | 45 ++++++++++------
 .../router/clientrm/TestRouterClientRMService.java | 12 ++---
 .../TestableFederationClientInterceptor.java       | 63 ++++++++++++++++++----
 .../rmadmin/MockRMAdminRequestInterceptor.java     | 39 +++++++++++---
 8 files changed, 235 insertions(+), 76 deletions(-)

diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/pom.xml
index 1787ae8..d299290 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/pom.xml
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/pom.xml
@@ -68,6 +68,13 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-yarn-server-resourcemanager</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/BaseRouterClientRMTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/BaseRouterClientRMTest.java
index 7fc4719..1d726d3 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/BaseRouterClientRMTest.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/BaseRouterClientRMTest.java
@@ -18,6 +18,8 @@
 
 package org.apache.hadoop.yarn.server.router.clientrm;
 
+import static org.mockito.Mockito.mock;
+
 import java.io.IOException;
 import java.security.PrivilegedExceptionAction;
 import java.util.Collections;
@@ -26,6 +28,7 @@ import java.util.concurrent.Executors;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.yarn.MockApps;
 import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.CancelDelegationTokenResponse;
 import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
@@ -78,6 +81,8 @@ import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
 import org.apache.hadoop.yarn.api.records.ContainerId;
+import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
+import org.apache.hadoop.yarn.api.records.Priority;
 import org.apache.hadoop.yarn.api.records.ReservationDefinition;
 import org.apache.hadoop.yarn.api.records.ReservationId;
 import org.apache.hadoop.yarn.api.records.ReservationRequest;
@@ -88,8 +93,13 @@ import org.apache.hadoop.yarn.api.records.Token;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.event.AsyncDispatcher;
 import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationSystemTestUtil;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
 import org.apache.hadoop.yarn.util.Clock;
 import org.apache.hadoop.yarn.util.UTCClock;
+import org.apache.hadoop.yarn.util.resource.Resources;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -119,7 +129,7 @@ public abstract class BaseRouterClientRMTest {
     return this.clientrmService;
   }
 
-  protected YarnConfiguration createConfiguration() {
+  protected Configuration createConfiguration() {
     YarnConfiguration config = new YarnConfiguration();
     String mockPassThroughInterceptorClass =
         PassThroughClientRequestInterceptor.class.getName();
@@ -134,11 +144,18 @@ public abstract class BaseRouterClientRMTest {
 
     config.setInt(YarnConfiguration.ROUTER_PIPELINE_CACHE_MAX_SIZE,
         TEST_MAX_CACHE_SIZE);
-    return config;
+    CapacitySchedulerConfiguration schedulerConf =
+        new CapacitySchedulerConfiguration(config);
+    ReservationSystemTestUtil.setupQueueConfiguration(schedulerConf);
+    schedulerConf.setClass(YarnConfiguration.RM_SCHEDULER,
+        CapacityScheduler.class, ResourceScheduler.class);
+    schedulerConf.setBoolean(YarnConfiguration.RM_RESERVATION_SYSTEM_ENABLE,
+        true);
+    return schedulerConf;
   }
 
   @Before
-  public void setUp() {
+  public void setUp() throws IOException {
     this.conf = createConfiguration();
     this.dispatcher = new AsyncDispatcher();
     this.dispatcher.init(conf);
@@ -205,13 +222,19 @@ public abstract class BaseRouterClientRMTest {
         .doAs(new PrivilegedExceptionAction<SubmitApplicationResponse>() {
           @Override
           public SubmitApplicationResponse run() throws Exception {
-            ApplicationSubmissionContext context =
-                ApplicationSubmissionContext.newInstance(appId, "", "", null,
-                    null, false, false, -1, null, null);
-            SubmitApplicationRequest req =
-                SubmitApplicationRequest.newInstance(context);
-            SubmitApplicationResponse response =
-                getRouterClientRMService().submitApplication(req);
+            ContainerLaunchContext amContainerSpec = mock(
+                ContainerLaunchContext.class);
+            ApplicationSubmissionContext context = ApplicationSubmissionContext
+                .newInstance(appId, MockApps.newAppName(), "q1",
+                    Priority.newInstance(0), amContainerSpec, false, false, -1,
+                    Resources.createResource(
+                        YarnConfiguration.
+                        DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB),
+                    "MockApp");
+            SubmitApplicationRequest req = SubmitApplicationRequest
+                .newInstance(context);
+            SubmitApplicationResponse response = getRouterClientRMService()
+                .submitApplication(req);
             return response;
           }
         });
@@ -334,9 +357,9 @@ public abstract class BaseRouterClientRMTest {
             long arrival = clock.getTime();
             long duration = 60000;
             long deadline = (long) (arrival + 1.05 * duration);
-
-            ReservationSubmissionRequest req = createSimpleReservationRequest(1,
-                arrival, deadline, duration, reservationId);
+            ReservationSubmissionRequest req = ReservationSystemTestUtil
+                .createSimpleReservationRequest(reservationId, 1, arrival,
+                    deadline, duration);
             ReservationSubmissionResponse response =
                 getRouterClientRMService().submitReservation(req);
             return response;
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/MockClientRequestInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/MockClientRequestInterceptor.java
index b38703f..e0538b8 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/MockClientRequestInterceptor.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/MockClientRequestInterceptor.java
@@ -18,8 +18,12 @@
 
 package org.apache.hadoop.yarn.server.router.clientrm;
 
-import org.apache.hadoop.yarn.conf.YarnConfiguration;
-import org.apache.hadoop.yarn.server.MockResourceManagerFacade;
+import org.apache.hadoop.yarn.api.protocolrecords.MoveApplicationAcrossQueuesRequest;
+import org.apache.hadoop.yarn.api.protocolrecords.MoveApplicationAcrossQueuesResponse;
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.server.resourcemanager.ClientRMService;
+import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
+import org.junit.Assert;
 
 /**
  * This class mocks the ClientRequestInterceptor.
@@ -28,9 +32,40 @@ public class MockClientRequestInterceptor
     extends DefaultClientRequestInterceptor {
 
   public void init(String user) {
-    MockResourceManagerFacade mockRM = new MockResourceManagerFacade(
-        new YarnConfiguration(super.getConf()), 0);
-    super.setRMClient(mockRM);
+    MockRM mockRM = new MockRM(super.getConf()) {
+      @Override
+      protected ClientRMService createClientRMService() {
+        return new ClientRMService(getRMContext(), getResourceScheduler(),
+            rmAppManager, applicationACLsManager, queueACLsManager,
+            getRMContext().getRMDelegationTokenSecretManager()) {
+          @Override
+          protected void serviceStart() {
+            // override to not start rpc handler
+          }
+
+          @Override
+          protected void serviceStop() {
+            // don't do anything
+          }
+
+          @Override
+          public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
+              MoveApplicationAcrossQueuesRequest request) throws YarnException {
+            return MoveApplicationAcrossQueuesResponse.newInstance();
+          }
+        };
+      }
+    };
+    mockRM.init(super.getConf());
+    mockRM.start();
+    try {
+      mockRM.registerNode("127.0.0.1:1", 102400, 100);
+      // allow plan follower to synchronize
+      Thread.sleep(1050);
+    } catch (Exception e) {
+      Assert.fail(e.getMessage());
+    }
+    super.setRMClient(mockRM.getClientRMService());
   }
 
 }
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java
index c49fe4e..ee6e7b8 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java
@@ -18,11 +18,15 @@
 
 package org.apache.hadoop.yarn.server.router.clientrm;
 
+import static org.mockito.Mockito.mock;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
 import java.util.Map;
+
+import org.apache.hadoop.yarn.MockApps;
 import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse;
 import org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsRequest;
@@ -35,6 +39,8 @@ import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationResponse;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
+import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
+import org.apache.hadoop.yarn.api.records.Priority;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.exceptions.YarnException;
 import org.apache.hadoop.yarn.server.federation.policies.manager.UniformBroadcastPolicyManager;
@@ -42,6 +48,8 @@ import org.apache.hadoop.yarn.server.federation.store.impl.MemoryFederationState
 import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
 import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade;
 import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreTestUtil;
+import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
+import org.apache.hadoop.yarn.util.resource.Resources;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -140,9 +148,8 @@ public class TestFederationClientInterceptor extends BaseRouterClientRMTest {
 
     Assert.assertNotNull(response);
     Assert.assertNotNull(response.getApplicationId());
-    Assert.assertTrue(
-        response.getApplicationId().getClusterTimestamp() < NUM_SUBCLUSTER);
-    Assert.assertTrue(response.getApplicationId().getClusterTimestamp() >= 0);
+    Assert.assertTrue(response.getApplicationId()
+        .getClusterTimestamp() == ResourceManager.getClusterTimeStamp());
   }
 
   /**
@@ -154,12 +161,9 @@ public class TestFederationClientInterceptor extends BaseRouterClientRMTest {
       throws YarnException, IOException, InterruptedException {
     LOG.info("Test FederationClientInterceptor: Submit Application");
 
-    ApplicationId appId =
-        ApplicationId.newInstance(System.currentTimeMillis(), 1);
-    ApplicationSubmissionContext context = ApplicationSubmissionContext
-        .newInstance(appId, "", "", null, null, false, false, -1, null, null);
-    SubmitApplicationRequest request =
-        SubmitApplicationRequest.newInstance(context);
+    ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(),
+        1);
+    SubmitApplicationRequest request = mockSubmitApplicationRequest(appId);
 
     SubmitApplicationResponse response = interceptor.submitApplication(request);
 
@@ -169,6 +173,20 @@ public class TestFederationClientInterceptor extends BaseRouterClientRMTest {
     Assert.assertTrue(subClusters.contains(scIdResult));
   }
 
+  private SubmitApplicationRequest mockSubmitApplicationRequest(
+      ApplicationId appId) {
+    ContainerLaunchContext amContainerSpec = mock(ContainerLaunchContext.class);
+    ApplicationSubmissionContext context = ApplicationSubmissionContext
+        .newInstance(appId, MockApps.newAppName(), "q1",
+            Priority.newInstance(0), amContainerSpec, false, false, -1,
+            Resources.createResource(
+                YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB),
+            "MockApp");
+    SubmitApplicationRequest request = SubmitApplicationRequest
+        .newInstance(context);
+    return request;
+  }
+
   /**
    * This test validates the correctness of SubmitApplication in case of
    * multiple submission. The first retry has to be submitted to the same
@@ -182,10 +200,7 @@ public class TestFederationClientInterceptor extends BaseRouterClientRMTest {
 
     ApplicationId appId =
         ApplicationId.newInstance(System.currentTimeMillis(), 1);
-    ApplicationSubmissionContext context = ApplicationSubmissionContext
-        .newInstance(appId, "", "", null, null, false, false, -1, null, null);
-    SubmitApplicationRequest request =
-        SubmitApplicationRequest.newInstance(context);
+    SubmitApplicationRequest request = mockSubmitApplicationRequest(appId);
 
     // First attempt
     SubmitApplicationResponse response = interceptor.submitApplication(request);
@@ -253,11 +268,8 @@ public class TestFederationClientInterceptor extends BaseRouterClientRMTest {
 
     ApplicationId appId =
         ApplicationId.newInstance(System.currentTimeMillis(), 1);
-    ApplicationSubmissionContext context = ApplicationSubmissionContext
-        .newInstance(appId, "", "", null, null, false, false, -1, null, null);
+    SubmitApplicationRequest request = mockSubmitApplicationRequest(appId);
 
-    SubmitApplicationRequest request =
-        SubmitApplicationRequest.newInstance(context);
     // Submit the application we are going to kill later
     SubmitApplicationResponse response = interceptor.submitApplication(request);
 
@@ -331,11 +343,8 @@ public class TestFederationClientInterceptor extends BaseRouterClientRMTest {
 
     ApplicationId appId =
         ApplicationId.newInstance(System.currentTimeMillis(), 1);
-    ApplicationSubmissionContext context = ApplicationSubmissionContext
-        .newInstance(appId, "", "", null, null, false, false, -1, null, null);
+    SubmitApplicationRequest request = mockSubmitApplicationRequest(appId);
 
-    SubmitApplicationRequest request =
-        SubmitApplicationRequest.newInstance(context);
     // Submit the application we want the report later
     SubmitApplicationResponse response = interceptor.submitApplication(request);
 
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptorRetry.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptorRetry.java
index a655c16..3727886 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptorRetry.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptorRetry.java
@@ -18,16 +18,21 @@
 
 package org.apache.hadoop.yarn.server.router.clientrm;
 
+import static org.mockito.Mockito.mock;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.hadoop.yarn.MockApps;
 import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse;
 import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
+import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
+import org.apache.hadoop.yarn.api.records.Priority;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.exceptions.YarnException;
 import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils;
@@ -37,6 +42,8 @@ import org.apache.hadoop.yarn.server.federation.store.records.GetApplicationHome
 import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
 import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade;
 import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreTestUtil;
+import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
+import org.apache.hadoop.yarn.util.resource.Resources;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -73,7 +80,7 @@ public class TestFederationClientInterceptorRetry
   private static List<SubClusterId> scs = new ArrayList<SubClusterId>();
 
   @Override
-  public void setUp() {
+  public void setUp() throws IOException {
     super.setUpConfig();
     interceptor = new TestableFederationClientInterceptor();
 
@@ -204,7 +211,7 @@ public class TestFederationClientInterceptorRetry
     } catch (Exception e) {
       Assert.fail();
     }
-    Assert.assertEquals(Integer.parseInt(good.getId()),
+    Assert.assertEquals(ResourceManager.getClusterTimeStamp(),
         response.getApplicationId().getClusterTimestamp());
   }
 
@@ -222,20 +229,32 @@ public class TestFederationClientInterceptorRetry
     final ApplicationId appId =
         ApplicationId.newInstance(System.currentTimeMillis(), 1);
 
-    ApplicationSubmissionContext context = ApplicationSubmissionContext
-        .newInstance(appId, "", "", null, null, false, false, -1, null, null);
-    final SubmitApplicationRequest request =
-        SubmitApplicationRequest.newInstance(context);
+    final SubmitApplicationRequest request = mockSubmitApplicationRequest(
+        appId);
     try {
       interceptor.submitApplication(request);
       Assert.fail();
     } catch (Exception e) {
-      System.out.println(e.toString());
+      System.out.println(e);
       Assert.assertTrue(e.getMessage()
           .equals(FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE));
     }
   }
 
+  private SubmitApplicationRequest mockSubmitApplicationRequest(
+      ApplicationId appId) {
+    ContainerLaunchContext amContainerSpec = mock(ContainerLaunchContext.class);
+    ApplicationSubmissionContext context = ApplicationSubmissionContext
+        .newInstance(appId, MockApps.newAppName(), "q1",
+            Priority.newInstance(0), amContainerSpec, false, false, -1,
+            Resources.createResource(
+                YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB),
+            "MockApp");
+    SubmitApplicationRequest request = SubmitApplicationRequest
+        .newInstance(context);
+    return request;
+  }
+
   /**
    * This test validates the correctness of SubmitApplication in case the
    * cluster is composed of only 2 bad SubClusters.
@@ -249,10 +268,8 @@ public class TestFederationClientInterceptorRetry
     final ApplicationId appId =
         ApplicationId.newInstance(System.currentTimeMillis(), 1);
 
-    ApplicationSubmissionContext context = ApplicationSubmissionContext
-        .newInstance(appId, "", "", null, null, false, false, -1, null, null);
-    final SubmitApplicationRequest request =
-        SubmitApplicationRequest.newInstance(context);
+    final SubmitApplicationRequest request = mockSubmitApplicationRequest(
+        appId);
     try {
       interceptor.submitApplication(request);
       Assert.fail();
@@ -276,10 +293,8 @@ public class TestFederationClientInterceptorRetry
     final ApplicationId appId =
         ApplicationId.newInstance(System.currentTimeMillis(), 1);
 
-    ApplicationSubmissionContext context = ApplicationSubmissionContext
-        .newInstance(appId, "", "", null, null, false, false, -1, null, null);
-    final SubmitApplicationRequest request =
-        SubmitApplicationRequest.newInstance(context);
+    final SubmitApplicationRequest request = mockSubmitApplicationRequest(
+        appId);
     try {
       interceptor.submitApplication(request);
     } catch (Exception e) {
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestRouterClientRMService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestRouterClientRMService.java
index b03059d..a7bec08 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestRouterClientRMService.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestRouterClientRMService.java
@@ -107,12 +107,6 @@ public class TestRouterClientRMService extends BaseRouterClientRMTest {
         submitApplication(responseGetNewApp.getApplicationId(), user);
     Assert.assertNotNull(responseSubmitApp);
 
-    LOG.info("testRouterClientRMServiceE2E - Kill Application");
-
-    KillApplicationResponse responseKillApp =
-        forceKillApplication(responseGetNewApp.getApplicationId(), user);
-    Assert.assertNotNull(responseKillApp);
-
     LOG.info("testRouterClientRMServiceE2E - Get Cluster Metrics");
 
     GetClusterMetricsResponse responseGetClusterMetrics =
@@ -168,6 +162,12 @@ public class TestRouterClientRMService extends BaseRouterClientRMTest {
     ReservationDeleteResponse responseDeleteReser =
         deleteReservation(user, getNewReservationResponse.getReservationId());
     Assert.assertNotNull(responseDeleteReser);
+
+    LOG.info("testRouterClientRMServiceE2E - Kill Application");
+
+    KillApplicationResponse responseKillApp =
+        forceKillApplication(responseGetNewApp.getApplicationId(), user);
+    Assert.assertNotNull(responseKillApp);
   }
 
   /**
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestableFederationClientInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestableFederationClientInterceptor.java
index e4a1a42..c97d053 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestableFederationClientInterceptor.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestableFederationClientInterceptor.java
@@ -18,14 +18,28 @@
 
 package org.apache.hadoop.yarn.server.router.clientrm;
 
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
+import java.net.ConnectException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
+import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
+import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationResponse;
 import org.apache.hadoop.yarn.exceptions.YarnException;
-import org.apache.hadoop.yarn.server.MockResourceManagerFacade;
 import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
+import org.apache.hadoop.yarn.server.resourcemanager.ClientRMService;
+import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
+import org.apache.hadoop.yarn.server.resourcemanager.RMAppManager;
+import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler;
+import org.apache.hadoop.yarn.server.resourcemanager.security.QueueACLsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.security.RMDelegationTokenSecretManager;
+import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
+import org.junit.Assert;
 
 /**
  * Extends the FederationClientInterceptor and overrides methods to provide a
@@ -34,7 +48,7 @@ import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
 public class TestableFederationClientInterceptor
     extends FederationClientInterceptor {
 
-  private ConcurrentHashMap<SubClusterId, MockResourceManagerFacade> mockRMs =
+  private ConcurrentHashMap<SubClusterId, MockRM> mockRMs =
       new ConcurrentHashMap<>();
 
   private List<SubClusterId> badSubCluster = new ArrayList<SubClusterId>();
@@ -43,32 +57,61 @@ public class TestableFederationClientInterceptor
   protected ApplicationClientProtocol getClientRMProxyForSubCluster(
       SubClusterId subClusterId) throws YarnException {
 
-    MockResourceManagerFacade mockRM = null;
+    MockRM mockRM = null;
     synchronized (this) {
       if (mockRMs.containsKey(subClusterId)) {
         mockRM = mockRMs.get(subClusterId);
       } else {
-        mockRM = new MockResourceManagerFacade(super.getConf(), 0,
-            Integer.parseInt(subClusterId.getId()),
-            !badSubCluster.contains(subClusterId));
+        mockRM = new MockRM();
+        if (badSubCluster.contains(subClusterId)) {
+          RMContext rmContext = mock(RMContext.class);
+          return new MockClientRMService(rmContext, null, null, null, null,
+              null);
+        }
+        mockRM.init(super.getConf());
+        mockRM.start();
+        try {
+          mockRM.registerNode("h1:1234", 1024);
+        } catch (Exception e) {
+          Assert.fail(e.getMessage());
+        }
         mockRMs.put(subClusterId, mockRM);
-
       }
-      return mockRM;
+      return mockRM.getClientRMService();
     }
   }
 
+  private static class MockClientRMService extends ClientRMService {
+
+    MockClientRMService(RMContext rmContext, YarnScheduler scheduler,
+        RMAppManager rmAppManager,
+        ApplicationACLsManager applicationACLsManager,
+        QueueACLsManager queueACLsManager,
+        RMDelegationTokenSecretManager rmDTSecretManager) {
+      super(rmContext, scheduler, rmAppManager, applicationACLsManager,
+          queueACLsManager, rmDTSecretManager);
+    }
+
+    @Override
+    public SubmitApplicationResponse submitApplication(
+        SubmitApplicationRequest request) throws YarnException, IOException {
+      throw new ConnectException("RM is stopped");
+    }
+
+  }
+
   /**
    * For testing purpose, some subclusters has to be down to simulate particular
    * scenarios as RM Failover, network issues. For this reason we keep track of
    * these bad subclusters. This method make the subcluster unusable.
    *
    * @param badSC the subcluster to make unusable
+   * @throws IOException
    */
-  protected void registerBadSubCluster(SubClusterId badSC) {
+  protected void registerBadSubCluster(SubClusterId badSC) throws IOException {
     badSubCluster.add(badSC);
     if (mockRMs.contains(badSC)) {
-      mockRMs.get(badSC).setRunningMode(false);
+      mockRMs.get(badSC).close();
     }
   }
 
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/rmadmin/MockRMAdminRequestInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/rmadmin/MockRMAdminRequestInterceptor.java
index ab7bdb4..ee55b63 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/rmadmin/MockRMAdminRequestInterceptor.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/rmadmin/MockRMAdminRequestInterceptor.java
@@ -18,8 +18,13 @@
 
 package org.apache.hadoop.yarn.server.router.rmadmin;
 
-import org.apache.hadoop.yarn.conf.YarnConfiguration;
-import org.apache.hadoop.yarn.server.MockResourceManagerFacade;
+import java.io.IOException;
+
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshServiceAclsRequest;
+import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshServiceAclsResponse;
+import org.apache.hadoop.yarn.server.resourcemanager.AdminService;
+import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
 
 /**
  * This class mocks the RMAmdinRequestInterceptor.
@@ -28,9 +33,31 @@ public class MockRMAdminRequestInterceptor
     extends DefaultRMAdminRequestInterceptor {
 
   public void init(String user) {
-    MockResourceManagerFacade mockRM = new MockResourceManagerFacade(
-        new YarnConfiguration(super.getConf()), 0);
-    super.setRMAdmin(mockRM);
-  }
+    MockRM mockRM = new MockRM(super.getConf()) {
+      @Override
+      protected AdminService createAdminService() {
+        return new AdminService(this) {
+          @Override
+          protected void startServer() {
+            // override to not start rpc handler
+          }
 
+          @Override
+          public RefreshServiceAclsResponse refreshServiceAcls(
+              RefreshServiceAclsRequest request)
+              throws YarnException, IOException {
+            return RefreshServiceAclsResponse.newInstance();
+          }
+
+          @Override
+          protected void stopServer() {
+            // don't do anything
+          }
+        };
+      }
+    };
+    mockRM.init(super.getConf());
+    mockRM.start();
+    super.setRMAdmin(mockRM.getAdminService());
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org