Search in sources :

Example 1 with HBaseHandler

use of org.apache.hadoop.hbase.thrift.ThriftServerRunner.HBaseHandler in project hbase by apache.

the class TestThriftServer method testMetricsWithException.

@Test
public void testMetricsWithException() throws Exception {
    String rowkey = "row1";
    String family = "f";
    String col = "c";
    // create a table which will throw exceptions for requests
    final TableName tableName = TableName.valueOf(name.getMethodName());
    HTableDescriptor tableDesc = new HTableDescriptor(tableName);
    tableDesc.addCoprocessor(ErrorThrowingGetObserver.class.getName());
    tableDesc.addFamily(new HColumnDescriptor(family));
    Table table = UTIL.createTable(tableDesc, null);
    long now = System.currentTimeMillis();
    table.put(new Put(Bytes.toBytes(rowkey)).addColumn(Bytes.toBytes(family), Bytes.toBytes(col), now, Bytes.toBytes("val1")));
    Configuration conf = UTIL.getConfiguration();
    ThriftMetrics metrics = getMetrics(conf);
    ThriftServerRunner.HBaseHandler hbaseHandler = new ThriftServerRunner.HBaseHandler(UTIL.getConfiguration(), UserProvider.instantiate(UTIL.getConfiguration()));
    Hbase.Iface handler = HbaseHandlerMetricsProxy.newInstance(hbaseHandler, metrics, conf);
    ByteBuffer tTableName = asByteBuffer(tableName.getNameAsString());
    // check metrics increment with a successful get
    long preGetCounter = metricsHelper.checkCounterExists("getRow_num_ops", metrics.getSource()) ? metricsHelper.getCounter("getRow_num_ops", metrics.getSource()) : 0;
    List<TRowResult> tRowResult = handler.getRow(tTableName, asByteBuffer(rowkey), null);
    assertEquals(1, tRowResult.size());
    TRowResult tResult = tRowResult.get(0);
    TCell expectedColumnValue = new TCell(asByteBuffer("val1"), now);
    assertArrayEquals(Bytes.toBytes(rowkey), tResult.getRow());
    Collection<TCell> returnedColumnValues = tResult.getColumns().values();
    assertEquals(1, returnedColumnValues.size());
    assertEquals(expectedColumnValue, returnedColumnValues.iterator().next());
    metricsHelper.assertCounter("getRow_num_ops", preGetCounter + 1, metrics.getSource());
    // check metrics increment when the get throws each exception type
    for (ErrorThrowingGetObserver.ErrorType type : ErrorThrowingGetObserver.ErrorType.values()) {
        testExceptionType(handler, metrics, tTableName, rowkey, type);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Configuration(org.apache.hadoop.conf.Configuration) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HBaseHandler(org.apache.hadoop.hbase.thrift.ThriftServerRunner.HBaseHandler) TCell(org.apache.hadoop.hbase.thrift.generated.TCell) ByteBuffer(java.nio.ByteBuffer) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TableName(org.apache.hadoop.hbase.TableName) HBaseHandler(org.apache.hadoop.hbase.thrift.ThriftServerRunner.HBaseHandler) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 Configuration (org.apache.hadoop.conf.Configuration)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 TableName (org.apache.hadoop.hbase.TableName)1 Put (org.apache.hadoop.hbase.client.Put)1 Table (org.apache.hadoop.hbase.client.Table)1 HBaseHandler (org.apache.hadoop.hbase.thrift.ThriftServerRunner.HBaseHandler)1 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)1 TCell (org.apache.hadoop.hbase.thrift.generated.TCell)1 TRowResult (org.apache.hadoop.hbase.thrift.generated.TRowResult)1 Test (org.junit.Test)1