use of co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.
the class AbstractIncrementHandlerTest method testIncrements.
@Test
public void testIncrements() throws Exception {
TableId tableId = TableId.from(NamespaceId.DEFAULT.getEntityName(), "incrementTest");
createTable(tableId);
try (HTable table = new HBaseTableUtilFactory(cConf).get().createHTable(conf, tableId)) {
byte[] colA = Bytes.toBytes("a");
byte[] row1 = Bytes.toBytes("row1");
// test column containing only increments
table.put(newIncrement(row1, colA, 1));
table.put(newIncrement(row1, colA, 1));
table.put(newIncrement(row1, colA, 1));
assertColumn(table, row1, colA, 3);
// test intermixed increments and puts
table.put(tableUtil.buildPut(row1).add(FAMILY, colA, ts++, Bytes.toBytes(5L)).build());
assertColumn(table, row1, colA, 5);
table.put(newIncrement(row1, colA, 1));
table.put(newIncrement(row1, colA, 1));
assertColumn(table, row1, colA, 7);
// test multiple increment columns
byte[] row2 = Bytes.toBytes("row2");
byte[] colB = Bytes.toBytes("b");
// increment A and B twice at the same timestamp
table.put(newIncrement(row2, colA, 1, 1));
table.put(newIncrement(row2, colB, 1, 1));
table.put(newIncrement(row2, colA, 2, 1));
table.put(newIncrement(row2, colB, 2, 1));
// increment A once more
table.put(newIncrement(row2, colA, 1));
assertColumns(table, row2, new byte[][] { colA, colB }, new long[] { 3, 2 });
// overwrite B with a new put
table.put(tableUtil.buildPut(row2).add(FAMILY, colB, ts++, Bytes.toBytes(10L)).build());
assertColumns(table, row2, new byte[][] { colA, colB }, new long[] { 3, 10 });
}
}
Aggregations