@Test
  public void test() throws ServiceException, IOException {
    Scan scan = new Scan();
    ScanRequest req = RequestConverter.buildScanRequest(HRI.getRegionName(), scan, 0, false);
    HBaseRpcController hrc = new HBaseRpcControllerImpl();
    ScanResponse resp = scan(hrc, req);
    assertTrue(resp.getMoreResults());
    assertTrue(resp.getMoreResultsInRegion());
    assertEquals(0, ResponseConverter.getResults(hrc.cellScanner(), resp).length);
    long scannerId = resp.getScannerId();
    int nextCallSeq = 0;
    // test normal next
    for (int i = 0; i < COUNT / 2; i++) {
      req = RequestConverter.buildScanRequest(scannerId, 1, false, nextCallSeq++, false, false, -1);
      hrc.reset();
      resp = scan(hrc, req);
      assertTrue(resp.getMoreResults());
      assertTrue(resp.getMoreResultsInRegion());
      Result[] results = ResponseConverter.getResults(hrc.cellScanner(), resp);
      assertEquals(1, results.length);
      assertResult(i, results[0]);
    }
    // test zero next
    req = RequestConverter.buildScanRequest(scannerId, 0, false, nextCallSeq++, false, false, -1);
    hrc.reset();
    resp = scan(hrc, req);
    assertTrue(resp.getMoreResults());
    assertTrue(resp.getMoreResultsInRegion());
    assertEquals(0, ResponseConverter.getResults(hrc.cellScanner(), resp).length);
    for (int i = COUNT / 2; i < COUNT; i++) {
      req = RequestConverter.buildScanRequest(scannerId, 1, false, nextCallSeq++, false, false, -1);
      hrc.reset();
      resp = scan(hrc, req);
      assertTrue(resp.getMoreResults());
      assertEquals(i != COUNT - 1, resp.getMoreResultsInRegion());
      Result[] results = ResponseConverter.getResults(hrc.cellScanner(), resp);
      assertEquals(1, results.length);
      assertResult(i, results[0]);
    }
    // close
    req = RequestConverter.buildScanRequest(scannerId, 0, true, false);
    hrc.reset();
    resp = scan(hrc, req);
  }
Testcase to make sure that we do not close scanners if ScanRequest.numberOfRows is zero. See
HBASE-18042 for more details.
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScanWithoutFetchingData.java