@Test
  public void testCountersFromHistoryServer() throws Exception {
    MRClientProtocol historyServerProxy = mock(MRClientProtocol.class);
    when(historyServerProxy.getCounters(getCountersRequest()))
        .thenReturn(getCountersResponseFromHistoryServer());
    ResourceMgrDelegate rm = mock(ResourceMgrDelegate.class);
    when(rm.getApplicationReport(TypeConverter.toYarn(oldJobId).getAppId())).thenReturn(null);
    ClientServiceDelegate clientServiceDelegate = getClientServiceDelegate(historyServerProxy, rm);

    Counters counters = TypeConverter.toYarn(clientServiceDelegate.getJobCounters(oldJobId));
    Assert.assertNotNull(counters);
    Assert.assertEquals(
        1001, counters.getCounterGroup("dummyCounters").getCounter("dummyCounter").getValue());
  }
 private GetCountersResponse getCountersResponseFromHistoryServer() {
   GetCountersResponse countersResponse = Records.newRecord(GetCountersResponse.class);
   Counter counter = Records.newRecord(Counter.class);
   CounterGroup counterGroup = Records.newRecord(CounterGroup.class);
   Counters counters = Records.newRecord(Counters.class);
   counter.setDisplayName("dummyCounter");
   counter.setName("dummyCounter");
   counter.setValue(1001);
   counterGroup.setName("dummyCounters");
   counterGroup.setDisplayName("dummyCounters");
   counterGroup.setCounter("dummyCounter", counter);
   counters.setCounterGroup("dummyCounters", counterGroup);
   countersResponse.setCounters(counters);
   return countersResponse;
 }
  static Counters getMyCounters() {
    Counter counter = recordFactory.newRecordInstance(Counter.class);
    counter.setName("Mycounter");
    counter.setDisplayName("My counter display name");
    counter.setValue(12345);

    CounterGroup group = recordFactory.newRecordInstance(CounterGroup.class);
    group.setName("MyGroup");
    group.setDisplayName("My groupd display name");
    group.setCounter("myCounter", counter);

    Counters counters = recordFactory.newRecordInstance(Counters.class);
    counters.setCounterGroup("myGroupd", group);
    return counters;
  }