Refine search
@Test public void testRegionObserverScanTimeStacking() throws Exception { byte[] ROW = Bytes.toBytes("testRow"); byte[] TABLE = Bytes.toBytes(getClass().getName()); byte[] A = Bytes.toBytes("A"); byte[][] FAMILIES = new byte[][] { A }; // Use new HTU to not overlap with the DFS cluster started in #CompactionStacking Configuration conf = new HBaseTestingUtility().getConfiguration(); HRegion region = initHRegion(TABLE, getClass().getName(), conf, FAMILIES); RegionCoprocessorHost h = region.getCoprocessorHost(); h.load(NoDataFromScan.class, Coprocessor.PRIORITY_HIGHEST, conf); h.load(EmptyRegionObsever.class, Coprocessor.PRIORITY_USER, conf); Put put = new Put(ROW); put.addColumn(A, A, A); region.put(put); Get get = new Get(ROW); Result r = region.get(get); assertNull( "Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: " + r, r.listCells()); HBaseTestingUtility.closeRegionAndWAL(region); }
@Test public void testRegionObserverFlushTimeStacking() throws Exception { byte[] ROW = Bytes.toBytes("testRow"); byte[] TABLE = Bytes.toBytes(getClass().getName()); byte[] A = Bytes.toBytes("A"); byte[][] FAMILIES = new byte[][] { A }; // Use new HTU to not overlap with the DFS cluster started in #CompactionStacking Configuration conf = new HBaseTestingUtility().getConfiguration(); HRegion region = initHRegion(TABLE, getClass().getName(), conf, FAMILIES); RegionCoprocessorHost h = region.getCoprocessorHost(); h.load(NoDataFromFlush.class, Coprocessor.PRIORITY_HIGHEST, conf); h.load(EmptyRegionObsever.class, Coprocessor.PRIORITY_USER, conf); // put a row and flush it to disk Put put = new Put(ROW); put.addColumn(A, A, A); region.put(put); region.flush(true); Get get = new Get(ROW); Result r = region.get(get); assertNull( "Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: " + r, r.listCells()); HBaseTestingUtility.closeRegionAndWAL(region); }
@Test public void testHolesInMeta() throws Exception { byte[] family = Bytes.toBytes("family"); this.region = initHRegion(tableName, Bytes.toBytes("x"), Bytes.toBytes("z"), method, CONF, false, family); byte[] rowNotServed = Bytes.toBytes("a"); Get g = new Get(rowNotServed); try { region.get(g); fail(); } catch (WrongRegionException x) { // OK } byte[] row = Bytes.toBytes("y"); g = new Get(row); region.get(g); }
protected final void verifyThroughRegion(HBaseTestingUtility util, int start, int end) throws IOException { HRegion region = util.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0); for (int i = start; i < end; i++) { assertEquals(i, Bytes.toInt(region.get(new Get(Bytes.toBytes(i))).getValue(CF, CQ))); } }
@Test public void testGet_FamilyChecker() throws IOException { byte[] row1 = Bytes.toBytes("row1"); byte[] fam1 = Bytes.toBytes("fam1"); byte[] fam2 = Bytes.toBytes("False"); byte[] col1 = Bytes.toBytes("col1"); // Setting up region this.region = initHRegion(tableName, method, CONF, fam1); Get get = new Get(row1); get.addColumn(fam2, col1); // Test try { region.get(get); fail("Expecting DoNotRetryIOException in get but did not get any"); } catch (org.apache.hadoop.hbase.DoNotRetryIOException e) { LOG.info("Got expected DoNotRetryIOException successfully"); } }
private static boolean allReplicasHaveRow(byte[] row) throws IOException { for (RegionServerThread t : TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads()) { for (HRegion region : t.getRegionServer().getRegions(TABLE_NAME)) { if (region.get(new Get(row), false).isEmpty()) { return false; } } } return true; }
protected void assertResultEquals(final HRegion region, final byte [] row, final byte [] family, final byte [] qualifier, final long timestamp, final byte [] value) throws IOException { Get get = new Get(row); get.setTimestamp(timestamp); Result res = region.get(get); NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> map = res.getMap(); byte [] res_value = map.get(family).get(qualifier).get(timestamp); if (value == null) { assertEquals(Bytes.toString(family) + " " + Bytes.toString(qualifier) + " at timestamp " + timestamp, null, res_value); } else { if (res_value == null) { fail(Bytes.toString(family) + " " + Bytes.toString(qualifier) + " at timestamp " + timestamp + "\" was expected to be \"" + Bytes.toStringBinary(value) + " but was null"); } if (res_value != null) { assertEquals(Bytes.toString(family) + " " + Bytes.toString(qualifier) + " at timestamp " + timestamp, value, new String(res_value, StandardCharsets.UTF_8)); } } }
private Cell[] getData(String family, String row, List<String> columns, int expBlocksRowCol, int expBlocksRow, int expBlocksNone) throws IOException { int[] expBlocks = new int[] { expBlocksRowCol, expBlocksRow, expBlocksNone }; Cell[] kvs = null; for (int i = 0; i < BLOOM_TYPE.length; i++) { BloomType bloomType = BLOOM_TYPE[i]; byte[] cf = Bytes.toBytes(family + "_" + bloomType); long blocksStart = getBlkAccessCount(cf); Get get = new Get(Bytes.toBytes(row)); for (String column : columns) { get.addColumn(cf, Bytes.toBytes(column)); } kvs = region.get(get).rawCells(); long blocksEnd = getBlkAccessCount(cf); if (expBlocks[i] != -1) { assertEquals("Blocks Read Check for Bloom: " + bloomType, expBlocks[i], blocksEnd - blocksStart); } System.out.println("Blocks Read for Bloom: " + bloomType + " = " + (blocksEnd - blocksStart) + "Expected = " + expBlocks[i]); } return kvs; }
@Override public void run() { for (int i=0; i<numOps; i++) { try { Append a = new Append(row); a.addColumn(fam1, qual1, val); a.addColumn(fam1, qual2, val); a.addColumn(fam2, qual3, val); a.setDurability(Durability.ASYNC_WAL); region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE); Get g = new Get(row); Result result = region.get(g); assertEquals(result.getValue(fam1, qual1).length, result.getValue(fam1, qual2).length); assertEquals(result.getValue(fam1, qual1).length, result.getValue(fam2, qual3).length); } catch (IOException e) { e.printStackTrace(); failures.incrementAndGet(); fail(); } } } };
@Test public void testDeleteRowWithFutureTs() throws IOException { byte[] fam = Bytes.toBytes("info"); byte[][] families = { fam }; this.region = initHRegion(tableName, method, CONF, families); byte[] row = Bytes.toBytes("table_name"); // column names byte[] serverinfo = Bytes.toBytes("serverinfo"); // add data in the far future Put put = new Put(row); put.addColumn(fam, serverinfo, HConstants.LATEST_TIMESTAMP - 5, Bytes.toBytes("value")); region.put(put); // now delete something in the present Delete delete = new Delete(row); region.delete(delete); // make sure we still see our data Get get = new Get(row).addColumn(fam, serverinfo); Result result = region.get(get); assertEquals(1, result.size()); // delete the future row delete = new Delete(row, HConstants.LATEST_TIMESTAMP - 3); region.delete(delete); // make sure it is gone get = new Get(row).addColumn(fam, serverinfo); result = region.get(get); assertEquals(0, result.size()); }
@Test public void testDelete_multiDeleteColumn() throws IOException { byte[] row1 = Bytes.toBytes("row1"); byte[] fam1 = Bytes.toBytes("fam1"); byte[] qual = Bytes.toBytes("qualifier"); byte[] value = Bytes.toBytes("value"); Put put = new Put(row1); put.addColumn(fam1, qual, 1, value); put.addColumn(fam1, qual, 2, value); this.region = initHRegion(tableName, method, CONF, fam1); region.put(put); // We do support deleting more than 1 'latest' version Delete delete = new Delete(row1); delete.addColumn(fam1, qual); delete.addColumn(fam1, qual); region.delete(delete); Get get = new Get(row1); get.addFamily(fam1); Result r = region.get(get); assertEquals(0, r.size()); }
static void assertGet(final HRegion r, final byte[] family, final byte[] k) throws IOException { // Now I have k, get values out and assert they are as expected. Get get = new Get(k).addFamily(family).setMaxVersions(); Cell[] results = r.get(get).rawCells(); for (int j = 0; j < results.length; j++) { byte[] tmp = CellUtil.cloneValue(results[j]); // Row should be equal to value every time. assertTrue(Bytes.equals(k, tmp)); } }
private static void assertGet(final HRegion region, byte [] row, byte [] familiy, byte[] qualifier, byte[] value) throws IOException { // run a get and see if the value matches Get get = new Get(row); get.addColumn(familiy, qualifier); Result result = region.get(get); assertEquals(1, result.size()); Cell kv = result.rawCells()[0]; byte[] r = CellUtil.cloneValue(kv); assertTrue(Bytes.compareTo(r, value) == 0); }