goiri commented on code in PR #4540:
URL: https://github.com/apache/hadoop/pull/4540#discussion_r918200085


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestRouterYarnClientUtils.java:
##########
@@ -27,14 +27,7 @@
 
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
-import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse;
-import org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsResponse;
-import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse;
-import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeLabelsResponse;
-import org.apache.hadoop.yarn.api.protocolrecords.GetLabelsToNodesResponse;
-import org.apache.hadoop.yarn.api.protocolrecords.GetQueueUserAclsInfoResponse;
-import org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse;
-import 
org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
+import org.apache.hadoop.yarn.api.protocolrecords.*;

Review Comment:
   Avoid



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java:
##########
@@ -1169,4 +1172,57 @@ public void testGetQueueInfo() throws Exception {
     Assert.assertEquals(queueInfo.getChildQueues().size(), 12, 0);
     Assert.assertEquals(queueInfo.getAccessibleNodeLabels().size(), 1);
   }
+
+  @Test
+  public void testGetResourceProfiles() throws Exception {
+    LOG.info("Test FederationClientInterceptor : Get Resource Profiles 
request.");
+
+    // null request
+    LambdaTestUtils.intercept(YarnException.class, "Missing 
getResourceProfiles request.",
+        () -> interceptor.getResourceProfiles(null));
+
+    // normal request
+    GetAllResourceProfilesRequest request = 
GetAllResourceProfilesRequest.newInstance();
+    GetAllResourceProfilesResponse response = 
interceptor.getResourceProfiles(request);
+
+    Assert.assertNotNull(response);
+    
Assert.assertEquals(response.getResourceProfiles().get("maximum").getMemorySize(),
  32768);

Review Comment:
   Can we extract some of these?
   resProfiles = response.getResourceProfiles()
   maxResProfiles = resProfiles.get("maximum")



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java:
##########
@@ -1169,4 +1172,57 @@ public void testGetQueueInfo() throws Exception {
     Assert.assertEquals(queueInfo.getChildQueues().size(), 12, 0);
     Assert.assertEquals(queueInfo.getAccessibleNodeLabels().size(), 1);
   }
+
+  @Test
+  public void testGetResourceProfiles() throws Exception {
+    LOG.info("Test FederationClientInterceptor : Get Resource Profiles 
request.");
+
+    // null request
+    LambdaTestUtils.intercept(YarnException.class, "Missing 
getResourceProfiles request.",
+        () -> interceptor.getResourceProfiles(null));
+
+    // normal request
+    GetAllResourceProfilesRequest request = 
GetAllResourceProfilesRequest.newInstance();
+    GetAllResourceProfilesResponse response = 
interceptor.getResourceProfiles(request);
+
+    Assert.assertNotNull(response);
+    
Assert.assertEquals(response.getResourceProfiles().get("maximum").getMemorySize(),
  32768);
+    
Assert.assertEquals(response.getResourceProfiles().get("maximum").getVirtualCores(),
  16);
+    
Assert.assertEquals(response.getResourceProfiles().get("default").getMemorySize(),
  8192);
+    
Assert.assertEquals(response.getResourceProfiles().get("default").getVirtualCores(),
  8);
+    
Assert.assertEquals(response.getResourceProfiles().get("minimum").getMemorySize(),
  4096);
+    
Assert.assertEquals(response.getResourceProfiles().get("minimum").getVirtualCores(),
  4);
+  }
+
+  @Test
+  public void testGetResourceProfile() throws Exception {
+    LOG.info("Test FederationClientInterceptor : Get Resource Profile 
request.");
+
+    // null request
+    LambdaTestUtils.intercept(YarnException.class,
+        "Missing getResourceProfile request or profileName.",
+        () -> interceptor.getResourceProfile(null));
+
+    // normal request
+    GetResourceProfileRequest request = 
GetResourceProfileRequest.newInstance("maximum");
+    GetResourceProfileResponse response = 
interceptor.getResourceProfile(request);
+
+    Assert.assertNotNull(response);
+    Assert.assertEquals(response.getResource().getMemorySize(), 32768);
+    Assert.assertEquals(response.getResource().getVirtualCores(), 16);
+
+    request = GetResourceProfileRequest.newInstance("default");

Review Comment:
   request2 and response2?



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestRouterYarnClientUtils.java:
##########
@@ -539,4 +532,73 @@ public void testMergeResourceTypes() {
     Assert.assertTrue(CollectionUtils.isEqualCollection(expectedResponse,
         response.getResourceTypeInfo()));
   }
+
+  @Test
+  public void testMergeResourceProfiles() {
+    // normal response1
+    Map<String, Resource> profiles = new HashMap<>();
+    Resource resource1 = Resource.newInstance(1024, 1);
+    GetAllResourceProfilesResponse response1 = 
GetAllResourceProfilesResponse.newInstance();
+    profiles.put("maximum", resource1);
+    response1.setResourceProfiles(profiles);
+
+    // normal response2
+    profiles = new HashMap<>();
+    Resource resource2 = Resource.newInstance(2048, 2);
+    GetAllResourceProfilesResponse response2 = 
GetAllResourceProfilesResponse.newInstance();
+    profiles.put("maximum", resource2);
+    response2.setResourceProfiles(profiles);
+
+    // empty response
+    GetAllResourceProfilesResponse response3 = 
GetAllResourceProfilesResponse.newInstance();
+
+    // null response
+    GetAllResourceProfilesResponse response4 = null;
+
+    List<GetAllResourceProfilesResponse> responses = new ArrayList<>();
+    responses.add(response1);
+    responses.add(response2);
+    responses.add(response3);
+    responses.add(response4);
+
+    GetAllResourceProfilesResponse response =
+        RouterYarnClientUtils.mergeClusterResourceProfilesResponse(responses);
+    Resource resource = response.getResourceProfiles().get("maximum");
+    Assert.assertEquals(resource.getVirtualCores(), 3);
+    Assert.assertEquals(resource.getMemorySize(), 3072);
+  }
+
+  @Test
+  public void testMergeResourceProfile() {
+    // normal response1
+    Resource resource1 = Resource.newInstance(1024, 1);
+    GetResourceProfileResponse response1 =
+        Records.newRecord(GetResourceProfileResponse.class);
+    response1.setResource(resource1);
+
+    // normal response2
+    Resource resource2 = Resource.newInstance(2048, 2);
+    GetResourceProfileResponse response2 =
+        Records.newRecord(GetResourceProfileResponse.class);
+    response2.setResource(resource2);
+
+    // empty response
+    GetResourceProfileResponse response3 =
+        Records.newRecord(GetResourceProfileResponse.class);
+
+    // null response
+    GetResourceProfileResponse response4 = null;
+
+    List<GetResourceProfileResponse> responses = new ArrayList<>();
+    responses.add(response1);
+    responses.add(response2);
+    responses.add(response3);
+    responses.add(response4);
+
+    GetResourceProfileResponse response =
+        RouterYarnClientUtils.mergeClusterResourceProfileResponse(responses);
+    Resource resource = response.getResource();
+    Assert.assertEquals(resource.getVirtualCores(), 3);

Review Comment:
   Expected first.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to