@Test
  public void testScannWhenRpcCallContextNull() throws Exception {
    ResultScanner resultScanner = null;
    Table table = null;
    try {
      table = TEST_UTIL.createTable(tableName, new byte[][] { CF }, 1, 1024, null);
      putToTable(table, r0);
      putToTable(table, r1);
      putToTable(table, r2);

      admin.flush(table.getName());

      Scan scan = new Scan();
      scan.setCaching(2);
      scan.withStartRow(r0, true).withStopRow(r2, true);

      MyRSRpcServices.inTest = true;
      resultScanner = table.getScanner(scan);
      Result result = resultScanner.next();
      byte[] rowKey = result.getRow();
      assertTrue(Bytes.equals(r0, rowKey));

      result = resultScanner.next();
      rowKey = result.getRow();
      assertTrue(Bytes.equals(r1, rowKey));

      result = resultScanner.next();
      rowKey = result.getRow();
      assertTrue(Bytes.equals(r2, rowKey));
      assertNull(resultScanner.next());
      assertTrue(MyRSRpcServices.exceptionRef.get() == null);
    } finally {
      MyRSRpcServices.inTest = false;
      if (resultScanner != null) {
        resultScanner.close();
      }
      if (table != null) {
        table.close();
      }
    }
  }
Use {@link DeallocateRewriteByteBuffAllocator} to rewrite the bytebuffers right after
released.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerScan.java