use of org.apache.hadoop.hbase.client.RowMutations in project hbase by apache.
the class TestHRegion method testMutateRow.
@Test
public void testMutateRow() throws Exception {
final byte[] row = Bytes.toBytes("row");
final byte[] q1 = Bytes.toBytes("q1");
final byte[] q2 = Bytes.toBytes("q2");
final byte[] q3 = Bytes.toBytes("q3");
final byte[] q4 = Bytes.toBytes("q4");
final String v1 = "v1";
region = initHRegion(tableName, method, CONF, fam1);
// Initial values
region.batchMutate(new Mutation[] { new Put(row).addColumn(fam1, q2, Bytes.toBytes("toBeDeleted")), new Put(row).addColumn(fam1, q3, Bytes.toBytes(5L)), new Put(row).addColumn(fam1, q4, Bytes.toBytes("a")) });
// Do mutateRow
Result result = region.mutateRow(new RowMutations(row).add(Arrays.asList(new Put(row).addColumn(fam1, q1, Bytes.toBytes(v1)), new Delete(row).addColumns(fam1, q2), new Increment(row).addColumn(fam1, q3, 1), new Append(row).addColumn(fam1, q4, Bytes.toBytes("b")))));
assertNotNull(result);
assertEquals(6L, Bytes.toLong(result.getValue(fam1, q3)));
assertEquals("ab", Bytes.toString(result.getValue(fam1, q4)));
// Verify the value
result = region.get(new Get(row));
assertEquals(v1, Bytes.toString(result.getValue(fam1, q1)));
assertNull(result.getValue(fam1, q2));
assertEquals(6L, Bytes.toLong(result.getValue(fam1, q3)));
assertEquals("ab", Bytes.toString(result.getValue(fam1, q4)));
}
Aggregations