@Before
  public void setUp() throws Exception {
    env = mock(RegionCoprocessorEnvironment.class);
    region = mock(HRegion.class);
    RegionCoprocessorHost host = mock(RegionCoprocessorHost.class);
    when(env.getRegion()).thenReturn(region);
    when(region.getCoprocessorHost()).thenReturn(host);

    RegionInfo regionInfo = mock(RegionInfo.class);
    when(region.getRegionInfo()).thenReturn(regionInfo);
    when(regionInfo.getRegionNameAsString()).thenReturn("testRegion");

    scan = new Scan().addColumn(CF, CQ);

    scanner = mock(RegionScannerImpl.class);
    doAnswer(createMockScanner()).when(scanner).next(any(List.class));
    when(region.getScanner(any())).thenReturn(scanner);

    doAnswer(createMockQuota()).when(env).checkScanQuota(any(), anyLong(), anyLong());

    request = AggregateRequest.newBuilder().setScan(ProtobufUtil.toScan(scan))
      .setInterpreterClassName(LongColumnInterpreter.class.getName())
      .setClientSupportsPartialResult(true).build();

    controller = mock(RpcController.class);

    aggregate = new AggregateImplementation<>();
    aggregate.start(env);
  }
Test AggregateImplementation with throttling and partial results
hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAggregateImplementation.java