/** * Needed doing 'contains' on List. Only compares the key portion, not the value. */ @Override public boolean equals(Object other) { if (!(other instanceof Cell)) { return false; } return CellUtil.equals(this, (Cell) other); }
/** * Needed doing 'contains' on List. Only compares the key portion, not the value. */ @Override public boolean equals(Object other) { if (!(other instanceof Cell)) { return false; } return CellUtil.equals(this, (Cell)other); }
/** Check a key/value pair after it was read by the reader */ private void checkCell(Cell expected, Cell actual) { assertTrue(String.format("Expected key %s, but was %s", CellUtil.getCellKeyAsString(expected), CellUtil.getCellKeyAsString(actual)), CellUtil.equals(expected, actual)); } }
@Test public void testWriteCell() throws IOException { byte[] r = Bytes.toBytes("row1"); byte[] f = Bytes.toBytes("cf1"); byte[] q1 = Bytes.toBytes("qual1"); byte[] q2 = Bytes.toBytes("qual2"); byte[] v = Bytes.toBytes("val1"); byte[] tags = Bytes.toBytes("tag1"); KeyValue kv = new KeyValue(r, f, q1, 0, q1.length, 1234L, KeyValue.Type.Put, v, 0, v.length, tags); NonExtendedCell nonExtCell = new NonExtendedCell(kv); ByteArrayOutputStream os = new ByteArrayOutputStream(); int writeCell = PrivateCellUtil.writeCell(nonExtCell, os, true); byte[] byteArray = os.toByteArray(); KeyValue res = new KeyValue(byteArray); assertTrue(CellUtil.equals(kv, res)); }
Iterator<Cell> includeIter = includeTail.iterator(); for (int j = 1 + i; j != ascCells.length; ++j) { assertEquals(true, CellUtil.equals(excludeIter.next(), ascCells[j])); assertEquals(true, CellUtil.equals(includeIter.next(), ascCells[j])); Iterator<Cell> includeIter = includeHead.iterator(); for (int j = 0; j != i; ++j) { assertEquals(true, CellUtil.equals(excludeIter.next(), ascCells[j])); assertEquals(true, CellUtil.equals(includeIter.next(), ascCells[j])); Iterator<Cell> iter = sub.values().iterator(); for (int i = 0; i != ascCells.length; ++i) { assertEquals(true, CellUtil.equals(iter.next(), ascCells[i]));
assertTrue(decoder.advance()); Cell c = decoder.current(); assertTrue(CellUtil.equals(c, kv1)); assertTrue(decoder.advance()); c = decoder.current(); assertTrue(CellUtil.equals(c, kv2)); assertTrue(decoder.advance()); c = decoder.current(); assertTrue(CellUtil.equals(c, kv3)); assertFalse(decoder.advance()); dis.close();
assertTrue(decoder.advance()); Cell c = decoder.current(); assertTrue(CellUtil.equals(c, kv1)); assertTrue(decoder.advance()); c = decoder.current(); assertTrue(CellUtil.equals(c, kv2)); assertTrue(decoder.advance()); c = decoder.current(); assertTrue(CellUtil.equals(c, kv3)); assertFalse(decoder.advance()); dis.close();
/** * Basic test to verify utility methods in {@link PBType} and delegation to protobuf works. */ @Test public void testRoundTrip() { final Cell cell = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual"), Bytes.toBytes("val")); CellProtos.Cell c = ProtobufUtil.toCell(cell), decoded; PositionedByteRange pbr = new SimplePositionedByteRange(c.getSerializedSize()); pbr.setPosition(0); int encodedLength = CODEC.encode(pbr, c); pbr.setPosition(0); decoded = CODEC.decode(pbr); assertEquals(encodedLength, pbr.getPosition()); assertTrue(CellUtil.equals(cell, ProtobufUtil .toCell(ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY), decoded))); } }
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(decoder.advance()); Cell c = decoder.current(); assertTrue(CellUtil.equals(c, kv1)); List<Tag> tags = PrivateCellUtil.getTags(c); assertTrue(decoder.advance()); c = decoder.current(); assertTrue(CellUtil.equals(c, kv2)); tags = PrivateCellUtil.getTags(c); assertEquals(1, tags.size()); assertTrue(decoder.advance()); c = decoder.current(); assertTrue(CellUtil.equals(c, kv3)); tags = PrivateCellUtil.getTags(c); assertEquals(3, tags.size());
assertTrue(decoder.advance()); Cell c = decoder.current(); assertTrue(CellUtil.equals(c, cell1)); List<Tag> tags = PrivateCellUtil.getTags(c); assertTrue(decoder.advance()); c = decoder.current(); assertTrue(CellUtil.equals(c, cell2)); tags = PrivateCellUtil.getTags(c); assertEquals(1, tags.size()); assertTrue(decoder.advance()); c = decoder.current(); assertTrue(CellUtil.equals(c, cell3)); tags = PrivateCellUtil.getTags(c); assertEquals(3, tags.size());
private void checkSeekingConsistency(List<DataBlockEncoder.EncodedSeeker> encodedSeekers, boolean seekBefore, Cell keyValue) { Cell expectedKeyValue = null; ByteBuffer expectedKey = null; ByteBuffer expectedValue = null; for (DataBlockEncoder.EncodedSeeker seeker : encodedSeekers) { seeker.seekToKeyInBlock(keyValue, seekBefore); seeker.rewind(); Cell actualKeyValue = seeker.getCell(); ByteBuffer actualKey = null; actualKey = ByteBuffer.wrap(((KeyValue) seeker.getKey()).getKey()); ByteBuffer actualValue = seeker.getValueShallowCopy(); if (expectedKeyValue != null) { assertTrue(CellUtil.equals(expectedKeyValue, actualKeyValue)); } else { expectedKeyValue = actualKeyValue; } if (expectedKey != null) { assertEquals(expectedKey, actualKey); } else { expectedKey = actualKey; } if (expectedValue != null) { assertEquals(expectedValue, actualValue); } else { expectedValue = actualValue; } } }
Decoder decoder = codec.getDecoder(is); assertTrue(decoder.advance()); assertTrue(CellUtil.equals(c1, decoder.current())); assertTrue(decoder.advance()); assertTrue(CellUtil.equals(c2, decoder.current())); assertTrue(decoder.advance()); assertTrue(CellUtil.equals(c3, decoder.current())); assertFalse(decoder.advance());
@Test public void testCompareCells() { KeyValue kv1 = new KeyValue(row1, fam1, qual1, val); KeyValue kv2 = new KeyValue(row2, fam1, qual1, val); assertTrue((comparator.compare(kv1, kv2)) < 0); kv1 = new KeyValue(row1, fam2, qual1, val); kv2 = new KeyValue(row1, fam1, qual1, val); assertTrue((comparator.compareFamilies(kv1, kv2) > 0)); kv1 = new KeyValue(row1, fam1, qual1, 1L, val); kv2 = new KeyValue(row1, fam1, qual1, 2L, val); assertTrue((comparator.compare(kv1, kv2) > 0)); kv1 = new KeyValue(row1, fam1, qual1, 1L, Type.Put); kv2 = new KeyValue(row1, fam1, qual1, 1L, Type.Maximum); assertTrue((comparator.compare(kv1, kv2) > 0)); kv1 = new KeyValue(row1, fam1, qual1, 1L, Type.Put); kv2 = new KeyValue(row1, fam1, qual1, 1L, Type.Put); assertTrue((CellUtil.equals(kv1, kv2))); }
/** * Needed doing 'contains' on List. Only compares the key portion, not the value. */ @Override public boolean equals(Object other) { if (!(other instanceof Cell)) { return false; } return CellUtil.equals(this, (Cell)other); }
/** * Needed doing 'contains' on List. Only compares the key portion, not the value. */ @Override public boolean equals(Object other) { if (!(other instanceof Cell)) { return false; } return CellUtil.equals(this, (Cell)other); }
/** * Needed doing 'contains' on List. Only compares the key portion, not the value. */ @Override public boolean equals(Object other) { if (!(other instanceof Cell)) { return false; } return CellUtil.equals(this, (Cell) other); }
/** * Needed doing 'contains' on List. Only compares the key portion, not the value. */ @Override public boolean equals(Object other) { if (!(other instanceof Cell)) { return false; } return CellUtil.equals(this, (Cell) other); }
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()); } }
/** Check a key/value pair after it was read by the reader */ private void checkCell(Cell expected, Cell actual) { assertTrue(String.format("Expected key %s, but was %s", CellUtil.getCellKeyAsString(expected), CellUtil.getCellKeyAsString(actual)), CellUtil.equals(expected, actual)); } }