@Test
  public void testLongLivedScan() throws Exception {
    int numTrials = 6;
    int trialPause = 1000;
    int cleanUpInterval = 100;

    // Shutdown the Rest Servlet container
    REST_TEST_UTIL.shutdownServletContainer();

    // Set the ConnectionCache timeout to trigger halfway through the trials
    TEST_UTIL.getConfiguration().setLong(RESTServlet.MAX_IDLETIME, (numTrials / 2) * trialPause);
    TEST_UTIL.getConfiguration().setLong(RESTServlet.CLEANUP_INTERVAL, cleanUpInterval);

    // Start the Rest Servlet container
    REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());

    // Truncate the test table for inserting test scenarios rows keys
    TEST_UTIL.getAdmin().disableTable(TABLE);
    TEST_UTIL.getAdmin().truncateTable(TABLE, false);

    remoteTable =
      new RemoteHTable(new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())),
        TEST_UTIL.getConfiguration(), TABLE.toBytes());

    String row = "testrow";

    try (Table table = TEST_UTIL.getConnection().getTable(TABLE)) {
      List<Put> puts = new ArrayList<Put>();
      Put put = null;
      for (int i = 1; i <= numTrials; i++) {
        put = new Put(Bytes.toBytes(row + i));
        put.addColumn(COLUMN_1, QUALIFIER_1, TS_2, Bytes.toBytes("testvalue" + i));
        puts.add(put);
      }
      table.put(puts);
    }

    Scan scan = new Scan();
    scan.setCaching(1);
    scan.setBatch(1);

    ResultScanner scanner = remoteTable.getScanner(scan);
    Result result = null;
    // get scanner and rows
    for (int i = 1; i <= numTrials; i++) {
      // Make sure that the Scanner doesn't throw an exception after the ConnectionCache timeout
      result = scanner.next();
      assertEquals(row + i, Bytes.toString(result.getRow()));
      Thread.sleep(trialPause);
    }
  }
Tests keeping a HBase scanner alive for long periods of time. Each call to next() should reset
the ConnectionCache timeout for the scanner's connection.
@throws Exception if starting the servlet container or disabling or truncating the table fails
hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java