slfan1989 commented on code in PR #4793:
URL: https://github.com/apache/hadoop/pull/4793#discussion_r954630046


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java:
##########
@@ -723,6 +728,81 @@ public void testAppsRace() throws Exception {
     assertTrue(appsInfo.getApps().isEmpty());
   }
 
+  @Test
+  public void testGetAppsCache() throws YarnException, InterruptedException, 
TimeoutException {
+    // mock up an RM that returns app reports for apps that don't exist
+    // in the RMApps list
+    ApplicationId appId = ApplicationId.newInstance(1, 1);
+    ApplicationReport mockReport = mock(ApplicationReport.class);
+    when(mockReport.getApplicationId()).thenReturn(appId);
+    GetApplicationsResponse mockAppsResponse =
+        mock(GetApplicationsResponse.class);
+    when(mockAppsResponse.getApplicationList())
+        .thenReturn(Arrays.asList(new ApplicationReport[]{mockReport}));
+
+    ClientRMService mockClientSvc = mock(ClientRMService.class);
+    when(mockClientSvc.getApplications(isA(GetApplicationsRequest.class)))
+        .thenReturn(mockAppsResponse);
+    ResourceManager mockRM = mock(ResourceManager.class);
+    RMContextImpl rmContext = new RMContextImpl(null, null, null, null, null, 
null, null, null,
+        null, null);
+    when(mockRM.getRMContext()).thenReturn(rmContext);
+    when(mockRM.getClientRMService()).thenReturn(mockClientSvc);
+    rmContext.setNodeLabelManager(mock(RMNodeLabelsManager.class));
+
+    Configuration conf = new Configuration();
+    conf.setBoolean(YarnConfiguration.APPS_CACHE_ENABLE, true);
+    conf.setInt(YarnConfiguration.APPS_CACHE_SIZE, 2);
+    conf.setInt(YarnConfiguration.APPS_CACHE_EXPIRE, 100);
+    RMWebServices webSvc = new RMWebServices(mockRM, conf,
+        mock(HttpServletResponse.class));
+    final Set<String> emptySet =
+        Collections.unmodifiableSet(Collections.<String>emptySet());
+
+    // verify we don't get any apps when querying
+    HttpServletRequest mockHsr = mock(HttpServletRequest.class);
+    AppsInfo appsInfo = webSvc.getApps(mockHsr, null, emptySet, null,
+        "mock_user", "mock_queue", null, null,
+        null, null, null, emptySet, emptySet, null,
+        null);

Review Comment:
   avoid



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java:
##########
@@ -723,6 +728,81 @@ public void testAppsRace() throws Exception {
     assertTrue(appsInfo.getApps().isEmpty());
   }
 
+  @Test
+  public void testGetAppsCache() throws YarnException, InterruptedException, 
TimeoutException {
+    // mock up an RM that returns app reports for apps that don't exist
+    // in the RMApps list
+    ApplicationId appId = ApplicationId.newInstance(1, 1);
+    ApplicationReport mockReport = mock(ApplicationReport.class);
+    when(mockReport.getApplicationId()).thenReturn(appId);
+    GetApplicationsResponse mockAppsResponse =
+        mock(GetApplicationsResponse.class);
+    when(mockAppsResponse.getApplicationList())
+        .thenReturn(Arrays.asList(new ApplicationReport[]{mockReport}));
+
+    ClientRMService mockClientSvc = mock(ClientRMService.class);
+    when(mockClientSvc.getApplications(isA(GetApplicationsRequest.class)))
+        .thenReturn(mockAppsResponse);
+    ResourceManager mockRM = mock(ResourceManager.class);
+    RMContextImpl rmContext = new RMContextImpl(null, null, null, null, null, 
null, null, null,
+        null, null);
+    when(mockRM.getRMContext()).thenReturn(rmContext);
+    when(mockRM.getClientRMService()).thenReturn(mockClientSvc);
+    rmContext.setNodeLabelManager(mock(RMNodeLabelsManager.class));
+
+    Configuration conf = new Configuration();
+    conf.setBoolean(YarnConfiguration.APPS_CACHE_ENABLE, true);
+    conf.setInt(YarnConfiguration.APPS_CACHE_SIZE, 2);
+    conf.setInt(YarnConfiguration.APPS_CACHE_EXPIRE, 100);
+    RMWebServices webSvc = new RMWebServices(mockRM, conf,
+        mock(HttpServletResponse.class));
+    final Set<String> emptySet =
+        Collections.unmodifiableSet(Collections.<String>emptySet());
+
+    // verify we don't get any apps when querying
+    HttpServletRequest mockHsr = mock(HttpServletRequest.class);
+    AppsInfo appsInfo = webSvc.getApps(mockHsr, null, emptySet, null,
+        "mock_user", "mock_queue", null, null,
+        null, null, null, emptySet, emptySet, null,
+        null);
+    LRUCache<AppsCacheKey, AppsInfo> cache = webSvc.getAppsLRUCache();
+    Assert.assertEquals(1, cache.size());
+    AppsCacheKey appsCacheKey = AppsCacheKey.newInstance(null, emptySet,
+        null, "mock_user", "mock_queue", null,
+        null, null, null, null, emptySet, emptySet,
+        null, null);
+    Assert.assertEquals(appsInfo, cache.get(appsCacheKey));
+
+    AppsInfo appsInfo1 = webSvc.getApps(mockHsr, null, emptySet, null,
+        "mock_user1", "mock_queue", null, null,
+        null, null, null, emptySet, emptySet, null,
+        null);

Review Comment:
   avoid



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java:
##########
@@ -723,6 +728,81 @@ public void testAppsRace() throws Exception {
     assertTrue(appsInfo.getApps().isEmpty());
   }
 
+  @Test
+  public void testGetAppsCache() throws YarnException, InterruptedException, 
TimeoutException {
+    // mock up an RM that returns app reports for apps that don't exist
+    // in the RMApps list
+    ApplicationId appId = ApplicationId.newInstance(1, 1);
+    ApplicationReport mockReport = mock(ApplicationReport.class);
+    when(mockReport.getApplicationId()).thenReturn(appId);
+    GetApplicationsResponse mockAppsResponse =
+        mock(GetApplicationsResponse.class);
+    when(mockAppsResponse.getApplicationList())
+        .thenReturn(Arrays.asList(new ApplicationReport[]{mockReport}));
+
+    ClientRMService mockClientSvc = mock(ClientRMService.class);
+    when(mockClientSvc.getApplications(isA(GetApplicationsRequest.class)))
+        .thenReturn(mockAppsResponse);
+    ResourceManager mockRM = mock(ResourceManager.class);
+    RMContextImpl rmContext = new RMContextImpl(null, null, null, null, null, 
null, null, null,
+        null, null);
+    when(mockRM.getRMContext()).thenReturn(rmContext);
+    when(mockRM.getClientRMService()).thenReturn(mockClientSvc);
+    rmContext.setNodeLabelManager(mock(RMNodeLabelsManager.class));
+
+    Configuration conf = new Configuration();
+    conf.setBoolean(YarnConfiguration.APPS_CACHE_ENABLE, true);
+    conf.setInt(YarnConfiguration.APPS_CACHE_SIZE, 2);
+    conf.setInt(YarnConfiguration.APPS_CACHE_EXPIRE, 100);
+    RMWebServices webSvc = new RMWebServices(mockRM, conf,
+        mock(HttpServletResponse.class));
+    final Set<String> emptySet =
+        Collections.unmodifiableSet(Collections.<String>emptySet());
+
+    // verify we don't get any apps when querying
+    HttpServletRequest mockHsr = mock(HttpServletRequest.class);
+    AppsInfo appsInfo = webSvc.getApps(mockHsr, null, emptySet, null,
+        "mock_user", "mock_queue", null, null,
+        null, null, null, emptySet, emptySet, null,
+        null);
+    LRUCache<AppsCacheKey, AppsInfo> cache = webSvc.getAppsLRUCache();
+    Assert.assertEquals(1, cache.size());
+    AppsCacheKey appsCacheKey = AppsCacheKey.newInstance(null, emptySet,
+        null, "mock_user", "mock_queue", null,
+        null, null, null, null, emptySet, emptySet,
+        null, null);

Review Comment:
   avoid



-- 
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