private static void throwExceptionForInvalidRanges(List<RowRange> invalidRanges, boolean details) { StringBuilder sb = new StringBuilder(); sb.append(invalidRanges.size()).append(" invaild ranges.\n"); if (details) { for (RowRange range : invalidRanges) { sb.append( "Invalid range: start row => " + Bytes.toString(range.startRow) + ", stop row => " + Bytes.toString(range.stopRow)).append('\n'); } } throw new IllegalArgumentException(sb.toString()); }
private void getOneRowAndAssertAllExist(final Table table) throws IOException { Get get = new Get(ROWKEY); Result result = table.get(get); assertTrue("Column A value should be a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))).equals("a")); assertTrue("Column B value should be b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))).equals("b")); assertTrue("Column C value should be c", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))).equals("c")); }
@Test public void testGetStargateVersionText() throws IOException { Response response = client.get("/version", Constants.MIMETYPE_TEXT); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type")); String body = Bytes.toString(response.getBody()); assertTrue(body.length() > 0); assertTrue(body.contains(RESTServlet.VERSION_STRING)); assertTrue(body.contains(System.getProperty("java.vm.vendor"))); assertTrue(body.contains(System.getProperty("java.version"))); assertTrue(body.contains(System.getProperty("java.vm.version"))); assertTrue(body.contains(System.getProperty("os.name"))); assertTrue(body.contains(System.getProperty("os.version"))); assertTrue(body.contains(System.getProperty("os.arch"))); // TODO: fix when we actually get a jersey version // assertTrue(body.contains(ServletContainer.class.getPackage().getImplementationVersion())); }
@Override public Void run() throws Exception { GetAuthsResponse authsResponse = null; try (Connection conn = ConnectionFactory.createConnection(conf)) { authsResponse = VisibilityClient.getAuths(conn, "@testgroup"); } catch (Throwable e) { fail("Should not have failed"); } List<String> authsList = new ArrayList<>(authsResponse.getAuthList().size()); for (ByteString authBS : authsResponse.getAuthList()) { authsList.add(Bytes.toString(authBS.toByteArray())); } assertEquals(0, authsList.size()); return null; } });
@Override public Void answer(InvocationOnMock invocation) throws Throwable { ImmutableBytesWritable writer = (ImmutableBytesWritable) invocation.getArgument(0); MapReduceExtendedCell key = (MapReduceExtendedCell) invocation.getArgument(1); assertEquals("Key", Bytes.toString(writer.get())); assertEquals("row", Bytes.toString(CellUtil.cloneRow(key))); return null; } }).when(ctx).write(any(), any());
@Test public void testResolve() throws Exception { final Configuration conf = HBaseConfiguration.create(); init(name.getMethodName(), conf, true); String targetPathName = MobUtils.formatDate(currentDate); Path targetPath = new Path(store.getPath(), targetPathName); store.commitFile(mobFilePath, targetPath); //resolve Cell resultCell1 = store.resolve(seekKey1, false); Cell resultCell2 = store.resolve(seekKey2, false); Cell resultCell3 = store.resolve(seekKey3, false); //compare Assert.assertEquals(Bytes.toString(value), Bytes.toString(CellUtil.cloneValue(resultCell1))); Assert.assertEquals(Bytes.toString(value), Bytes.toString(CellUtil.cloneValue(resultCell2))); Assert.assertEquals(Bytes.toString(value2), Bytes.toString(CellUtil.cloneValue(resultCell3))); }
private void verifyTableDescriptor(final TableDescriptor htd, final TableName tableName, final byte[]... families) { Set<byte[]> htdFamilies = htd.getColumnFamilyNames(); assertEquals(tableName, htd.getTableName()); assertEquals(families.length, htdFamilies.size()); for (byte[] familyName: families) { assertTrue("Expected family " + Bytes.toString(familyName), htdFamilies.contains(familyName)); } } }
@Test public void testRestoreSnapshotOfCloned() throws IOException, InterruptedException { TableName clonedTableName = TableName.valueOf("clonedtb-" + System.currentTimeMillis()); admin.cloneSnapshot(snapshotName0, clonedTableName); verifyRowCount(UTIL, clonedTableName, snapshot0Rows); admin.snapshot(Bytes.toString(snapshotName2), clonedTableName, SnapshotType.FLUSH); UTIL.deleteTable(clonedTableName); admin.cloneSnapshot(snapshotName2, clonedTableName); verifyRowCount(UTIL, clonedTableName, snapshot0Rows); UTIL.deleteTable(clonedTableName); }
private void verifyRegionResults(RegionLocator regionLocator, Map<byte[], String> results, String expected, byte[] row) throws Exception { for (Map.Entry<byte [], String> e: results.entrySet()) { LOG.info("row=" + Bytes.toString(row) + ", expected=" + expected + ", result key=" + Bytes.toString(e.getKey()) + ", value=" + e.getValue()); } HRegionLocation loc = regionLocator.getRegionLocation(row, true); byte[] region = loc.getRegionInfo().getRegionName(); assertTrue("Results should contain region " + Bytes.toStringBinary(region) + " for row '" + Bytes.toStringBinary(row)+ "'", results.containsKey(region)); assertEquals("Invalid result for row '"+Bytes.toStringBinary(row)+"'", expected, results.get(region)); } }
private Result scanAfterBulkLoad(ResultScanner scanner, Result result, String expctedVal) throws IOException { while (result != null) { List<Cell> cells = result.getColumnCells(Bytes.toBytes("col"), Bytes.toBytes("q")); for (Cell _c : cells) { if (Bytes.toString(_c.getRowArray(), _c.getRowOffset(), _c.getRowLength()) .equals("row1")) { System.out .println(Bytes.toString(_c.getRowArray(), _c.getRowOffset(), _c.getRowLength())); System.out.println(Bytes.toString(_c.getQualifierArray(), _c.getQualifierOffset(), _c.getQualifierLength())); System.out.println( Bytes.toString(_c.getValueArray(), _c.getValueOffset(), _c.getValueLength())); Assert.assertEquals(expctedVal, Bytes.toString(_c.getValueArray(), _c.getValueOffset(), _c.getValueLength())); } } result = scanner.next(); } return result; }
private void assertKey(Cell key, byte [] row, byte [] family, byte [] qualifier, byte [] value) throws Exception { assertTrue("Expected row [" + Bytes.toString(row) + "] " + "Got row [" + Bytes.toString(CellUtil.cloneRow(key)) +"]", equals(row, CellUtil.cloneRow(key))); assertTrue("Expected family [" + Bytes.toString(family) + "] " + "Got family [" + Bytes.toString(CellUtil.cloneFamily(key)) + "]", equals(family, CellUtil.cloneFamily(key))); assertTrue("Expected qualifier [" + Bytes.toString(qualifier) + "] " + "Got qualifier [" + Bytes.toString(CellUtil.cloneQualifier(key)) + "]", equals(qualifier, CellUtil.cloneQualifier(key))); assertTrue("Expected value [" + Bytes.toString(value) + "] " + "Got value [" + Bytes.toString(CellUtil.cloneValue(key)) + "]", equals(value, CellUtil.cloneValue(key))); }
@Test public void testRegionNameForRegionReplicas() throws Exception { String tableName = name.getMethodName(); final TableName tn = TableName.valueOf(tableName); String startKey = "startkey"; final byte[] sk = Bytes.toBytes(startKey); String id = "id"; // assert with only the region name without encoding // primary, replicaId = 0 byte [] name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0, false); String nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id, nameStr); // replicaId = 1 name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 1, false); nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id + "_" + String.format(HRegionInfo.REPLICA_ID_FORMAT, 1), nameStr); // replicaId = max name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0xFFFF, false); nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id + "_" + String.format(HRegionInfo.REPLICA_ID_FORMAT, 0xFFFF), nameStr); }
private void stopUsingCurrentWriter() { if (currentWriter != null) { if (LOG.isDebugEnabled()) { LOG.debug("Stopping to use a writer after [" + Bytes.toString(currentWriterEndKey) + "] row; wrote out " + cellsInCurrentWriter + " kvs"); } cellsInCurrentWriter = 0; } currentWriter = null; currentWriterEndKey = (existingWriters.size() + 1 == boundaries.size()) ? null : boundaries.get(existingWriters .size() + 1); } }
@Override public void reduce(ImmutableBytesWritable key, Iterator<Put> values, OutputCollector<ImmutableBytesWritable, Put> output, Reporter reporter) throws IOException { String strKey = Bytes.toString(key.get()); List<Put> result = new ArrayList<>(); while (values.hasNext()) result.add(values.next()); if (relation.keySet().contains(strKey)) { Set<String> set = relation.get(strKey); if (set != null) { assertEquals(set.size(), result.size()); } else { throwAccertionError("Test infrastructure error: set is null"); } } else { throwAccertionError("Test infrastructure error: key not found in map"); } }
private void validateCounts(Table[] htables, byte[] type, int[] expectedCounts) throws IOException { for (int i = 0; i < htables.length; i++) { assertEquals(Bytes.toString(type) + " were replicated back ", expectedCounts[i], getCount(htables[i], type)); } }
private void verifyTableDescriptor(final TableDescriptor htd, final TableName tableName, final byte[]... families) { Set<byte[]> htdFamilies = htd.getColumnFamilyNames(); assertEquals(tableName, htd.getTableName()); assertEquals(families.length, htdFamilies.size()); for (byte[] familyName : families) { assertTrue("Expected family " + Bytes.toString(familyName), htdFamilies.contains(familyName)); } }
@Test public void testCorruptedSnapshot() throws IOException, InterruptedException { SnapshotTestingUtils.corruptSnapshot(TEST_UTIL, Bytes.toString(snapshotName0)); TableName cloneName = TableName.valueOf(getValidMethodName() + "-" + System.currentTimeMillis()); try { admin.cloneSnapshot(snapshotName0, cloneName); fail("Expected CorruptedSnapshotException, got succeeded cloneSnapshot()"); } catch (CorruptedSnapshotException e) { // Got the expected corruption exception. // check for no references of the cloned table. assertFalse(admin.tableExists(cloneName)); } catch (Exception e) { fail("Expected CorruptedSnapshotException got: " + e); } } }
private void assertSingleResult(Result result, byte [] row, byte [] family, byte [] qualifier, byte [] value) throws Exception { assertTrue("Expected row [" + Bytes.toString(row) + "] " + "Got row [" + Bytes.toString(result.getRow()) +"]", equals(row, result.getRow())); assertTrue("Expected a single key but result contains " + result.size(), result.size() == 1); Cell kv = result.rawCells()[0]; assertTrue("Expected family [" + Bytes.toString(family) + "] " + "Got family [" + Bytes.toString(CellUtil.cloneFamily(kv)) + "]", equals(family, CellUtil.cloneFamily(kv))); assertTrue("Expected qualifier [" + Bytes.toString(qualifier) + "] " + "Got qualifier [" + Bytes.toString(CellUtil.cloneQualifier(kv)) + "]", equals(qualifier, CellUtil.cloneQualifier(kv))); assertTrue("Expected value [" + Bytes.toString(value) + "] " + "Got value [" + Bytes.toString(CellUtil.cloneValue(kv)) + "]", equals(value, CellUtil.cloneValue(kv))); }
private void getOneRowAndAssertAllButCExist(final Table table) throws IOException { Get get = new Get(ROWKEY); Result result = table.get(get); assertTrue("Column A value should be a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))).equals("a")); assertTrue("Column B value should be b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))).equals("b")); assertTrue("Column C should not exist", result.getValue(FAMILY, Bytes.toBytes("C")) == null); }