Repository: hbase Updated Branches: refs/heads/master 2773510f1 -> 8d33949b8
http://git-wip-us.apache.org/repos/asf/hbase/blob/8d33949b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java index 1653728..4082818 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java @@ -19,8 +19,13 @@ package org.apache.hadoop.hbase.regionserver; +import static org.apache.hadoop.hbase.CellUtil.createCell; +import static org.apache.hadoop.hbase.KeyValueTestUtil.create; import static org.apache.hadoop.hbase.regionserver.KeyValueScanFixture.scanFixture; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -28,6 +33,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.NavigableSet; +import java.util.OptionalInt; import java.util.TreeSet; import java.util.concurrent.atomic.AtomicInteger; @@ -42,7 +48,6 @@ import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeepDeletedCells; import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.KeyValueTestUtil; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.filter.ColumnCountGetFilter; @@ -51,7 +56,6 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdge; import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper; -import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -66,11 +70,10 @@ public class TestStoreScanner { @Rule public final TestRule timeout = CategoryBasedTimeout.builder().withTimeout(this.getClass()). withLookingForStuckThread(true).build(); private static final String CF_STR = "cf"; - private static final byte [] CF = Bytes.toBytes(CF_STR); + private static final byte[] CF = Bytes.toBytes(CF_STR); static Configuration CONF = HBaseConfiguration.create(); private ScanInfo scanInfo = new ScanInfo(CONF, CF, 0, Integer.MAX_VALUE, Long.MAX_VALUE, KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, CellComparator.COMPARATOR, false); - private ScanType scanType = ScanType.USER_SCAN; /** * From here on down, we have a bunch of defines and specific CELL_GRID of Cells. The @@ -79,15 +82,15 @@ public class TestStoreScanner { * {@link StoreScanner#optimize(org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode, * Cell)} is not overly enthusiastic. */ - private static final byte [] ZERO = new byte [] {'0'}; - private static final byte [] ZERO_POINT_ZERO = new byte [] {'0', '.', '0'}; - private static final byte [] ONE = new byte [] {'1'}; - private static final byte [] TWO = new byte [] {'2'}; - private static final byte [] TWO_POINT_TWO = new byte [] {'2', '.', '2'}; - private static final byte [] THREE = new byte [] {'3'}; - private static final byte [] FOUR = new byte [] {'4'}; - private static final byte [] FIVE = new byte [] {'5'}; - private static final byte [] VALUE = new byte [] {'v'}; + private static final byte[] ZERO = new byte[] {'0'}; + private static final byte[] ZERO_POINT_ZERO = new byte[] {'0', '.', '0'}; + private static final byte[] ONE = new byte[] {'1'}; + private static final byte[] TWO = new byte[] {'2'}; + private static final byte[] TWO_POINT_TWO = new byte[] {'2', '.', '2'}; + private static final byte[] THREE = new byte[] {'3'}; + private static final byte[] FOUR = new byte[] {'4'}; + private static final byte[] FIVE = new byte[] {'5'}; + private static final byte[] VALUE = new byte[] {'v'}; private static final int CELL_GRID_BLOCK2_BOUNDARY = 4; private static final int CELL_GRID_BLOCK3_BOUNDARY = 11; private static final int CELL_GRID_BLOCK4_BOUNDARY = 15; @@ -100,32 +103,32 @@ public class TestStoreScanner { * We will use this to test scan does the right thing as it * we do Gets, StoreScanner#optimize, and what we do on (faked) block boundaries. */ - private static final Cell [] CELL_GRID = new Cell [] { - CellUtil.createCell(ONE, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(ONE, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(ONE, CF, THREE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(ONE, CF, FOUR, 1L, KeyValue.Type.Put.getCode(), VALUE), + private static final Cell[] CELL_GRID = new Cell [] { + createCell(ONE, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(ONE, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(ONE, CF, THREE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(ONE, CF, FOUR, 1L, KeyValue.Type.Put.getCode(), VALUE), // Offset 4 CELL_GRID_BLOCK2_BOUNDARY - CellUtil.createCell(TWO, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(TWO, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(TWO, CF, THREE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(TWO, CF, FOUR, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(TWO_POINT_TWO, CF, ZERO, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(TWO_POINT_TWO, CF, ZERO_POINT_ZERO, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(TWO_POINT_TWO, CF, FIVE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(TWO, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(TWO, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(TWO, CF, THREE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(TWO, CF, FOUR, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(TWO_POINT_TWO, CF, ZERO, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(TWO_POINT_TWO, CF, ZERO_POINT_ZERO, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(TWO_POINT_TWO, CF, FIVE, 1L, KeyValue.Type.Put.getCode(), VALUE), // Offset 11! CELL_GRID_BLOCK3_BOUNDARY - CellUtil.createCell(THREE, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(THREE, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(THREE, CF, THREE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(THREE, CF, FOUR, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(THREE, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(THREE, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(THREE, CF, THREE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(THREE, CF, FOUR, 1L, KeyValue.Type.Put.getCode(), VALUE), // Offset 15 CELL_GRID_BLOCK4_BOUNDARY - CellUtil.createCell(FOUR, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(FOUR, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(FOUR, CF, THREE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(FOUR, CF, FOUR, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(FOUR, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(FOUR, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(FOUR, CF, THREE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(FOUR, CF, FOUR, 1L, KeyValue.Type.Put.getCode(), VALUE), // Offset 19 CELL_GRID_BLOCK5_BOUNDARY - CellUtil.createCell(FOUR, CF, FIVE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(FIVE, CF, ZERO, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(FOUR, CF, FIVE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(FIVE, CF, ZERO, 1L, KeyValue.Type.Put.getCode(), VALUE), }; private static class KeyValueHeapWithCount extends KeyValueHeap { @@ -154,11 +157,9 @@ public class TestStoreScanner { AtomicInteger count; final AtomicInteger optimization = new AtomicInteger(0); - CellGridStoreScanner(final Scan scan, ScanInfo scanInfo, ScanType scanType) - throws IOException { - super(scan, scanInfo, scanType, scan.getFamilyMap().get(CF), - Arrays.<KeyValueScanner>asList( - new KeyValueScanner[] {new KeyValueScanFixture(CellComparator.COMPARATOR, CELL_GRID)})); + CellGridStoreScanner(final Scan scan, ScanInfo scanInfo) throws IOException { + super(scan, scanInfo, scan.getFamilyMap().get(CF), Arrays.<KeyValueScanner> asList( + new KeyValueScanner[] { new KeyValueScanFixture(CellComparator.COMPARATOR, CELL_GRID) })); } protected void resetKVHeap(List<? extends KeyValueScanner> scanners, @@ -204,25 +205,24 @@ public class TestStoreScanner { private static final int CELL_WITH_VERSIONS_BLOCK2_BOUNDARY = 4; - private static final Cell [] CELL_WITH_VERSIONS = new Cell [] { - CellUtil.createCell(ONE, CF, ONE, 2L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(ONE, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(ONE, CF, TWO, 2L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(ONE, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), + private static final Cell[] CELL_WITH_VERSIONS = new Cell [] { + createCell(ONE, CF, ONE, 2L, KeyValue.Type.Put.getCode(), VALUE), + createCell(ONE, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(ONE, CF, TWO, 2L, KeyValue.Type.Put.getCode(), VALUE), + createCell(ONE, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), // Offset 4 CELL_WITH_VERSIONS_BLOCK2_BOUNDARY - CellUtil.createCell(TWO, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), - CellUtil.createCell(TWO, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(TWO, CF, ONE, 1L, KeyValue.Type.Put.getCode(), VALUE), + createCell(TWO, CF, TWO, 1L, KeyValue.Type.Put.getCode(), VALUE), }; private static class CellWithVersionsStoreScanner extends StoreScanner { // Count of how often optimize is called and of how often it does an optimize. final AtomicInteger optimization = new AtomicInteger(0); - CellWithVersionsStoreScanner(final Scan scan, ScanInfo scanInfo, ScanType scanType) - throws IOException { - super(scan, scanInfo, scanType, scan.getFamilyMap().get(CF), Arrays - .<KeyValueScanner> asList(new KeyValueScanner[] { new KeyValueScanFixture( - CellComparator.COMPARATOR, CELL_WITH_VERSIONS) })); + CellWithVersionsStoreScanner(final Scan scan, ScanInfo scanInfo) throws IOException { + super(scan, scanInfo, scan.getFamilyMap().get(CF), + Arrays.<KeyValueScanner> asList(new KeyValueScanner[] { + new KeyValueScanFixture(CellComparator.COMPARATOR, CELL_WITH_VERSIONS) })); } protected boolean trySkipToNextColumn(Cell cell) throws IOException { @@ -246,11 +246,10 @@ public class TestStoreScanner { // Count of how often optimize is called and of how often it does an optimize. final AtomicInteger optimization = new AtomicInteger(0); - CellWithVersionsNoOptimizeStoreScanner(final Scan scan, ScanInfo scanInfo, ScanType scanType) - throws IOException { - super(scan, scanInfo, scanType, scan.getFamilyMap().get(CF), Arrays - .<KeyValueScanner> asList(new KeyValueScanner[] { new KeyValueScanFixture( - CellComparator.COMPARATOR, CELL_WITH_VERSIONS) })); + CellWithVersionsNoOptimizeStoreScanner(Scan scan, ScanInfo scanInfo) throws IOException { + super(scan, scanInfo, scan.getFamilyMap().get(CF), + Arrays.<KeyValueScanner> asList(new KeyValueScanner[] { + new KeyValueScanFixture(CellComparator.COMPARATOR, CELL_WITH_VERSIONS) })); } protected boolean trySkipToNextColumn(Cell cell) throws IOException { @@ -272,40 +271,34 @@ public class TestStoreScanner { @Test public void testWithColumnCountGetFilter() throws Exception { Get get = new Get(ONE); - get.setMaxVersions(); + get.readAllVersions(); get.addFamily(CF); get.setFilter(new ColumnCountGetFilter(2)); - CellWithVersionsNoOptimizeStoreScanner scannerNoOptimize = new CellWithVersionsNoOptimizeStoreScanner( - new Scan(get), this.scanInfo, this.scanType); - try { + try (CellWithVersionsNoOptimizeStoreScanner scannerNoOptimize = + new CellWithVersionsNoOptimizeStoreScanner(new Scan(get), this.scanInfo)) { List<Cell> results = new ArrayList<>(); while (scannerNoOptimize.next(results)) { continue; } - Assert.assertEquals(2, results.size()); - Assert.assertTrue(CellUtil.matchingColumn(results.get(0), CELL_WITH_VERSIONS[0])); - Assert.assertTrue(CellUtil.matchingColumn(results.get(1), CELL_WITH_VERSIONS[2])); - Assert.assertTrue("Optimize should do some optimizations", + assertEquals(2, results.size()); + assertTrue(CellUtil.matchingColumn(results.get(0), CELL_WITH_VERSIONS[0])); + assertTrue(CellUtil.matchingColumn(results.get(1), CELL_WITH_VERSIONS[2])); + assertTrue("Optimize should do some optimizations", scannerNoOptimize.optimization.get() == 0); - } finally { - scannerNoOptimize.close(); } get.setFilter(new ColumnCountGetFilter(2)); - CellWithVersionsStoreScanner scanner = new CellWithVersionsStoreScanner(new Scan(get), - this.scanInfo, this.scanType); - try { + try (CellWithVersionsStoreScanner scanner = + new CellWithVersionsStoreScanner(new Scan(get), this.scanInfo)) { List<Cell> results = new ArrayList<>(); while (scanner.next(results)) { continue; } - Assert.assertEquals(2, results.size()); - Assert.assertTrue(CellUtil.matchingColumn(results.get(0), CELL_WITH_VERSIONS[0])); - Assert.assertTrue(CellUtil.matchingColumn(results.get(1), CELL_WITH_VERSIONS[2])); - Assert.assertTrue("Optimize should do some optimizations", scanner.optimization.get() > 0); - } finally { - scanner.close(); + assertEquals(2, results.size()); + assertTrue(CellUtil.matchingColumn(results.get(0), CELL_WITH_VERSIONS[0])); + assertTrue(CellUtil.matchingColumn(results.get(1), CELL_WITH_VERSIONS[2])); + assertTrue("Optimize should do some optimizations", scanner.optimization.get() > 0); } } @@ -329,22 +322,19 @@ public class TestStoreScanner { // row TWO_POINT_TWO. We should read one block only. Get get = new Get(TWO); Scan scan = new Scan(get); - CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo, this.scanType); - try { + try (CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo)) { List<Cell> results = new ArrayList<>(); while (scanner.next(results)) { continue; } // Should be four results of column 1 (though there are 5 rows in the CELL_GRID -- the // TWO_POINT_TWO row does not have a a column ONE. - Assert.assertEquals(4, results.size()); + assertEquals(4, results.size()); // We should have gone the optimize route 5 times totally... an INCLUDE for the four cells // in the row plus the DONE on the end. - Assert.assertEquals(5, scanner.count.get()); + assertEquals(5, scanner.count.get()); // For a full row Get, there should be no opportunity for scanner optimization. - Assert.assertEquals(0, scanner.optimization.get()); - } finally { - scanner.close(); + assertEquals(0, scanner.optimization.get()); } } @@ -353,22 +343,19 @@ public class TestStoreScanner { // Do a Get against row FOUR. It spans two blocks. Get get = new Get(FOUR); Scan scan = new Scan(get); - CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo, this.scanType); - try { + try (CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo)) { List<Cell> results = new ArrayList<>(); while (scanner.next(results)) { continue; } // Should be four results of column 1 (though there are 5 rows in the CELL_GRID -- the // TWO_POINT_TWO row does not have a a column ONE. - Assert.assertEquals(5, results.size()); + assertEquals(5, results.size()); // We should have gone the optimize route 6 times totally... an INCLUDE for the five cells // in the row plus the DONE on the end. - Assert.assertEquals(6, scanner.count.get()); + assertEquals(6, scanner.count.get()); // For a full row Get, there should be no opportunity for scanner optimization. - Assert.assertEquals(0, scanner.optimization.get()); - } finally { - scanner.close(); + assertEquals(0, scanner.optimization.get()); } } @@ -382,22 +369,19 @@ public class TestStoreScanner { Scan scan = new Scan(); // A scan that just gets the first qualifier on each row of the CELL_GRID scan.addColumn(CF, ONE); - CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo, this.scanType); - try { + try (CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo)) { List<Cell> results = new ArrayList<>(); while (scanner.next(results)) { continue; } // Should be four results of column 1 (though there are 5 rows in the CELL_GRID -- the // TWO_POINT_TWO row does not have a a column ONE. - Assert.assertEquals(4, results.size()); + assertEquals(4, results.size()); for (Cell cell: results) { assertTrue(Bytes.equals(ONE, 0, ONE.length, cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())); } - Assert.assertTrue("Optimize should do some optimizations", scanner.optimization.get() > 0); - } finally { - scanner.close(); + assertTrue("Optimize should do some optimizations", scanner.optimization.get() > 0); } } @@ -416,18 +400,15 @@ public class TestStoreScanner { get.addColumn(CF, TWO); get.addColumn(CF, THREE); Scan scan = new Scan(get); - CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo, this.scanType); - try { + try (CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo)) { List<Cell> results = new ArrayList<>(); // For a Get there should be no more next's after the first call. - Assert.assertEquals(false, scanner.next(results)); + assertEquals(false, scanner.next(results)); // Should be one result only. - Assert.assertEquals(2, results.size()); + assertEquals(2, results.size()); // And we should have gone through optimize twice only. - Assert.assertEquals("First qcode is SEEK_NEXT_COL and second INCLUDE_AND_SEEK_NEXT_ROW", - 3, scanner.count.get()); - } finally { - scanner.close(); + assertEquals("First qcode is SEEK_NEXT_COL and second INCLUDE_AND_SEEK_NEXT_ROW", 3, + scanner.count.get()); } } @@ -447,18 +428,15 @@ public class TestStoreScanner { Get get = new Get(THREE); get.addColumn(CF, TWO); Scan scan = new Scan(get); - CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo, this.scanType); - try { + try (CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo)) { List<Cell> results = new ArrayList<>(); // For a Get there should be no more next's after the first call. - Assert.assertEquals(false, scanner.next(results)); + assertEquals(false, scanner.next(results)); // Should be one result only. - Assert.assertEquals(1, results.size()); + assertEquals(1, results.size()); // And we should have gone through optimize twice only. - Assert.assertEquals("First qcode is SEEK_NEXT_COL and second INCLUDE_AND_SEEK_NEXT_ROW", - 2, scanner.count.get()); - } finally { - scanner.close(); + assertEquals("First qcode is SEEK_NEXT_COL and second INCLUDE_AND_SEEK_NEXT_ROW", 2, + scanner.count.get()); } } @@ -467,57 +445,53 @@ public class TestStoreScanner { String r1 = "R1"; // returns only 1 of these 2 even though same timestamp KeyValue [] kvs = new KeyValue[] { - KeyValueTestUtil.create(r1, CF_STR, "a", 1, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create(r1, CF_STR, "a", 2, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create(r1, CF_STR, "a", 3, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create(r1, CF_STR, "a", 4, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create(r1, CF_STR, "a", 5, KeyValue.Type.Put, "dont-care"), + create(r1, CF_STR, "a", 1, KeyValue.Type.Put, "dont-care"), + create(r1, CF_STR, "a", 2, KeyValue.Type.Put, "dont-care"), + create(r1, CF_STR, "a", 3, KeyValue.Type.Put, "dont-care"), + create(r1, CF_STR, "a", 4, KeyValue.Type.Put, "dont-care"), + create(r1, CF_STR, "a", 5, KeyValue.Type.Put, "dont-care"), }; List<KeyValueScanner> scanners = Arrays.<KeyValueScanner>asList( new KeyValueScanner[] { new KeyValueScanFixture(CellComparator.COMPARATOR, kvs) }); - Scan scanSpec = new Scan(Bytes.toBytes(r1)); + Scan scanSpec = new Scan().withStartRow(Bytes.toBytes(r1)); scanSpec.setTimeRange(0, 6); - scanSpec.setMaxVersions(); + scanSpec.readAllVersions(); List<Cell> results = null; - try (StoreScanner scan = - new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), scanners)) { + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(5, results.size()); - Assert.assertEquals(kvs[kvs.length - 1], results.get(0)); + assertEquals(true, scan.next(results)); + assertEquals(5, results.size()); + assertEquals(kvs[kvs.length - 1], results.get(0)); } // Scan limited TimeRange - scanSpec = new Scan(Bytes.toBytes(r1)); + scanSpec = new Scan().withStartRow(Bytes.toBytes(r1)); scanSpec.setTimeRange(1, 3); - scanSpec.setMaxVersions(); - try (StoreScanner scan = - new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), scanners)) { + scanSpec.readAllVersions(); + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(2, results.size()); + assertEquals(true, scan.next(results)); + assertEquals(2, results.size()); } // Another range. - scanSpec = new Scan(Bytes.toBytes(r1)); + scanSpec = new Scan().withStartRow(Bytes.toBytes(r1)); scanSpec.setTimeRange(5, 10); - scanSpec.setMaxVersions(); - try (StoreScanner scan = - new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), scanners)) { + scanSpec.readAllVersions(); + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(1, results.size()); + assertEquals(true, scan.next(results)); + assertEquals(1, results.size()); } // See how TimeRange and Versions interact. // Another range. - scanSpec = new Scan(Bytes.toBytes(r1)); + scanSpec = new Scan().withStartRow(Bytes.toBytes(r1)); scanSpec.setTimeRange(0, 10); - scanSpec.setMaxVersions(3); - try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), - scanners)) { + scanSpec.readVersions(3); + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(3, results.size()); + assertEquals(true, scan.next(results)); + assertEquals(3, results.size()); } } @@ -525,22 +499,21 @@ public class TestStoreScanner { public void testScanSameTimestamp() throws IOException { // returns only 1 of these 2 even though same timestamp KeyValue [] kvs = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), }; List<KeyValueScanner> scanners = Arrays.asList( new KeyValueScanner[] { new KeyValueScanFixture(CellComparator.COMPARATOR, kvs) }); - Scan scanSpec = new Scan(Bytes.toBytes("R1")); + Scan scanSpec = new Scan().withStartRow(Bytes.toBytes("R1")); // this only uses maxVersions (default=1) and TimeRange (default=all) - try (StoreScanner scan = - new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), scanners)) { + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(kvs[0], results.get(0)); + assertEquals(true, scan.next(results)); + assertEquals(1, results.size()); + assertEquals(kvs[0], results.get(0)); } } @@ -555,30 +528,29 @@ public class TestStoreScanner { public void testWontNextToNext() throws IOException { // build the scan file: KeyValue [] kvs = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", 2, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R2", "cf", "a", 1, KeyValue.Type.Put, "dont-care") + create("R1", "cf", "a", 2, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), + create("R2", "cf", "a", 1, KeyValue.Type.Put, "dont-care") }; List<KeyValueScanner> scanners = scanFixture(kvs); - Scan scanSpec = new Scan(Bytes.toBytes("R1")); + Scan scanSpec = new Scan().withStartRow(Bytes.toBytes("R1")); // this only uses maxVersions (default=1) and TimeRange (default=all) - try (StoreScanner scan = - new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), scanners)) { + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { List<Cell> results = new ArrayList<>(); scan.next(results); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(kvs[0], results.get(0)); + assertEquals(1, results.size()); + assertEquals(kvs[0], results.get(0)); // should be ok... // now scan _next_ again. results.clear(); scan.next(results); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(kvs[2], results.get(0)); + assertEquals(1, results.size()); + assertEquals(kvs[2], results.get(0)); results.clear(); scan.next(results); - Assert.assertEquals(0, results.size()); + assertEquals(0, results.size()); } } @@ -586,16 +558,15 @@ public class TestStoreScanner { @Test public void testDeleteVersionSameTimestamp() throws IOException { KeyValue [] kvs = new KeyValue [] { - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Delete, "dont-care"), + create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", 1, KeyValue.Type.Delete, "dont-care"), }; List<KeyValueScanner> scanners = scanFixture(kvs); - Scan scanSpec = new Scan(Bytes.toBytes("R1")); - try (StoreScanner scan = - new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), scanners)) { + Scan scanSpec = new Scan().withStartRow(Bytes.toBytes("R1")); + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertFalse(scan.next(results)); - Assert.assertEquals(0, results.size()); + assertFalse(scan.next(results)); + assertEquals(0, results.size()); } } @@ -606,207 +577,202 @@ public class TestStoreScanner { @Test public void testDeletedRowThenGoodRow() throws IOException { KeyValue [] kvs = new KeyValue [] { - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Delete, "dont-care"), - KeyValueTestUtil.create("R2", "cf", "a", 20, KeyValue.Type.Put, "dont-care") + create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", 1, KeyValue.Type.Delete, "dont-care"), + create("R2", "cf", "a", 20, KeyValue.Type.Put, "dont-care") }; List<KeyValueScanner> scanners = scanFixture(kvs); - Scan scanSpec = new Scan(Bytes.toBytes("R1")); - try (StoreScanner scan = - new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), scanners)) { + Scan scanSpec = new Scan().withStartRow(Bytes.toBytes("R1")); + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(0, results.size()); + assertEquals(true, scan.next(results)); + assertEquals(0, results.size()); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(kvs[2], results.get(0)); + assertEquals(true, scan.next(results)); + assertEquals(1, results.size()); + assertEquals(kvs[2], results.get(0)); - Assert.assertEquals(false, scan.next(results)); + assertEquals(false, scan.next(results)); } } public void testDeleteVersionMaskingMultiplePuts() throws IOException { long now = System.currentTimeMillis(); KeyValue [] kvs1 = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", now, KeyValue.Type.Delete, "dont-care") + create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", now, KeyValue.Type.Delete, "dont-care") }; KeyValue [] kvs2 = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", now-500, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", now-100, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care") + create("R1", "cf", "a", now-500, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", now-100, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care") }; List<KeyValueScanner> scanners = scanFixture(kvs1, kvs2); - try (StoreScanner scan = new StoreScanner(new Scan(Bytes.toBytes("R1")), scanInfo, scanType, - getCols("a"), scanners)) { + try (StoreScanner scan = new StoreScanner(new Scan().withStartRow(Bytes.toBytes("R1")), + scanInfo, getCols("a"), scanners)) { List<Cell> results = new ArrayList<>(); // the two put at ts=now will be masked by the 1 delete, and // since the scan default returns 1 version we'll return the newest // key, which is kvs[2], now-100. - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(kvs2[1], results.get(0)); + assertEquals(true, scan.next(results)); + assertEquals(1, results.size()); + assertEquals(kvs2[1], results.get(0)); } } public void testDeleteVersionsMixedAndMultipleVersionReturn() throws IOException { long now = System.currentTimeMillis(); KeyValue [] kvs1 = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", now, KeyValue.Type.Delete, "dont-care") + create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", now, KeyValue.Type.Delete, "dont-care") }; KeyValue [] kvs2 = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", now-500, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", now+500, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R2", "cf", "z", now, KeyValue.Type.Put, "dont-care") + create("R1", "cf", "a", now-500, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", now+500, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care"), + create("R2", "cf", "z", now, KeyValue.Type.Put, "dont-care") }; List<KeyValueScanner> scanners = scanFixture(kvs1, kvs2); - Scan scanSpec = new Scan(Bytes.toBytes("R1")).setMaxVersions(2); - try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, scanType, - getCols("a"), scanners)) { + Scan scanSpec = new Scan().withStartRow(Bytes.toBytes("R1")).readVersions(2); + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(2, results.size()); - Assert.assertEquals(kvs2[1], results.get(0)); - Assert.assertEquals(kvs2[0], results.get(1)); + assertEquals(true, scan.next(results)); + assertEquals(2, results.size()); + assertEquals(kvs2[1], results.get(0)); + assertEquals(kvs2[0], results.get(1)); } } @Test public void testWildCardOneVersionScan() throws IOException { KeyValue [] kvs = new KeyValue [] { - KeyValueTestUtil.create("R1", "cf", "a", 2, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "b", 1, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.DeleteColumn, "dont-care"), + create("R1", "cf", "a", 2, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "b", 1, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", 1, KeyValue.Type.DeleteColumn, "dont-care"), }; List<KeyValueScanner> scanners = scanFixture(kvs); try (StoreScanner scan = - new StoreScanner(new Scan(Bytes.toBytes("R1")), scanInfo, scanType, null, scanners)) { + new StoreScanner(new Scan().withStartRow(Bytes.toBytes("R1")), scanInfo, null, scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(2, results.size()); - Assert.assertEquals(kvs[0], results.get(0)); - Assert.assertEquals(kvs[1], results.get(1)); + assertEquals(true, scan.next(results)); + assertEquals(2, results.size()); + assertEquals(kvs[0], results.get(0)); + assertEquals(kvs[1], results.get(1)); } } @Test public void testWildCardScannerUnderDeletes() throws IOException { KeyValue [] kvs = new KeyValue [] { - KeyValueTestUtil.create("R1", "cf", "a", 2, KeyValue.Type.Put, "dont-care"), // inc + create("R1", "cf", "a", 2, KeyValue.Type.Put, "dont-care"), // inc // orphaned delete column. - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.DeleteColumn, "dont-care"), + create("R1", "cf", "a", 1, KeyValue.Type.DeleteColumn, "dont-care"), // column b - KeyValueTestUtil.create("R1", "cf", "b", 2, KeyValue.Type.Put, "dont-care"), // inc - KeyValueTestUtil.create("R1", "cf", "b", 1, KeyValue.Type.Put, "dont-care"), // inc + create("R1", "cf", "b", 2, KeyValue.Type.Put, "dont-care"), // inc + create("R1", "cf", "b", 1, KeyValue.Type.Put, "dont-care"), // inc // column c - KeyValueTestUtil.create("R1", "cf", "c", 10, KeyValue.Type.Delete, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "c", 10, KeyValue.Type.Put, "dont-care"), // no - KeyValueTestUtil.create("R1", "cf", "c", 9, KeyValue.Type.Put, "dont-care"), // inc + create("R1", "cf", "c", 10, KeyValue.Type.Delete, "dont-care"), + create("R1", "cf", "c", 10, KeyValue.Type.Put, "dont-care"), // no + create("R1", "cf", "c", 9, KeyValue.Type.Put, "dont-care"), // inc // column d - KeyValueTestUtil.create("R1", "cf", "d", 11, KeyValue.Type.Put, "dont-care"), // inc - KeyValueTestUtil.create("R1", "cf", "d", 10, KeyValue.Type.DeleteColumn, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "d", 9, KeyValue.Type.Put, "dont-care"), // no - KeyValueTestUtil.create("R1", "cf", "d", 8, KeyValue.Type.Put, "dont-care"), // no + create("R1", "cf", "d", 11, KeyValue.Type.Put, "dont-care"), // inc + create("R1", "cf", "d", 10, KeyValue.Type.DeleteColumn, "dont-care"), + create("R1", "cf", "d", 9, KeyValue.Type.Put, "dont-care"), // no + create("R1", "cf", "d", 8, KeyValue.Type.Put, "dont-care"), // no }; List<KeyValueScanner> scanners = scanFixture(kvs); - try (StoreScanner scan = new StoreScanner(new Scan().setMaxVersions(2), - scanInfo, scanType, null, scanners)) { + try (StoreScanner scan = + new StoreScanner(new Scan().readVersions(2), scanInfo, null, scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(5, results.size()); - Assert.assertEquals(kvs[0], results.get(0)); - Assert.assertEquals(kvs[2], results.get(1)); - Assert.assertEquals(kvs[3], results.get(2)); - Assert.assertEquals(kvs[6], results.get(3)); - Assert.assertEquals(kvs[7], results.get(4)); + assertEquals(true, scan.next(results)); + assertEquals(5, results.size()); + assertEquals(kvs[0], results.get(0)); + assertEquals(kvs[2], results.get(1)); + assertEquals(kvs[3], results.get(2)); + assertEquals(kvs[6], results.get(3)); + assertEquals(kvs[7], results.get(4)); } } @Test public void testDeleteFamily() throws IOException { - KeyValue [] kvs = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", 100, KeyValue.Type.DeleteFamily, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "b", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "c", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "d", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "e", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "e", 11, KeyValue.Type.DeleteColumn, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "f", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "g", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "g", 11, KeyValue.Type.Delete, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "h", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "i", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R2", "cf", "a", 11, KeyValue.Type.Put, "dont-care"), + KeyValue[] kvs = new KeyValue[] { + create("R1", "cf", "a", 100, KeyValue.Type.DeleteFamily, "dont-care"), + create("R1", "cf", "b", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "c", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "d", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "e", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "e", 11, KeyValue.Type.DeleteColumn, "dont-care"), + create("R1", "cf", "f", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "g", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "g", 11, KeyValue.Type.Delete, "dont-care"), + create("R1", "cf", "h", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "i", 11, KeyValue.Type.Put, "dont-care"), + create("R2", "cf", "a", 11, KeyValue.Type.Put, "dont-care"), }; List<KeyValueScanner> scanners = scanFixture(kvs); try (StoreScanner scan = - new StoreScanner(new Scan().setMaxVersions(Integer.MAX_VALUE), scanInfo, scanType, null, - scanners)) { + new StoreScanner(new Scan().readAllVersions(), scanInfo, null, scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(0, results.size()); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(kvs[kvs.length-1], results.get(0)); + assertEquals(true, scan.next(results)); + assertEquals(0, results.size()); + assertEquals(true, scan.next(results)); + assertEquals(1, results.size()); + assertEquals(kvs[kvs.length - 1], results.get(0)); - Assert.assertEquals(false, scan.next(results)); + assertEquals(false, scan.next(results)); } } @Test public void testDeleteColumn() throws IOException { KeyValue [] kvs = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", 10, KeyValue.Type.DeleteColumn, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", 9, KeyValue.Type.Delete, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", 8, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "b", 5, KeyValue.Type.Put, "dont-care") + create("R1", "cf", "a", 10, KeyValue.Type.DeleteColumn, "dont-care"), + create("R1", "cf", "a", 9, KeyValue.Type.Delete, "dont-care"), + create("R1", "cf", "a", 8, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "b", 5, KeyValue.Type.Put, "dont-care") }; List<KeyValueScanner> scanners = scanFixture(kvs); - try (StoreScanner scan = new StoreScanner(new Scan(), scanInfo, scanType, null, - scanners)) { + try (StoreScanner scan = new StoreScanner(new Scan(), scanInfo, null, scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(kvs[3], results.get(0)); + assertEquals(true, scan.next(results)); + assertEquals(1, results.size()); + assertEquals(kvs[3], results.get(0)); } } - private static final KeyValue [] kvs = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "b", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "c", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "d", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "e", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "f", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "g", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "h", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "i", 11, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R2", "cf", "a", 11, KeyValue.Type.Put, "dont-care"), + private static final KeyValue[] kvs = new KeyValue[] { + create("R1", "cf", "a", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "b", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "c", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "d", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "e", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "f", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "g", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "h", 11, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "i", 11, KeyValue.Type.Put, "dont-care"), + create("R2", "cf", "a", 11, KeyValue.Type.Put, "dont-care"), }; @Test public void testSkipColumn() throws IOException { List<KeyValueScanner> scanners = scanFixture(kvs); - try (StoreScanner scan = - new StoreScanner(new Scan(), scanInfo, scanType, getCols("a", "d"), scanners)) { + try (StoreScanner scan = new StoreScanner(new Scan(), scanInfo, getCols("a", "d"), scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(2, results.size()); - Assert.assertEquals(kvs[0], results.get(0)); - Assert.assertEquals(kvs[3], results.get(1)); + assertEquals(true, scan.next(results)); + assertEquals(2, results.size()); + assertEquals(kvs[0], results.get(0)); + assertEquals(kvs[3], results.get(1)); results.clear(); - Assert.assertEquals(true, scan.next(results)); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(kvs[kvs.length-1], results.get(0)); + assertEquals(true, scan.next(results)); + assertEquals(1, results.size()); + assertEquals(kvs[kvs.length - 1], results.get(0)); results.clear(); - Assert.assertEquals(false, scan.next(results)); + assertEquals(false, scan.next(results)); } } @@ -818,54 +784,48 @@ public class TestStoreScanner { public void testWildCardTtlScan() throws IOException { long now = System.currentTimeMillis(); KeyValue [] kvs = new KeyValue[] { - KeyValueTestUtil.create("R1", "cf", "a", now-1000, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "b", now-10, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "c", now-200, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "d", now-10000, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R2", "cf", "a", now, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R2", "cf", "b", now-10, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R2", "cf", "c", now-200, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R2", "cf", "c", now-1000, KeyValue.Type.Put, "dont-care") + create("R1", "cf", "a", now-1000, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "b", now-10, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "c", now-200, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "d", now-10000, KeyValue.Type.Put, "dont-care"), + create("R2", "cf", "a", now, KeyValue.Type.Put, "dont-care"), + create("R2", "cf", "b", now-10, KeyValue.Type.Put, "dont-care"), + create("R2", "cf", "c", now-200, KeyValue.Type.Put, "dont-care"), + create("R2", "cf", "c", now-1000, KeyValue.Type.Put, "dont-care") }; List<KeyValueScanner> scanners = scanFixture(kvs); Scan scan = new Scan(); - scan.setMaxVersions(1); + scan.readVersions(1); ScanInfo scanInfo = new ScanInfo(CONF, CF, 0, 1, 500, KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, CellComparator.COMPARATOR, false); - ScanType scanType = ScanType.USER_SCAN; - try (StoreScanner scanner = new StoreScanner(scan, scanInfo, scanType, null, scanners)) { + try (StoreScanner scanner = new StoreScanner(scan, scanInfo, null, scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scanner.next(results)); - Assert.assertEquals(2, results.size()); - Assert.assertEquals(kvs[1], results.get(0)); - Assert.assertEquals(kvs[2], results.get(1)); + assertEquals(true, scanner.next(results)); + assertEquals(2, results.size()); + assertEquals(kvs[1], results.get(0)); + assertEquals(kvs[2], results.get(1)); results.clear(); - Assert.assertEquals(true, scanner.next(results)); - Assert.assertEquals(3, results.size()); - Assert.assertEquals(kvs[4], results.get(0)); - Assert.assertEquals(kvs[5], results.get(1)); - Assert.assertEquals(kvs[6], results.get(2)); + assertEquals(true, scanner.next(results)); + assertEquals(3, results.size()); + assertEquals(kvs[4], results.get(0)); + assertEquals(kvs[5], results.get(1)); + assertEquals(kvs[6], results.get(2)); results.clear(); - Assert.assertEquals(false, scanner.next(results)); + assertEquals(false, scanner.next(results)); } } @Test public void testScannerReseekDoesntNPE() throws Exception { List<KeyValueScanner> scanners = scanFixture(kvs); - try (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 + try (StoreScanner scan = new StoreScanner(new Scan(), scanInfo, 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(Collections.EMPTY_LIST, Collections.EMPTY_LIST); - - scan.updateReaders(Collections.EMPTY_LIST, Collections.EMPTY_LIST); - + scan.updateReaders(Collections.emptyList(), Collections.emptyList()); + scan.updateReaders(Collections.emptyList(), Collections.emptyList()); scan.peek(); } } @@ -875,15 +835,14 @@ public class TestStoreScanner { * TODO this fails, since we don't handle deletions, etc, in peek */ public void SKIP_testPeek() throws Exception { - KeyValue [] kvs = new KeyValue [] { - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), - KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Delete, "dont-care"), + KeyValue[] kvs = new KeyValue [] { + create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), + create("R1", "cf", "a", 1, KeyValue.Type.Delete, "dont-care"), }; List<KeyValueScanner> scanners = scanFixture(kvs); - Scan scanSpec = new Scan(Bytes.toBytes("R1")); - try (StoreScanner scan = - new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), scanners)) { - Assert.assertNull(scan.peek()); + Scan scanSpec = new Scan().withStartRow(Bytes.toBytes("R1")); + try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { + assertNull(scan.peek()); } } @@ -893,29 +852,26 @@ public class TestStoreScanner { @Test public void testExpiredDeleteFamily() throws Exception { long now = System.currentTimeMillis(); - KeyValue [] kvs = new KeyValue[] { + KeyValue[] kvs = new KeyValue[] { new KeyValue(Bytes.toBytes("R1"), Bytes.toBytes("cf"), null, now-1000, KeyValue.Type.DeleteFamily), - KeyValueTestUtil.create("R1", "cf", "a", now-10, KeyValue.Type.Put, + create("R1", "cf", "a", now-10, KeyValue.Type.Put, "dont-care"), }; List<KeyValueScanner> scanners = scanFixture(kvs); Scan scan = new Scan(); - scan.setMaxVersions(1); + scan.readVersions(1); // scanner with ttl equal to 500 ScanInfo scanInfo = new ScanInfo(CONF, CF, 0, 1, 500, KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, CellComparator.COMPARATOR, false); - ScanType scanType = ScanType.USER_SCAN; - try (StoreScanner scanner = - new StoreScanner(scan, scanInfo, scanType, null, scanners)) { - + try (StoreScanner scanner = new StoreScanner(scan, scanInfo, null, scanners)) { List<Cell> results = new ArrayList<>(); - Assert.assertEquals(true, scanner.next(results)); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(kvs[1], results.get(0)); + assertEquals(true, scanner.next(results)); + assertEquals(1, results.size()); + assertEquals(kvs[1], results.get(0)); results.clear(); - Assert.assertEquals(false, scanner.next(results)); + assertEquals(false, scanner.next(results)); } } @@ -933,38 +889,36 @@ public class TestStoreScanner { now - 100, KeyValue.Type.DeleteFamily), // live /*1*/ new KeyValue(Bytes.toBytes("R1"), Bytes.toBytes("cf"), null, now - 1000, KeyValue.Type.DeleteFamily), // expired - /*2*/ KeyValueTestUtil.create("R1", "cf", "a", now - 50, + /*2*/ create("R1", "cf", "a", now - 50, KeyValue.Type.Put, "v3"), // live - /*3*/ KeyValueTestUtil.create("R1", "cf", "a", now - 55, + /*3*/ create("R1", "cf", "a", now - 55, KeyValue.Type.Delete, "dontcare"), // live - /*4*/ KeyValueTestUtil.create("R1", "cf", "a", now - 55, + /*4*/ create("R1", "cf", "a", now - 55, KeyValue.Type.Put, "deleted-version v2"), // deleted - /*5*/ KeyValueTestUtil.create("R1", "cf", "a", now - 60, + /*5*/ create("R1", "cf", "a", now - 60, KeyValue.Type.Put, "v1"), // live - /*6*/ KeyValueTestUtil.create("R1", "cf", "a", now - 65, + /*6*/ create("R1", "cf", "a", now - 65, KeyValue.Type.Put, "v0"), // max-version reached - /*7*/ KeyValueTestUtil.create("R1", "cf", "a", + /*7*/ create("R1", "cf", "a", now - 100, KeyValue.Type.DeleteColumn, "dont-care"), // max-version - /*8*/ KeyValueTestUtil.create("R1", "cf", "b", now - 600, + /*8*/ create("R1", "cf", "b", now - 600, KeyValue.Type.DeleteColumn, "dont-care"), //expired - /*9*/ KeyValueTestUtil.create("R1", "cf", "b", now - 70, + /*9*/ create("R1", "cf", "b", now - 70, KeyValue.Type.Put, "v2"), //live - /*10*/ KeyValueTestUtil.create("R1", "cf", "b", now - 750, + /*10*/ create("R1", "cf", "b", now - 750, KeyValue.Type.Put, "v1"), //expired - /*11*/ KeyValueTestUtil.create("R1", "cf", "c", now - 500, + /*11*/ create("R1", "cf", "c", now - 500, KeyValue.Type.Delete, "dontcare"), //expired - /*12*/ KeyValueTestUtil.create("R1", "cf", "c", now - 600, + /*12*/ create("R1", "cf", "c", now - 600, KeyValue.Type.Put, "v1"), //expired - /*13*/ KeyValueTestUtil.create("R1", "cf", "c", now - 1000, + /*13*/ create("R1", "cf", "c", now - 1000, KeyValue.Type.Delete, "dontcare"), //expired - /*14*/ KeyValueTestUtil.create("R1", "cf", "d", now - 60, + /*14*/ create("R1", "cf", "d", now - 60, KeyValue.Type.Put, "expired put"), //live - /*15*/ KeyValueTestUtil.create("R1", "cf", "d", now - 100, + /*15*/ create("R1", "cf", "d", now - 100, KeyValue.Type.Delete, "not-expired delete"), //live }; List<KeyValueScanner> scanners = scanFixture(kvs); - Scan scan = new Scan(); - scan.setMaxVersions(2); ScanInfo scanInfo = new ScanInfo(CONF, Bytes.toBytes("cf"), 0 /* minVersions */, 2 /* maxVersions */, 500 /* ttl */, @@ -973,20 +927,18 @@ public class TestStoreScanner { 200, /* timeToPurgeDeletes */ CellComparator.COMPARATOR, false); try (StoreScanner scanner = - new StoreScanner(scan, scanInfo, - ScanType.COMPACT_DROP_DELETES, null, scanners, - HConstants.OLDEST_TIMESTAMP)) { + new StoreScanner(scanInfo, OptionalInt.of(2), ScanType.COMPACT_DROP_DELETES, scanners)) { List<Cell> results = new ArrayList<>(); results = new ArrayList<>(); - Assert.assertEquals(true, scanner.next(results)); - Assert.assertEquals(kvs[0], results.get(0)); - Assert.assertEquals(kvs[2], results.get(1)); - Assert.assertEquals(kvs[3], results.get(2)); - Assert.assertEquals(kvs[5], results.get(3)); - Assert.assertEquals(kvs[9], results.get(4)); - Assert.assertEquals(kvs[14], results.get(5)); - Assert.assertEquals(kvs[15], results.get(6)); - Assert.assertEquals(7, results.size()); + assertEquals(true, scanner.next(results)); + assertEquals(kvs[0], results.get(0)); + assertEquals(kvs[2], results.get(1)); + assertEquals(kvs[3], results.get(2)); + assertEquals(kvs[5], results.get(3)); + assertEquals(kvs[9], results.get(4)); + assertEquals(kvs[14], results.get(5)); + assertEquals(kvs[15], results.get(6)); + assertEquals(7, results.size()); } } finally { EnvironmentEdgeManagerTestHelper.reset(); @@ -995,17 +947,17 @@ public class TestStoreScanner { @Test public void testPreadNotEnabledForCompactionStoreScanners() throws Exception { - ScanType scanType = ScanType.COMPACT_RETAIN_DELETES; long now = System.currentTimeMillis(); KeyValue[] kvs = new KeyValue[] { new KeyValue(Bytes.toBytes("R1"), Bytes.toBytes("cf"), null, now - 1000, KeyValue.Type.DeleteFamily), - KeyValueTestUtil.create("R1", "cf", "a", now - 10, KeyValue.Type.Put, "dont-care"), }; + create("R1", "cf", "a", now - 10, KeyValue.Type.Put, "dont-care"), }; List<KeyValueScanner> scanners = scanFixture(kvs); - Scan scan = new Scan(); ScanInfo scanInfo = new ScanInfo(CONF, CF, 0, 1, 500, KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, CellComparator.COMPARATOR, false); - StoreScanner storeScanner = new StoreScanner(scan, scanInfo, scanType, null, scanners); - assertFalse(storeScanner.isScanUsePread()); + try (StoreScanner storeScanner = new StoreScanner(scanInfo, OptionalInt.empty(), + ScanType.COMPACT_RETAIN_DELETES, scanners)) { + assertFalse(storeScanner.isScanUsePread()); + } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/8d33949b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java index 993a1fd..2704fa4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java @@ -27,6 +27,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.NavigableSet; +import java.util.OptionalInt; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; @@ -251,18 +252,17 @@ public class TestCoprocessorScanPolicy { family.getMinVersions(), newVersions == null ? family.getMaxVersions() : newVersions, newTtl == null ? oldSI.getTtl() : newTtl, family.getKeepDeletedCells(), family.getBlocksize(), oldSI.getTimeToPurgeDeletes(), oldSI.getComparator(), family.isNewVersionBehavior()); - Scan scan = new Scan(); - scan.setMaxVersions(newVersions == null ? oldSI.getMaxVersions() : newVersions); - return new StoreScanner(store, scanInfo, scan, scanners, - ScanType.COMPACT_RETAIN_DELETES, store.getSmallestReadPoint(), + return new StoreScanner(store, scanInfo, + newVersions == null ? OptionalInt.empty() : OptionalInt.of(newVersions.intValue()), + scanners, ScanType.COMPACT_RETAIN_DELETES, store.getSmallestReadPoint(), HConstants.OLDEST_TIMESTAMP); } @Override public InternalScanner preCompactScannerOpen( - final ObserverContext<RegionCoprocessorEnvironment> c, - Store store, List<? extends KeyValueScanner> scanners, ScanType scanType, - long earliestPutTs, InternalScanner s) throws IOException { + final ObserverContext<RegionCoprocessorEnvironment> c, Store store, + List<? extends KeyValueScanner> scanners, ScanType scanType, long earliestPutTs, + InternalScanner s) throws IOException { Long newTtl = ttls.get(store.getTableName()); Integer newVersions = versions.get(store.getTableName()); ScanInfo oldSI = store.getScanInfo(); @@ -270,11 +270,11 @@ public class TestCoprocessorScanPolicy { ScanInfo scanInfo = new ScanInfo(TEST_UTIL.getConfiguration(), family.getName(), family.getMinVersions(), newVersions == null ? family.getMaxVersions() : newVersions, newTtl == null ? oldSI.getTtl() : newTtl, family.getKeepDeletedCells(), - family.getBlocksize(), oldSI.getTimeToPurgeDeletes(), oldSI.getComparator(), family.isNewVersionBehavior()); - Scan scan = new Scan(); - scan.setMaxVersions(newVersions == null ? oldSI.getMaxVersions() : newVersions); - return new StoreScanner(store, scanInfo, scan, scanners, scanType, - store.getSmallestReadPoint(), earliestPutTs); + family.getBlocksize(), oldSI.getTimeToPurgeDeletes(), oldSI.getComparator(), + family.isNewVersionBehavior()); + return new StoreScanner(store, scanInfo, + newVersions == null ? OptionalInt.empty() : OptionalInt.of(newVersions.intValue()), + scanners, scanType, store.getSmallestReadPoint(), earliestPutTs); } @Override