@Test
  public void testAggregationWithErrors() throws Throwable {
    Table table = util.getConnection().getTable(TEST_TABLE);
    final Map<byte[], ColumnAggregationWithErrorsSumResponse> results = Collections.synchronizedMap(
      new TreeMap<byte[], ColumnAggregationWithErrorsSumResponse>(Bytes.BYTES_COMPARATOR));
    ColumnAggregationWithErrorsSumRequest.Builder builder =
      ColumnAggregationWithErrorsSumRequest.newBuilder();
    builder.setFamily(ByteString.copyFrom(TEST_FAMILY));
    if (TEST_QUALIFIER != null && TEST_QUALIFIER.length > 0) {
      builder.setQualifier(ByteString.copyFrom(TEST_QUALIFIER));
    }

    boolean hasError = false;
    try {
      table.batchCoprocessorService(
        ColumnAggregationWithErrorsProtos.ColumnAggregationServiceWithErrors.getDescriptor()
          .findMethodByName("sum"),
        builder.build(), ROWS[0], ROWS[ROWS.length - 1],
        ColumnAggregationWithErrorsSumResponse.getDefaultInstance(),
        new Batch.Callback<ColumnAggregationWithErrorsSumResponse>() {

          @Override
          public void update(byte[] region, byte[] row,
            ColumnAggregationWithErrorsSumResponse result) {
            results.put(region, result);
          }
        });
    } catch (Throwable t) {
      LOG.info("Exceptions in coprocessor service", t);
      hasError = true;
    }

    long sumResult = 0;
    long expectedResult = 0;
    for (Map.Entry<byte[], ColumnAggregationWithErrorsSumResponse> e : results.entrySet()) {
      LOG.info(
        "Got value " + e.getValue().getSum() + " for region " + Bytes.toStringBinary(e.getKey()));
      sumResult += e.getValue().getSum();
    }
    for (long i = 0; i < rowSeperator2; i++) {
      expectedResult += i;
    }
    assertEquals("Invalid result", expectedResult, sumResult);
    assertTrue(hasError);
    table.close();
  }
TestEndpoint: test cases to verify the batch execution of coprocessor Endpoint
hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestBatchCoprocessorEndpoint.java