@Test public void testCompressingWithNullDictionaries() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); byte [] blahBytes = Bytes.toBytes("blah"); Compressor.writeCompressed(blahBytes, 0, blahBytes.length, dos, null); dos.close(); byte [] dosbytes = baos.toByteArray(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dosbytes)); byte [] product = Compressor.readCompressed(dis, null); assertTrue(Bytes.equals(blahBytes, product)); }
@Override public void run() { gets.add(new Get(ROW)); gets.add(new Get(ROW1)); try { CustomInnerRegionObserver.getCdl().set(latch); Result[] r = table.get(gets); assertTrue(Bytes.equals(r[0].getRow(), ROW)); assertTrue(Bytes.equals(r[1].getRow(), ROW1)); } catch (IOException e) { } } }
private static void assertSort(List<? extends Row> rows) { assertFalse(rows.isEmpty()); assertEquals(DEFAULT_ROWS.size(), rows.size()); for (int i = 0; i != DEFAULT_ROWS.size(); ++i) { assertTrue(Bytes.equals(DEFAULT_ROWS.get(i), rows.get(i).getRow())); } } }
/** * Create a znode with data */ @Test public void testCreateWithParents() throws KeeperException, InterruptedException { byte[] expectedData = new byte[] { 1, 2, 3 }; ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4/testCreateWithParents", expectedData); byte[] data = ZKUtil.getData(ZKW, "/l1/l2/l3/l4/testCreateWithParents"); assertTrue(Bytes.equals(expectedData, data)); ZKUtil.deleteNodeRecursively(ZKW, "/l1"); ZKUtil.createWithParents(ZKW, "/testCreateWithParents", expectedData); data = ZKUtil.getData(ZKW, "/testCreateWithParents"); assertTrue(Bytes.equals(expectedData, data)); ZKUtil.deleteNodeRecursively(ZKW, "/testCreateWithParents"); }
@Test public void testLocateAfter() throws IOException, InterruptedException, ExecutionException { byte[] row = Bytes.toBytes("1"); byte[] splitKey = Arrays.copyOf(row, 2); TEST_UTIL.createTable(TABLE_NAME, FAMILY, new byte[][] { splitKey }); TEST_UTIL.waitTableAvailable(TABLE_NAME); HRegionLocation currentLoc = getDefaultRegionLocation(TABLE_NAME, row, RegionLocateType.CURRENT, false).get(); ServerName currentServerName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName(); assertLocEquals(EMPTY_START_ROW, splitKey, currentServerName, currentLoc); HRegionLocation afterLoc = getDefaultRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER, false).get(); ServerName afterServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()) .filter(rs -> rs.getRegions(TABLE_NAME).stream() .anyMatch(r -> Bytes.equals(splitKey, r.getRegionInfo().getStartKey()))) .findAny().get().getServerName(); assertLocEquals(splitKey, EMPTY_END_ROW, afterServerName, afterLoc); assertSame(afterLoc, getDefaultRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER, false).get()); }
private static boolean needShuffle(List<? extends Row> rows) { assertFalse(rows.isEmpty()); assertEquals(DEFAULT_ROWS.size(), rows.size()); for (int i = 0; i != DEFAULT_ROWS.size(); ++i) { if (!Bytes.equals(DEFAULT_ROWS.get(i), rows.get(i).getRow())) { return false; } } return true; }
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); }
private void initiateScan(Table table) throws IOException { Scan scan = new Scan(); if (reverse) { scan.setReversed(true); } CustomInnerRegionObserver.getCdl().set(latch); ResultScanner resScanner = table.getScanner(scan); int i = (reverse ? ROWS.length - 1 : 0); boolean resultFound = false; for (Result result : resScanner) { resultFound = true; System.out.println(result); if (!reverse) { assertTrue(Bytes.equals(result.getRow(), ROWS[i])); i++; } else { assertTrue(Bytes.equals(result.getRow(), ROWS[i])); i--; } } assertTrue(resultFound); } }
@Override protected List<String> extractAuths(String user, List<Result> results) { List<String> auths = new ArrayList<>(); for (Result result : results) { if (Bytes.equals(result.getRow(), Bytes.toBytes(user))) { NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(LABELS_TABLE_FAMILY); for (byte[] q : familyMap.keySet()) { auths.add(Bytes.toString(q, 0, q.length)); } } } return auths; } }
private void result(byte[] fam, byte[] row, byte[] qual, byte[] row2, Table table, byte[] value, byte[] value2, byte[] row1, byte[] value1) throws IOException { Scan s = new Scan(row); // If filters are used this attribute can be specifically check for in // filterKV method and // kvs can be filtered out if the tags of interest is not found in that kv s.setAttribute("visibility", Bytes.toBytes("myTag")); ResultScanner scanner = null; try { scanner = table.getScanner(s); Result next = scanner.next(); assertTrue(Bytes.equals(next.getRow(), row)); assertTrue(Bytes.equals(next.getValue(fam, qual), value)); Result next2 = scanner.next(); assertTrue(next2 != null); assertTrue(Bytes.equals(next2.getRow(), row1)); assertTrue(Bytes.equals(next2.getValue(fam, qual), value1)); next2 = scanner.next(); assertTrue(next2 != null); assertTrue(Bytes.equals(next2.getRow(), row2)); assertTrue(Bytes.equals(next2.getValue(fam, qual), value2)); } finally { if (scanner != null) scanner.close(); } }
@Override protected void checkModel(CellModel model) { assertTrue(Bytes.equals(model.getColumn(), COLUMN)); assertTrue(Bytes.equals(model.getValue(), VALUE)); assertTrue(model.hasUserTimestamp()); assertEquals(TIMESTAMP, model.getTimestamp()); }
@Test public void testCompressUncompressTags2() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TagCompressionContext context = new TagCompressionContext(LRUDictionary.class, Byte.MAX_VALUE); KeyValue kv1 = createKVWithTags(1); int tagsLength1 = kv1.getTagsLength(); context.compressTags(baos, kv1.getTagsArray(), kv1.getTagsOffset(), tagsLength1); KeyValue kv2 = createKVWithTags(3); int tagsLength2 = kv2.getTagsLength(); context.compressTags(baos, kv2.getTagsArray(), kv2.getTagsOffset(), tagsLength2); context.clear(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.getBuffer()); byte[] dest = new byte[tagsLength1]; context.uncompressTags(bais, dest, 0, tagsLength1); assertTrue(Bytes.equals(kv1.getTagsArray(), kv1.getTagsOffset(), tagsLength1, dest, 0, tagsLength1)); dest = new byte[tagsLength2]; context.uncompressTags(bais, dest, 0, tagsLength2); assertTrue(Bytes.equals(kv2.getTagsArray(), kv2.getTagsOffset(), tagsLength2, dest, 0, tagsLength2)); }
private void verifyCounts(int countRow1, int countRow2) throws Exception { int count1 = 0; int count2 = 0; for (HStoreFile f: r.getStore(COLUMN_FAMILY_TEXT).getStorefiles()) { HFileScanner scanner = f.getReader().getScanner(false, false); scanner.seekTo(); do { byte [] row = CellUtil.cloneRow(scanner.getCell()); if (Bytes.equals(row, STARTROW)) { count1++; } else if(Bytes.equals(row, secondRowBytes)) { count2++; } } while(scanner.next()); } assertEquals(countRow1,count1); assertEquals(countRow2,count2); }
private static void assertResult(Result result, byte[] expectedValue) { assertFalse(result.isEmpty()); for (Cell c : result.rawCells()) { assertTrue(c.toString(), Bytes.equals(ROW, CellUtil.cloneRow(c))); assertTrue(c.toString(), Bytes.equals(FAMILY, CellUtil.cloneFamily(c))); assertTrue(c.toString(), Bytes.equals(expectedValue, CellUtil.cloneValue(c))); } }
public static void assertMetaLocation(Table meta, byte[] row, ServerName serverName, long seqNum, int replicaId, boolean checkSeqNum) throws IOException { Get get = new Get(row); Result result = meta.get(get); assertTrue(Bytes.equals( result.getValue(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(replicaId)), Bytes.toBytes(serverName.getHostAndPort()))); assertTrue(Bytes.equals( result.getValue(HConstants.CATALOG_FAMILY, MetaTableAccessor.getStartCodeColumn(replicaId)), Bytes.toBytes(serverName.getStartcode()))); if (checkSeqNum) { assertTrue(Bytes.equals( result.getValue(HConstants.CATALOG_FAMILY, MetaTableAccessor.getSeqNumColumn(replicaId)), Bytes.toBytes(seqNum))); } }
public void testExpectedNumberOfCellsPerPartialResult(Scan baseScan, int expectedNumberOfCells) throws Exception { if (LOG.isInfoEnabled()) LOG.info("groupSize:" + expectedNumberOfCells); // Use the cellHeapSize to set maxResultSize such that we know how many cells to expect back // from the call. The returned results should NOT exceed expectedNumberOfCells but may be less // than it in cases where expectedNumberOfCells is not an exact multiple of the number of // columns in the table. Scan scan = new Scan(baseScan); scan.setAllowPartialResults(true); scan.setMaxResultSize(getResultSizeForNumberOfCells(expectedNumberOfCells)); ResultScanner scanner = TABLE.getScanner(scan); Result result = null; byte[] prevRow = null; while ((result = scanner.next()) != null) { assertTrue(result.rawCells() != null); // Cases when cell count won't equal expectedNumberOfCells: // 1. Returned result is the final result needed to form the complete result for that row // 2. It is the first result we have seen for that row and thus may have been fetched as // the last group of cells that fit inside the maxResultSize assertTrue( "Result's cell count differed from expected number. result: " + result, result.rawCells().length == expectedNumberOfCells || !result.mayHaveMoreCellsInRow() || !Bytes.equals(prevRow, result.getRow())); prevRow = result.getRow(); } scanner.close(); }
public void testSplit2() throws Exception { // More split tests. byte [] lowest = Bytes.toBytes("http://A"); byte [] highest = Bytes.toBytes("http://z"); byte [] middle = Bytes.toBytes("http://]"); byte [][] parts = Bytes.split(lowest, highest, 1); for (int i = 0; i < parts.length; i++) { System.out.println(Bytes.toString(parts[i])); } assertEquals(3, parts.length); assertTrue(Bytes.equals(parts[1], middle)); }
@Test public void testGetBackBytesWePutIn() { ByteBuffer[] bufs = wrapArrays(HELLO_WORLD_CHUNKS); BufferChain chain = new BufferChain(bufs); assertTrue(Bytes.equals(Bytes.toBytes("hello world"), chain.getBytes())); }
private void compareRegionLoads(Collection<RegionMetrics> regionLoadCluster, Collection<RegionMetrics> regionLoads) { assertEquals("No of regionLoads from clusterStatus and regionloads from RS doesn't match", regionLoadCluster.size(), regionLoads.size()); for (RegionMetrics loadCluster : regionLoadCluster) { boolean matched = false; for (RegionMetrics load : regionLoads) { if (Bytes.equals(loadCluster.getRegionName(), load.getRegionName())) { matched = true; continue; } } assertTrue("The contents of region load from cluster and server should match", matched); } }
private static void assertResult(Result result, byte[] expectedValue, byte[] expectedFromCp) { assertFalse(result.isEmpty()); for (Cell c : result.rawCells()) { assertTrue(c.toString(), Bytes.equals(ROW, CellUtil.cloneRow(c))); assertTrue(c.toString(), Bytes.equals(FAMILY, CellUtil.cloneFamily(c))); if (Bytes.equals(QUALIFIER, CellUtil.cloneQualifier(c))) { assertTrue(c.toString(), Bytes.equals(expectedValue, CellUtil.cloneValue(c))); } else if (Bytes.equals(QUALIFIER_FROM_CP, CellUtil.cloneQualifier(c))) { assertTrue(c.toString(), Bytes.equals(expectedFromCp, CellUtil.cloneValue(c))); } else { fail("No valid qualifier"); } } }