Search in sources :

Example 26 with HBaseTableUtilFactory

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 });
    }
}
Also used : TableId(co.cask.cdap.data2.util.TableId) HBaseTableUtilFactory(co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory) HTable(org.apache.hadoop.hbase.client.HTable) Test(org.junit.Test)

Aggregations

HBaseTableUtilFactory (co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory)25 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)18 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)14 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)14 FileSystem (org.apache.hadoop.fs.FileSystem)7 Path (org.apache.hadoop.fs.Path)7 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)7 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)7 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)7 HRegionFileSystem (org.apache.hadoop.hbase.regionserver.HRegionFileSystem)7 HBaseDDLExecutorFactory (co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory)6 BeforeClass (org.junit.BeforeClass)6 WAL (org.apache.hadoop.hbase.wal.WAL)5 WALFactory (org.apache.hadoop.hbase.wal.WALFactory)5 LocationFactory (org.apache.twill.filesystem.LocationFactory)5 IOException (java.io.IOException)4 HTable (org.apache.hadoop.hbase.client.HTable)4 ConfigurationTable (co.cask.cdap.data2.util.hbase.ConfigurationTable)3 SimpleNamespaceQueryAdmin (co.cask.cdap.common.namespace.SimpleNamespaceQueryAdmin)2 TableId (co.cask.cdap.data2.util.TableId)2