use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.
the class TestThriftHBaseServiceHandler method testScanWithFilter.
@Test
public void testScanWithFilter() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
// insert data
TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(columnValue);
for (int i = 0; i < 10; i++) {
TPut put = new TPut(wrap(("testScanWithFilter" + i).getBytes()), columnValues);
handler.put(table, put);
}
// create scan instance with filter
TScan scan = new TScan();
List<TColumn> columns = new ArrayList<>(1);
TColumn column = new TColumn();
column.setFamily(familyAname);
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testScanWithFilter".getBytes());
scan.setStopRow("testScanWithFilterï¿¿".getBytes());
// only get the key part
scan.setFilterString(wrap(("KeyOnlyFilter()").getBytes()));
// get scanner and rows
int scanId = handler.openScanner(table, scan);
List<TResult> results = handler.getScannerRows(scanId, 10);
assertEquals(10, results.size());
for (int i = 0; i < 10; i++) {
// check if the rows are returned and in order
assertArrayEquals(("testScanWithFilter" + i).getBytes(), results.get(i).getRow());
// check that the value is indeed stripped by the filter
assertEquals(0, results.get(i).getColumnValues().get(0).getValue().length);
}
// check that we are at the end of the scan
results = handler.getScannerRows(scanId, 10);
assertEquals(0, results.size());
// close scanner and check that it was indeed closed
handler.closeScanner(scanId);
try {
handler.getScannerRows(scanId, 10);
fail("Scanner id should be invalid");
} catch (TIllegalArgument e) {
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.
the class TestThriftHBaseServiceHandler method testIncrement.
@Test
public void testIncrement() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testIncrement".getBytes();
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(Bytes.toBytes(1L))));
TPut put = new TPut(wrap(rowName), columnValues);
put.setColumnValues(columnValues);
handler.put(table, put);
List<TColumnIncrement> incrementColumns = new ArrayList<>(1);
incrementColumns.add(new TColumnIncrement(wrap(familyAname), wrap(qualifierAname)));
TIncrement increment = new TIncrement(wrap(rowName), incrementColumns);
handler.increment(table, increment);
TGet get = new TGet(wrap(rowName));
TResult result = handler.get(table, get);
assertArrayEquals(rowName, result.getRow());
assertEquals(1, result.getColumnValuesSize());
TColumnValue columnValue = result.getColumnValues().get(0);
assertArrayEquals(Bytes.toBytes(2L), columnValue.getValue());
}
use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.
the class TestThriftHBaseServiceHandler method testDeleteSingleTimestamp.
@Test
public void testDeleteSingleTimestamp() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testDeleteSingleTimestamp".getBytes();
ByteBuffer table = wrap(tableAname);
long timestamp1 = System.currentTimeMillis() - 10;
long timestamp2 = System.currentTimeMillis();
List<TColumnValue> columnValues = new ArrayList<>(1);
TColumnValue columnValueA = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
columnValueA.setTimestamp(timestamp1);
columnValues.add(columnValueA);
TPut put = new TPut(wrap(rowName), columnValues);
put.setColumnValues(columnValues);
handler.put(table, put);
columnValueA.setTimestamp(timestamp2);
handler.put(table, put);
TGet get = new TGet(wrap(rowName));
get.setMaxVersions(2);
TResult result = handler.get(table, get);
assertEquals(2, result.getColumnValuesSize());
TDelete delete = new TDelete(wrap(rowName));
List<TColumn> deleteColumns = new ArrayList<>(1);
TColumn deleteColumn = new TColumn(wrap(familyAname));
deleteColumn.setQualifier(qualifierAname);
deleteColumns.add(deleteColumn);
delete.setColumns(deleteColumns);
delete.setDeleteType(TDeleteType.DELETE_COLUMN);
handler.deleteSingle(table, delete);
get = new TGet(wrap(rowName));
result = handler.get(table, get);
assertArrayEquals(rowName, result.getRow());
assertEquals(1, result.getColumnValuesSize());
// the older timestamp should remain.
assertEquals(timestamp1, result.getColumnValues().get(0).getTimestamp());
}
use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.
the class TestThriftHBaseServiceHandler method testMetricsWithException.
@Test
public void testMetricsWithException() throws Exception {
byte[] rowkey = Bytes.toBytes("row1");
byte[] family = Bytes.toBytes("f");
byte[] col = Bytes.toBytes("c");
// create a table which will throw exceptions for requests
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);
table.put(new Put(rowkey).addColumn(family, col, Bytes.toBytes("val1")));
ThriftHBaseServiceHandler hbaseHandler = createHandler();
ThriftMetrics metrics = getMetrics(UTIL.getConfiguration());
THBaseService.Iface handler = ThriftHBaseServiceHandler.newInstance(hbaseHandler, metrics);
ByteBuffer tTableName = wrap(tableName.getName());
// check metrics increment with a successful get
long preGetCounter = metricsHelper.checkCounterExists("get_num_ops", metrics.getSource()) ? metricsHelper.getCounter("get_num_ops", metrics.getSource()) : 0;
TGet tGet = new TGet(wrap(rowkey));
TResult tResult = handler.get(tTableName, tGet);
List<TColumnValue> expectedColumnValues = Lists.newArrayList(new TColumnValue(wrap(family), wrap(col), wrap(Bytes.toBytes("val1"))));
assertArrayEquals(rowkey, tResult.getRow());
List<TColumnValue> returnedColumnValues = tResult.getColumnValues();
assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues);
metricsHelper.assertCounter("get_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);
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.
the class TestThriftHBaseServiceHandlerWithLabels method testIncrementWithTagsWithNotMatchLabels.
@Test
public void testIncrementWithTagsWithNotMatchLabels() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = "testIncrementWithTagsWithNotMatchLabels".getBytes();
ByteBuffer table = wrap(tableAname);
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(Bytes.toBytes(1L))));
TPut put = new TPut(wrap(rowName), columnValues);
put.setColumnValues(columnValues);
put.setCellVisibility(new TCellVisibility().setExpression(PRIVATE));
handler.put(table, put);
List<TColumnIncrement> incrementColumns = new ArrayList<>(1);
incrementColumns.add(new TColumnIncrement(wrap(familyAname), wrap(qualifierAname)));
TIncrement increment = new TIncrement(wrap(rowName), incrementColumns);
increment.setCellVisibility(new TCellVisibility().setExpression(SECRET));
handler.increment(table, increment);
TGet get = new TGet(wrap(rowName));
TAuthorization tauth = new TAuthorization();
List<String> labels = new ArrayList<>(1);
labels.add(PUBLIC);
tauth.setLabels(labels);
get.setAuthorizations(tauth);
TResult result = handler.get(table, get);
assertNull(result.getRow());
}
Aggregations