public static boolean matchingValue(final Cell left, final Cell right) { return matchingValue(left, right, left.getValueLength(), right.getValueLength()); }
private static void verifyData(Cell kv, String expectedRow, String expectedCol, long expectedVersion) { assertTrue("RowCheck", CellUtil.matchingRows(kv, Bytes.toBytes(expectedRow))); assertTrue("ColumnCheck", CellUtil.matchingQualifier(kv, Bytes.toBytes(expectedCol))); assertEquals("TSCheck", expectedVersion, kv.getTimestamp()); assertTrue("ValueCheck", CellUtil.matchingValue(kv, genValue(expectedRow, expectedCol, expectedVersion))); }
/** * Does a deep comparison of two Results, down to the byte arrays. * @param res1 first result to compare * @param res2 second result to compare * @throws Exception Every difference is throwing an exception */ public static void compareResults(Result res1, Result res2) throws Exception { if (res2 == null) { throw new Exception("There wasn't enough rows, we stopped at " + Bytes.toStringBinary(res1.getRow())); } if (res1.size() != res2.size()) { throw new Exception("This row doesn't have the same number of KVs: " + res1.toString() + " compared to " + res2.toString()); } Cell[] ourKVs = res1.rawCells(); Cell[] replicatedKVs = res2.rawCells(); for (int i = 0; i < res1.size(); i++) { if (!ourKVs[i].equals(replicatedKVs[i]) || !CellUtil.matchingValue(ourKVs[i], replicatedKVs[i])) { throw new Exception("This result was different: " + res1.toString() + " compared to " + res2.toString()); } } }
private void checkResult(Result r, byte[] col, byte[] ... vals) { assertEquals(r.size(), vals.length); List<Cell> kvs = r.getColumnCells(col, col); assertEquals(kvs.size(), vals.length); for (int i=0;i<vals.length;i++) { assertTrue(CellUtil.matchingValue(kvs.get(i), vals[i])); } }
if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) && CellUtil.matchingValue(cell, value) && cell.getTimestamp() == ts) { return true; for (Cell cell : list) { if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) && CellUtil.matchingValue(cell, value)) { return true;
private void verifyScanFull(Scan s, KeyValue [] kvs) throws IOException { InternalScanner scanner = this.region.getScanner(s); List<Cell> results = new ArrayList<>(); int row = 0; int idx = 0; for (boolean done = true; done; row++) { done = scanner.next(results); Arrays.sort(results.toArray(new Cell[results.size()]), CellComparator.getInstance()); if(results.isEmpty()) break; assertTrue("Scanned too many keys! Only expected " + kvs.length + " total but already scanned " + (results.size() + idx) + (results.isEmpty() ? "" : "(" + results.get(0).toString() + ")"), kvs.length >= idx + results.size()); for (Cell kv : results) { LOG.info("row=" + row + ", result=" + kv.toString() + ", match=" + kvs[idx].toString()); assertTrue("Row mismatch", CellUtil.matchingRows(kv, kvs[idx])); assertTrue("Family mismatch", CellUtil.matchingFamily(kv, kvs[idx])); assertTrue("Qualifier mismatch", CellUtil.matchingQualifier(kv, kvs[idx])); assertTrue("Value mismatch", CellUtil.matchingValue(kv, kvs[idx])); idx++; } results.clear(); } LOG.info("Looked at " + row + " rows with " + idx + " keys"); assertEquals("Expected " + kvs.length + " total keys but scanned " + idx, kvs.length, idx); }
private void isExpectedRowWithoutTimestamps(final int rowIndex, List<Cell> kvs) { int i = 0; for (Cell kv : kvs) { byte[] expectedColname = makeQualifier(rowIndex, i++); assertTrue("Column name", CellUtil.matchingQualifier(kv, expectedColname)); // Value is column name as bytes. Usually result is // 100 bytes in size at least. This is the default size // for BytesWriteable. For comparison, convert bytes to // String and trim to remove trailing null bytes. assertTrue("Content", CellUtil.matchingValue(kv, expectedColname)); } }
private void isExpectedRowWithoutTimestamps(final int rowIndex, List<Cell> kvs) { int i = 0; for (Cell kv : kvs) { byte[] expectedColname = makeQualifier(rowIndex, i++); assertTrue("Column name", CellUtil.matchingQualifier(kv, expectedColname)); // Value is column name as bytes. Usually result is // 100 bytes in size at least. This is the default size // for BytesWriteable. For comparison, convert bytes to // String and trim to remove trailing null bytes. assertTrue("Content", CellUtil.matchingValue(kv, expectedColname)); } }
assertTrue(CellUtil.matchingValue(result.listCells().get(0), Bytes.toBytes("value2-3"))); assertTrue(CellUtil.matchingValue(result.listCells().get(1), Bytes.toBytes("value4-3")));
assertTrue(CellUtil.matchingRows(kvs.get(0), Bytes.toBytes("KEY"))); assertTrue(CellUtil.matchingRows(kvs.get(1), Bytes.toBytes("KEY"))); assertTrue(CellUtil.matchingValue(kvs.get(0), Bytes.toBytes("VALUE" + valueMultiplier))); assertTrue(CellUtil.matchingValue(kvs.get(1), Bytes.toBytes("VALUE" + 2 * valueMultiplier)));
private void assertNResult(Result result, byte [] row, byte [] family, byte [] qualifier, long [] stamps, byte [][] values, int start, int end) throws IOException { assertTrue("Expected row [" + Bytes.toString(row) + "] " + "Got row [" + Bytes.toString(result.getRow()) +"]", equals(row, result.getRow())); int expectedResults = end - start + 1; assertEquals(expectedResults, result.size()); Cell[] keys = result.rawCells(); for (int i=0; i<keys.length; i++) { byte [] value = values[end-i]; long ts = stamps[end-i]; Cell key = keys[i]; assertTrue("(" + i + ") Expected family [" + Bytes.toString(family) + "] " + "Got family [" + Bytes.toString(CellUtil.cloneFamily(key)) + "]", CellUtil.matchingFamily(key, family)); assertTrue("(" + i + ") Expected qualifier [" + Bytes.toString(qualifier) + "] " + "Got qualifier [" + Bytes.toString(CellUtil.cloneQualifier(key))+ "]", CellUtil.matchingQualifier(key, qualifier)); assertTrue("Expected ts [" + ts + "] " + "Got ts [" + key.getTimestamp() + "]", ts == key.getTimestamp()); assertTrue("(" + i + ") Expected value [" + Bytes.toString(value) + "] " + "Got value [" + Bytes.toString(CellUtil.cloneValue(key)) + "]", CellUtil.matchingValue(key, value)); } }
assertTrue(CellUtil.matchingRows(kvs.get(0), Bytes.toBytes("KEY"))); assertTrue(CellUtil.matchingRows(kvs.get(1), Bytes.toBytes("KEY"))); assertTrue(CellUtil.matchingValue(kvs.get(0), Bytes.toBytes("VALUE" + valueMultiplier))); assertTrue(CellUtil.matchingValue(kvs.get(1), Bytes.toBytes("VALUE" + 2 * valueMultiplier)));
assertTrue(CellUtil.matchingRows(kvs.get(0), Bytes.toBytes("KEY"))); assertTrue(CellUtil.matchingRows(kvs.get(1), Bytes.toBytes("KEY"))); assertTrue(CellUtil.matchingValue(kvs.get(0), Bytes.toBytes("VALUE" + valueMultiplier))); assertTrue(CellUtil.matchingValue(kvs.get(1), Bytes.toBytes("VALUE" + 2 * valueMultiplier)));
@Test public void testPutSameKey() { byte[] bytes = Bytes.toBytes(getName()); KeyValue kv = new KeyValue(bytes, bytes, bytes, bytes); this.memstore.add(kv, null); byte[] other = Bytes.toBytes("somethingelse"); KeyValue samekey = new KeyValue(bytes, bytes, bytes, other); this.memstore.add(samekey, null); Cell found = this.memstore.getActive().first(); assertEquals(1, this.memstore.getActive().getCellsCount()); assertTrue(Bytes.toString(found.getValueArray()), CellUtil.matchingValue(samekey, found)); }
assertTrue("Family mismatch", CellUtil.matchingFamily(kv, kvs[idx])); assertTrue("Qualifier mismatch", CellUtil.matchingQualifier(kv, kvs[idx])); assertFalse("Should not have returned whole value", CellUtil.matchingValue(kv, kvs[idx])); if (useLen) { assertEquals("Value in result is not SIZEOF_INT", Bytes.SIZEOF_INT, kv.getValueLength());
static void verifyTestDataBatch(TableName tableName, int batchId) throws Exception { LOG.debug("Verifying test data batch " + batchId); Table table = TEST_UTIL.getConnection().getTable(tableName); for (int i = 0; i < NUM_ROWS_PER_BATCH; ++i) { Get get = new Get(getRowKey(batchId, i)); Result result = table.get(get); for (int j = 0; j < NUM_COLS_PER_ROW; ++j) { Cell kv = result.getColumnLatestCell(CF_BYTES, getQualifier(j)); if (kv == null) { continue; } assertTrue(CellUtil.matchingValue(kv, getValue(batchId, i, j))); } } table.close(); }
private void assertEquals(Mutation origin, Mutation clone) { Assert.assertEquals(origin.getFamilyCellMap().size(), clone.getFamilyCellMap().size()); for (byte[] family : origin.getFamilyCellMap().keySet()) { List<Cell> originCells = origin.getCellList(family); List<Cell> cloneCells = clone.getCellList(family); Assert.assertEquals(originCells.size(), cloneCells.size()); for (int i = 0; i != cloneCells.size(); ++i) { Cell originCell = originCells.get(i); Cell cloneCell = cloneCells.get(i); assertTrue(CellUtil.equals(originCell, cloneCell)); assertTrue(CellUtil.matchingValue(originCell, cloneCell)); } } Assert.assertEquals(origin.getAttributesMap().size(), clone.getAttributesMap().size()); for (String name : origin.getAttributesMap().keySet()) { byte[] originValue = origin.getAttributesMap().get(name); byte[] cloneValue = clone.getAttributesMap().get(name); assertTrue(Bytes.equals(originValue, cloneValue)); } Assert.assertEquals(origin.getTimestamp(), clone.getTimestamp()); Assert.assertEquals(origin.getPriority(), clone.getPriority()); if (origin instanceof Append) { assertEquals(((Append)origin).getTimeRange(), ((Append)clone).getTimeRange()); } if (origin instanceof Increment) { assertEquals(((Increment)origin).getTimeRange(), ((Increment)clone).getTimeRange()); } }
assertTrue(CellUtil.matchingQualifier(bbCell1, q1)); assertTrue(CellUtil.matchingQualifier(bbCell2, q2)); assertTrue(CellUtil.matchingValue(bbCell1, bbCell2)); assertTrue(CellUtil.matchingValue(kv, bbCell2)); assertTrue(CellUtil.matchingValue(bbCell1, v)); assertFalse(CellUtil.matchingColumn(bbCell1, bbCell2)); assertTrue(CellUtil.matchingColumn(kv, bbCell2));
assertTrue(CellUtil.matchingValue(new KeyValue(row1, fam1, col1, value2), res.rawCells()[0])); assertEquals(ts + 3, res.rawCells()[0].getTimestamp()); assertTrue(CellUtil.matchingValue(new KeyValue(row1, fam1, col1, value2), res.rawCells()[0]));
keyOnlyByteBufferedCell)); assertTrue(CellUtil.matchingValue(KeyOnlyKeyValue, keyOnlyCell)); assertTrue(KeyOnlyKeyValue.getValueLength() == keyOnlyByteBufferedCell .getValueLength()); assertEquals(8 + keyLen + (lenAsVal ? 4 : 0), keyOnlyCell.getSerializedSize()); if (keyOnlyByteBufferedCell.getValueLength() > 0) { assertTrue(CellUtil.matchingValue(KeyOnlyKeyValue, keyOnlyByteBufferedCell));