|
44 | 44 | import org.apache.hadoop.hbase.client.Scan; |
45 | 45 | import org.apache.hadoop.hbase.client.Table; |
46 | 46 | import org.apache.hadoop.hbase.rest.HBaseRESTTestingUtility; |
| 47 | +import org.apache.hadoop.hbase.rest.RESTServlet; |
47 | 48 | import org.apache.hadoop.hbase.testclassification.MediumTests; |
48 | 49 | import org.apache.hadoop.hbase.testclassification.RestTests; |
49 | 50 | import org.apache.hadoop.hbase.util.Bytes; |
@@ -576,5 +577,60 @@ public void testResponse(){ |
576 | 577 | assertTrue(response.hasBody()); |
577 | 578 | } |
578 | 579 |
|
579 | | -} |
| 580 | + /** |
| 581 | + * Tests keeping a HBase scanner alive for long periods of time. Each call to next() should reset |
| 582 | + * the ConnectionCache timeout for the scanner's connection |
| 583 | + * @throws Exception |
| 584 | + */ |
| 585 | + @Test |
| 586 | + public void testLongLivedScan() throws Exception { |
| 587 | + int numTrials = 6; |
| 588 | + int trialPause = 1000; |
| 589 | + int cleanUpInterval = 100; |
| 590 | + |
| 591 | + // Shutdown the Rest Servlet container |
| 592 | + REST_TEST_UTIL.shutdownServletContainer(); |
580 | 593 |
|
| 594 | + // Set the ConnectionCache timeout to trigger halfway through the trials |
| 595 | + TEST_UTIL.getConfiguration().setLong(RESTServlet.MAX_IDLETIME, (numTrials / 2) * trialPause); |
| 596 | + TEST_UTIL.getConfiguration().setLong(RESTServlet.CLEANUP_INTERVAL, cleanUpInterval); |
| 597 | + |
| 598 | + // Start the Rest Servlet container |
| 599 | + REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration()); |
| 600 | + |
| 601 | + // Truncate the test table for inserting test scenarios rows keys |
| 602 | + TEST_UTIL.getHBaseAdmin().disableTable(TABLE); |
| 603 | + TEST_UTIL.getHBaseAdmin().truncateTable(TABLE, false); |
| 604 | + |
| 605 | + remoteTable = new RemoteHTable( |
| 606 | + new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())), |
| 607 | + TEST_UTIL.getConfiguration(), TABLE.toBytes()); |
| 608 | + |
| 609 | + String row = "testrow"; |
| 610 | + |
| 611 | + try (Table table = TEST_UTIL.getConnection().getTable(TABLE)) { |
| 612 | + List<Put> puts = new ArrayList<Put>(); |
| 613 | + Put put = null; |
| 614 | + for (int i = 1; i <= numTrials; i++) { |
| 615 | + put = new Put(Bytes.toBytes(row + i)); |
| 616 | + put.addColumn(COLUMN_1, QUALIFIER_1, TS_2, Bytes.toBytes("testvalue" + i)); |
| 617 | + puts.add(put); |
| 618 | + } |
| 619 | + table.put(puts); |
| 620 | + } |
| 621 | + |
| 622 | + Scan scan = new Scan(); |
| 623 | + scan.setCaching(1); |
| 624 | + scan.setBatch(1); |
| 625 | + |
| 626 | + ResultScanner scanner = remoteTable.getScanner(scan); |
| 627 | + Result result = null; |
| 628 | + // get scanner and rows |
| 629 | + for (int i = 1; i <= numTrials; i++) { |
| 630 | + // Make sure that the Scanner doesn't throw an exception after the ConnectionCache timeout |
| 631 | + result = scanner.next(); |
| 632 | + assertEquals(row + i, Bytes.toString(result.getRow())); |
| 633 | + Thread.sleep(trialPause); |
| 634 | + } |
| 635 | + } |
| 636 | +} |
0 commit comments