@Override
  public GetApplicationsResponse
      getApplications(GetApplicationsRequest request) throws YarnException,
          IOException {
    long startedBegin =
        request.getStartRange() == null ? 0L : request.getStartRange()
          .getMinimum();
    long startedEnd =
        request.getStartRange() == null ? Long.MAX_VALUE : request
          .getStartRange().getMaximum();
    GetApplicationsResponse response =
        GetApplicationsResponse.newInstance(new ArrayList<ApplicationReport>(
          history.getApplications(request.getLimit(), startedBegin, startedEnd)
            .values()));
    return response;
  }
@Test
  void testApplications() throws IOException, YarnException {
    ApplicationId appId = null;
    appId = ApplicationId.newInstance(0, 1);
    ApplicationId appId1 = ApplicationId.newInstance(0, 2);
    GetApplicationsRequest request = GetApplicationsRequest.newInstance();
    GetApplicationsResponse response =
        clientService.getApplications(request);
    List<ApplicationReport> appReport = response.getApplicationList();
    assertNotNull(appReport);
    assertEquals(appId, appReport.get(1).getApplicationId());
    assertEquals(appId1, appReport.get(0).getApplicationId());

    // Create a historyManager, and set the max_apps can be loaded
    // as 1.
    Configuration conf = new YarnConfiguration();
    conf.setLong(YarnConfiguration.APPLICATION_HISTORY_MAX_APPS, 1);
    ApplicationHistoryManagerOnTimelineStore historyManager2 =
        new ApplicationHistoryManagerOnTimelineStore(dataManager,
            new ApplicationACLsManager(conf));
    historyManager2.init(conf);
    historyManager2.start();
    @SuppressWarnings("resource")
    ApplicationHistoryClientService clientService2 =
        new ApplicationHistoryClientService(historyManager2);
    response = clientService2.getApplications(request);
    appReport = response.getApplicationList();
    assertNotNull(appReport);
    assertTrue(appReport.size() == 1);
    // Expected to get the appReport for application with appId1
    assertEquals(appId1, appReport.get(0).getApplicationId());
  }