Search code examples
hadoophbasehbasetestingutility

Test a Coprocessor within HBaseTestingUtility


I've made an HBase Endpoint Coprocessor, closely based on the example given here. I'd like to test it using the HBaseTestingUtility, but no suggestions for loading Coprocessors seem like they will work in this setup.

I start the cluster via:

HBaseTestingUtility hbaseUtility = new HBaseTestingUtility();
hbaseUtility.startMiniCluster();
hbaseUtility.createTable(TableName.valueOf("test"), "a");

Deployment suggestions online include:

  1. Placing the Coprocessor jar on the HDFS and using HBase shell.
  2. Adding a property to hbase-site.xml, placing the Coprocessor jar in the HBase lib dir, and restarting HBase.
  3. Placing the Coprocessor jar on the HDFS and using hTableDescriptor.addCoprocessor(...).

3. sounds like the only remotely feasible option, but I'd have to have the Coprocessor jar in a known location, and would have to set up a local HDFS cluster. I'd much prefer to be able to pull in the Coprocessor jar from my local Maven repo and deploy it from a local location.

Can anyone recommend the best way to test a Coprocessor using the HBaseTestingUtility?


Solution

  • HTableDescriptor has an addCoprocessor(String class) method, which will find the Coprocessor on the classpath. My test class now looks like:

    HBaseTestingUtility hbaseUtility = new HBaseTestingUtility();
    hbaseUtility.startMiniCluster();
    TableName table = TableName.valueOf("test");
    hbaseUtility.createTable(table , "a");
    hBaseAdmin.disableTable(table);
    HTableDescriptor hTableDescriptor = new HTableDescriptor(table);
    hTableDescriptor.addCoprocessor("uk.co.hadoopathome.hbase.coprocessor.SumEndpoint");
    HColumnDescriptor colFam = new HColumnDescriptor("a");
    hTableDescriptor.addFamily(colFam);
    hBaseAdmin.modifyTable(table, hTableDescriptor);
    hBaseAdmin.enableTable(table);
    

    where the SumEndpoint class is the class that implements Coprocessor.