Refine search
private void checkRow(byte[] row, int count, Table... tables) throws IOException { Get get = new Get(row); for (Table table : tables) { Result res = table.get(get); assertEquals("Table '" + table + "' did not have the expected number of results.", count, res.size()); } }
private void assertResultEquals(Result result, int key, int start, int to) { assertEquals(to - start, result.size()); for (int i = start; i < to; i++) { assertEquals(key, Bytes.toInt(result.getValue(CF, Bytes.toBytes("cq" + i)))); } assertEquals(to - start == 4, result.mayHaveMoreCellsInRow()); }
@Test public void testMultiGet() throws Exception { ArrayList<Get> gets = new ArrayList<>(2); gets.add(new Get(ROW_1)); gets.add(new Get(ROW_2)); Result[] results = remoteTable.get(gets); assertNotNull(results); assertEquals(2, results.length); assertEquals(1, results[0].size()); assertEquals(2, results[1].size()); Get g = new Get(ROW_1); g.setMaxVersions(3); gets.add(g); assertNotNull(results); assertEquals(2, results.length); assertEquals(1, results[0].size()); assertEquals(3, results[1].size());
@Test public void testBatchDoNotAllowPartial() throws InterruptedException, ExecutionException { // we set batch to 2 and max result size to 1, then server will only returns one result per call // but we should get 2 + 1 for every row. List<Result> results = TABLE.scanAll(new Scan().setBatch(2).setMaxResultSize(1)).get(); assertEquals(2 * COUNT, results.size()); for (int i = 0; i < COUNT; i++) { Result firstTwo = results.get(2 * i); assertEquals(String.format("%02d", i), Bytes.toString(firstTwo.getRow())); assertEquals(2, firstTwo.size()); assertEquals(i, Bytes.toInt(firstTwo.getValue(FAMILY, CQS[0]))); assertEquals(2 * i, Bytes.toInt(firstTwo.getValue(FAMILY, CQS[1]))); Result secondOne = results.get(2 * i + 1); assertEquals(String.format("%02d", i), Bytes.toString(secondOne.getRow())); assertEquals(1, secondOne.size()); assertEquals(3 * i, Bytes.toInt(secondOne.getValue(FAMILY, CQS[2]))); } }
/** * Puts are buffered, but this tests when a delete (not-buffered) is applied * before the actual Put that creates it. * @throws Exception */ @Test public void testApplyDeleteBeforePut() throws Exception { List<WALEntry> entries = new ArrayList<>(5); List<Cell> cells = new ArrayList<>(); for(int i = 0; i < 2; i++) { entries.add(createEntry(TABLE_NAME1, i, KeyValue.Type.Put, cells)); } entries.add(createEntry(TABLE_NAME1, 1, KeyValue.Type.DeleteFamily, cells)); for(int i = 3; i < 5; i++) { entries.add(createEntry(TABLE_NAME1, i, KeyValue.Type.Put, cells)); } SINK.replicateEntries(entries, CellUtil.createCellScanner(cells.iterator()), replicationClusterId, baseNamespaceDir, hfileArchiveDir); Get get = new Get(Bytes.toBytes(1)); Result res = table1.get(get); assertEquals(0, res.size()); }
@Test public void testReversedBatchDoNotAllowPartial() throws InterruptedException, ExecutionException { // we set batch to 2 and max result size to 1, then server will only returns one result per call // but we should get 2 + 1 for every row. List<Result> results = TABLE.scanAll(new Scan().setBatch(2).setMaxResultSize(1).setReversed(true)).get(); assertEquals(2 * COUNT, results.size()); for (int i = 0; i < COUNT; i++) { int row = COUNT - i - 1; Result firstTwo = results.get(2 * i); assertEquals(String.format("%02d", row), Bytes.toString(firstTwo.getRow())); assertEquals(2, firstTwo.size()); assertEquals(row, Bytes.toInt(firstTwo.getValue(FAMILY, CQS[0]))); assertEquals(2 * row, Bytes.toInt(firstTwo.getValue(FAMILY, CQS[1]))); Result secondOne = results.get(2 * i + 1); assertEquals(String.format("%02d", row), Bytes.toString(secondOne.getRow())); assertEquals(1, secondOne.size()); assertEquals(3 * row, Bytes.toInt(secondOne.getValue(FAMILY, CQS[2]))); } } }
private void ensureRowNotReplicated(byte[] row, byte[] fam, Table... tables) throws IOException { Get get = new Get(row); get.addFamily(fam); for (Table table : tables) { Result res = table.get(get); assertEquals(0, res.size()); } }
static void verifyResult(Result result, List<Cell> expKvList, boolean toLog, String msg) { LOG.info(msg); LOG.info("Expected count: " + expKvList.size()); LOG.info("Actual count: " + result.size()); if (expKvList.isEmpty()) return; int i = 0; for (Cell kv : result.rawCells()) { if (i >= expKvList.size()) { break; // we will check the size later } Cell kvExp = expKvList.get(i++); if (toLog) { LOG.info("get kv is: " + kv.toString()); LOG.info("exp kv is: " + kvExp.toString()); } assertTrue("Not equal", kvExp.equals(kv)); } assertEquals(expKvList.size(), result.size()); }
@Test public void testAddAndRemoveClusters() throws Exception { LOG.info("testAddAndRemoveClusters"); htable1.put(put); Get get = new Get(rowKey); for (int i = 0; i < NB_RETRIES; i++) { if (i == NB_RETRIES - 1) { if (res.size() >= 1) { fail("Not supposed to be replicated"); } else { htable1.put(put); get = new Get(rowKey); for (int i = 0; i < NB_RETRIES; i++) { if (i == NB_RETRIES - 1) {
void validateData(Table table, int rownum) throws IOException { String row = "row" + String.format("%1$04d", rownum); Get get = new Get(Bytes.toBytes(row)); get.addFamily(HConstants.CATALOG_FAMILY); Result result = table.get(get); assertTrue(result.size() == 1); assertTrue(Bytes.equals(value, result.getValue(HConstants.CATALOG_FAMILY, null))); LOG.info("Validated row " + row); }
@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 testCompleteResult() throws InterruptedException, ExecutionException { int limit = 5; Scan scan = new Scan().setFilter(new ColumnCountOnRowFilter(2)).setMaxResultSize(1).setLimit(limit); List<Result> results = TABLE.scanAll(scan).get(); assertEquals(limit, results.size()); IntStream.range(0, limit).forEach(i -> { Result result = results.get(i); assertEquals(i, Bytes.toInt(result.getRow())); assertEquals(2, result.size()); assertFalse(result.mayHaveMoreCellsInRow()); assertEquals(i, Bytes.toInt(result.getValue(FAMILY, CQS[0]))); assertEquals(2 * i, Bytes.toInt(result.getValue(FAMILY, CQS[1]))); }); }
private void checkWithWait(byte[] row, int count, Table table) throws Exception { Get get = new Get(row); for (int i = 0; i < NB_RETRIES; i++) { if (i == NB_RETRIES - 1) { fail("Waited too much time while getting the row."); } boolean rowReplicated = false; Result res = table.get(get); if (res.size() >= 1) { LOG.info("Row is replicated"); rowReplicated = true; assertEquals("Table '" + table + "' did not have the expected number of results.", count, res.size()); break; } if (rowReplicated) { break; } else { Thread.sleep(SLEEP_TIME); } } }
private void checkResult(Result r, byte[] fam, byte[] col, byte[] ... vals) { assertEquals(r.size(), vals.length); List<Cell> kvs = r.getColumnCells(fam, col); assertEquals(kvs.size(), vals.length); for (int i=0;i<vals.length;i++) { assertArrayEquals(CellUtil.cloneValue(kvs.get(i)), vals[i]); } }
@Test public void testDisableInactivePeer() throws Exception { utility2.shutdownMiniHBaseCluster(); StartMiniClusterOption option = StartMiniClusterOption.builder().numRegionServers(2).build(); utility2.startMiniHBaseCluster(option); Get get = new Get(rowkey); for (int i = 0; i < NB_RETRIES; i++) { Result res = htable2.get(get); if (res.size() >= 1) { fail("Replication wasn't disabled"); } else {
private void ensureRowNotExisted(Table target, byte[] row, byte[]... families) throws Exception { for (byte[] fam : families) { Get get = new Get(row); get.addFamily(fam); for (int i = 0; i < NB_RETRIES; i++) { if (i == NB_RETRIES - 1) { fail("Waited too much time for delete replication"); } Result res = target.get(get); if (res.size() >= 1) { LOG.info("Row not deleted"); } else { break; } Thread.sleep(10 * SLEEP_TIME); } } } }
@Test public void testGet_NullQualifier() throws IOException { Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY); Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); table.put(put); put = new Put(ROW); put.addColumn(FAMILY, null, VALUE); table.put(put); LOG.info("Row put"); Get get = new Get(ROW); get.addColumn(FAMILY, null); Result r = table.get(get); assertEquals(1, r.size()); get = new Get(ROW); get.addFamily(FAMILY); r = table.get(get); assertEquals(2, r.size()); }
@Test public void testAllowPartial() throws InterruptedException, ExecutionException { int limit = 5; Scan scan = new Scan().setFilter(new ColumnCountOnRowFilter(2)).setMaxResultSize(1) .setAllowPartialResults(true).setLimit(limit); List<Result> results = TABLE.scanAll(scan).get(); assertEquals(2 * limit, results.size()); IntStream.range(0, 2 * limit).forEach(i -> { int key = i / 2; Result result = results.get(i); assertEquals(key, Bytes.toInt(result.getRow())); assertEquals(1, result.size()); assertTrue(result.mayHaveMoreCellsInRow()); int cqIndex = i % 2; assertEquals(key * (cqIndex + 1), Bytes.toInt(result.getValue(FAMILY, CQS[cqIndex]))); }); }