public void testScannerReseekDoesntNPE() throws Exception { List<KeyValueScanner> scanners = scanFixture(kvs); StoreScanner scan = new StoreScanner(new Scan(), scanInfo, scanType, getCols("a", "d"), scanners); // Previously a updateReaders twice in a row would cause an NPE. In test this would also // normally cause an NPE because scan.store is null. So as long as we get through these // two calls we are good and the bug was quashed. scan.updateReaders(); scan.updateReaders(); scan.peek(); }
public void testWideScanBatching() throws IOException { final int batch = 256; try { this.r = createNewHRegion(TESTTABLEDESC, null, null); int inserted = addWideContent(this.r); List<Cell> results = new ArrayList<Cell>(); Scan scan = new Scan(); scan.addFamily(A); scan.addFamily(B); scan.addFamily(C); scan.setMaxVersions(100); scan.setBatch(batch); InternalScanner s = r.getScanner(scan); int total = 0; int i = 0; boolean more; do { more = s.next(results); i++; LOG.info("iteration #" + i + ", results.size=" + results.size()); // assert that the result set is no larger assertTrue(results.size() <= batch); total += results.size(); if (results.size() > 0) { // assert that all results are from the same row byte[] row = CellUtil.cloneRow(results.get(0)); for (Cell kv : results) { assertTrue(Bytes.equals(row, CellUtil.cloneRow(kv))); } } results.clear(); // trigger ChangedReadersObservers Iterator<KeyValueScanner> scanners = ((HRegion.RegionScannerImpl) s).storeHeap.getHeap().iterator(); while (scanners.hasNext()) { StoreScanner ss = (StoreScanner) scanners.next(); ss.updateReaders(); } } while (more); // assert that the scanner returned all values LOG.info("inserted " + inserted + ", scanned " + total); assertEquals(total, inserted); s.close(); } finally { HRegion.closeHRegion(this.r); } }