Tested on Hadoop 2.7.7 + HBase 2.0.5.
- Add following dependencies:
- org.apache.hbase:hbase-client:${hbase.version}
- org.apache.hbase:hbase-common:${hbase.version}
- org.apache.hbase:hbase-testing-util:test:${hbase.version}
- Use
HbaseTestUtil
to startup a mini cluster in setup/teardown of the suite.
@Before
public void setUp() {
HbaseTestUtil.startMiniCluster();
}
@After
public void tearDown() {
HbaseTestUtil.stopMiniCluster();
}
- Create Table and run a test.
HBaseTestingUtility utility = HbaseTestUtil.getUtility();
utility.createTable(TableName.valueOf(HBASE_TABLE), HBASE_COLUMN_FAMILY);
try (Connection connection = ConnectionFactory.createConnection(configuration);
Table table = connection.getTable(TableName.valueOf(tableName))) {
try {
Put put = new Put(Bytes.toBytes(key));
put.addImmutable(columnFamily.getBytes(), column.getBytes(), parsedValue.getBytes());
table.put(put);
} catch (IOException e) {
...
}
} catch (IOException e) {
...
}