@Test
  public void testSumWithThrottling() throws Exception {
    ArgumentCaptor<AggregateResponse> responseCaptor =
      ArgumentCaptor.forClass(AggregateResponse.class);
    RpcCallback<AggregateResponse> callback = mock(RpcCallback.class);

    aggregate.getSum(controller, request, callback);

    verify(callback).run(responseCaptor.capture());

    AggregateResponse response = responseCaptor.getValue();
    assertTrue("Response should indicate there are more rows", response.hasNextChunkStartRow());
    assertEquals("Wait interval should be set", 1000, response.getWaitIntervalMs());
    ByteString b = response.getFirstPart(0);
    HBaseProtos.LongMsg q = getParsedGenericInstance(LONG_COLUMN_INTERPRETER.getClass(), 3, b);
    assertEquals(1L, (long) LONG_COLUMN_INTERPRETER.getCellValueFromProto(q));

    // Create a second request with the next chunk start row
    AggregateRequest request2 = AggregateRequest.newBuilder(request)
      .setScan(request.getScan().toBuilder().setStartRow(response.getNextChunkStartRow()).build())
      .build();

    // Reset throttles for second call
    reset();

    RpcCallback<AggregateResponse> callback2 = mock(RpcCallback.class);
    aggregate.getSum(controller, request2, callback2);

    verify(callback2).run(responseCaptor.capture());

    AggregateResponse response2 = responseCaptor.getValue();
    b = response2.getFirstPart(0);
    q = getParsedGenericInstance(LONG_COLUMN_INTERPRETER.getClass(), 3, b);
    assertEquals(14L, (long) LONG_COLUMN_INTERPRETER.getCellValueFromProto(q));
    assertFalse("Response should not indicate there are more rows",
      response2.hasNextChunkStartRow());
  }
Test AggregateImplementation with throttling and partial results
hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAggregateImplementation.java