@Override
    public ScanResponse scan(RpcController controller, ScanRequest request)
      throws ServiceException {
      try {
        if (!inTest) {
          return super.scan(controller, request);
        }

        HRegion region = null;
        if (request.hasRegion()) {
          region = this.getRegion(request.getRegion());
        }

        if (region != null && !tableName.equals(region.getTableDescriptor().getTableName())) {
          return super.scan(controller, request);
        }

        ScanResponse result = null;
        // Simulate RpcCallContext is null for test.
        Optional<RpcCall> rpcCall = RpcServer.unsetCurrentCall();
        try {
          result = super.scan(controller, request);
        } finally {
          rpcCall.ifPresent(RpcServer::setCurrentCall);
        }
        return result;
      } catch (Throwable e) {
        exceptionRef.set(e);
        throw new ServiceException(e);
      }
    }
Use {@link DeallocateRewriteByteBuffAllocator} to rewrite the bytebuffers right after
released.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerScan.java