RowResultAdapter implements RowAdapter<Result> { @Override public RowBuilder<Result> createRowBuilder() { return new RowResultBuilder(); }  @Override RowBuilder<Result> createRowBuilder(); @Override boolean isScanMarkerRow(Result result); @Override ByteString getKey(Result result);  }
@Test public void testWhenSplitCell() { ByteString valuePart1 = ByteString.copyFromUtf8("part-1"); ByteString valuePart2 = ByteString.copyFromUtf8("part-2"); ByteString valuePart3 = ByteString.copyFromUtf8("part-3"); RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder(); rowBuilder.startRow(ROW_KEY); rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 10000L, Collections.<String>emptyList(), 18); rowBuilder.cellValue(valuePart1); rowBuilder.cellValue(valuePart2); rowBuilder.cellValue(valuePart3); rowBuilder.finishCell(); Result actualResult = rowBuilder.finishRow(); assertArrayEquals( valuePart1.concat(valuePart2).concat(valuePart3).toByteArray(), actualResult.getValue(COL_FAMILY.getBytes(), QUAL_ONE.toByteArray())); }
@Test public void testWhenRowKeyIsNotSet() { RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder(); rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, LABELS, VALUE.size()); rowBuilder.cellValue(VALUE); try { rowBuilder.finishCell(); Assert.fail("should not accept null rowKey"); } catch (NullPointerException expected) { assertEquals("row key cannot be null", expected.getMessage()); } }
@Test public void testOnlyValueIsDifferent() { ByteString valuePart1 = ByteString.copyFromUtf8("part-1"); RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder(); rowBuilder.startRow(ROW_KEY); rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, LABELS, VALUE.size()); rowBuilder.cellValue(VALUE); rowBuilder.finishCell(); rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, LABELS, valuePart1.size()); rowBuilder.cellValue(valuePart1); rowBuilder.finishCell(); Result actual = rowBuilder.finishRow(); assertEquals(2, actual.size()); Result expected = Result.create( ImmutableList.<Cell>of( new RowCell( ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 30L, VALUE.toByteArray(), LABELS), new RowCell( ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 30L, valuePart1.toByteArray(), LABELS))); assertResult(expected, actual); }
@Test public void testDeduplicationLogic() { List<String> EMPTY_LABEL = ImmutableList.of(); ByteString valueForNewQual = ByteString.copyFromUtf8("value for new qualifier"); ByteString valueForCellWithoutLabel = ByteString.copyFromUtf8("value for Cell without label"); ByteString valueForCellWithLabel = ByteString.copyFromUtf8("value for cell with labels"); RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder(); rowBuilder.startRow(ROW_KEY); rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 20000L, EMPTY_LABEL, valueForNewQual.size()); rowBuilder.cellValue(valueForNewQual); rowBuilder.finishCell(); rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 20000L, EMPTY_LABEL, -1); rowBuilder.cellValue(valueForCellWithoutLabel); rowBuilder.finishCell(); rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 20000L, LABELS, -1); rowBuilder.cellValue(valueForCellWithLabel); rowBuilder.finishCell(); rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, EMPTY_LABEL, VALUE.size()); rowBuilder.cellValue(VALUE); rowBuilder.finishCell(); Result actual = rowBuilder.finishRow(); assertEquals(3, actual.size()); RowResult expected = RowResult.create( ROW_KEY, ImmutableList.<Cell>of( new RowCell( ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 20L, valueForNewQual.toByteArray(), EMPTY_LABEL), new RowCell( ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 20L, valueForCellWithLabel.toByteArray(), LABELS), new RowCell( ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 30L, VALUE.toByteArray(), EMPTY_LABEL))); assertResult(expected, actual); }
@Test public void testFamilyOrdering() { RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder(); rowBuilder.startRow(ROW_KEY); rowBuilder.startCell("cc", QUAL_ONE, 20000L, LABELS, -1); rowBuilder.cellValue(VALUE); rowBuilder.finishCell(); rowBuilder.startCell("bb", QUAL_TWO, 40000L, LABELS, VALUE.size() * 2); rowBuilder.cellValue(VALUE); rowBuilder.cellValue(VALUE); rowBuilder.finishCell(); rowBuilder.startCell("aa", QUAL_ONE, 20000L, LABELS, VALUE.size()); rowBuilder.cellValue(VALUE); rowBuilder.finishCell(); rowBuilder.startCell("zz", QUAL_ONE, 80000L, LABELS, VALUE.size()); rowBuilder.cellValue(VALUE); rowBuilder.finishCell(); rowBuilder.startCell("b", QUAL_ONE, 10000L, LABELS, VALUE.size()); rowBuilder.cellValue(VALUE); rowBuilder.finishCell(); Result actualResult = rowBuilder.finishRow(); List<String> colFamilyInActualOrder = new ArrayList<>(5); for (Cell cell : actualResult.listCells()) { colFamilyInActualOrder.add(Bytes.toString(CellUtil.cloneFamily(cell))); } assertEquals(ImmutableList.of("aa", "b", "bb", "cc", "zz"), colFamilyInActualOrder); }
@Test public void testReset() { RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder(); rowBuilder.startRow(ROW_KEY); rowBuilder.startCell( COL_FAMILY, QUAL_ONE, 10000L, Collections.<String>emptyList(), VALUE.size()); rowBuilder.cellValue(VALUE); rowBuilder.finishCell(); rowBuilder.reset(); ByteString anotherKey = ByteString.copyFromUtf8("another-rowKey"); rowBuilder.startRow(anotherKey); rowBuilder.startCell(COL_FAMILY, QUAL_TWO, 40000L, LABELS, VALUE.size()); rowBuilder.cellValue(VALUE); rowBuilder.finishCell(); Result actual = rowBuilder.finishRow(); assertResult( Result.create( ImmutableList.<Cell>of( new RowCell( anotherKey.toByteArray(), COL_FAMILY.getBytes(), QUAL_TWO.toByteArray(), 40L, VALUE.toByteArray()))), actual); }