use of org.apache.hadoop.hbase.thrift2.generated.TColumn in project hbase by apache.
the class TestThriftHBaseServiceHandlerWithLabels method testScanWithVisibilityLabels.
@Test
public void testScanWithVisibilityLabels() 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(Bytes.toBytes("testScan" + i)), columnValues);
if (i == 5) {
put.setCellVisibility(new TCellVisibility().setExpression(PUBLIC));
} else {
put.setCellVisibility(new TCellVisibility().setExpression("(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET));
}
handler.put(table, put);
}
// create scan instance
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(Bytes.toBytes("testScan"));
scan.setStopRow(Bytes.toBytes("testScan\uffff"));
TAuthorization tauth = new TAuthorization();
List<String> labels = new ArrayList<>(2);
labels.add(SECRET);
labels.add(PRIVATE);
tauth.setLabels(labels);
scan.setAuthorizations(tauth);
// get scanner and rows
int scanId = handler.openScanner(table, scan);
List<TResult> results = handler.getScannerRows(scanId, 10);
assertEquals(9, results.size());
Assert.assertFalse(Bytes.equals(results.get(5).getRow(), Bytes.toBytes("testScan" + 5)));
for (int i = 0; i < 9; i++) {
if (i < 5) {
assertArrayEquals(Bytes.toBytes("testScan" + i), results.get(i).getRow());
} else if (i == 5) {
continue;
} else {
assertArrayEquals(Bytes.toBytes("testScan" + (i + 1)), results.get(i).getRow());
}
}
// check that we are at the end of the scan
results = handler.getScannerRows(scanId, 9);
assertEquals(0, results.size());
// close scanner and check that it was indeed closed
handler.closeScanner(scanId);
try {
handler.getScannerRows(scanId, 9);
fail("Scanner id should be invalid");
} catch (TIllegalArgument e) {
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TColumn in project hbase by apache.
the class TestThriftHBaseServiceHandlerWithLabels method testGetScannerResultsWithAuthorizations.
@Test
public void testGetScannerResultsWithAuthorizations() 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 < 20; i++) {
TPut put = new TPut(wrap(Bytes.toBytes("testGetScannerResults" + pad(i, (byte) 2))), columnValues);
if (i == 3) {
put.setCellVisibility(new TCellVisibility().setExpression(PUBLIC));
} else {
put.setCellVisibility(new TCellVisibility().setExpression("(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET));
}
handler.put(table, put);
}
// create scan instance
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(Bytes.toBytes("testGetScannerResults"));
// get 5 rows and check the returned results
scan.setStopRow(Bytes.toBytes("testGetScannerResults05"));
TAuthorization tauth = new TAuthorization();
List<String> labels = new ArrayList<>(2);
labels.add(SECRET);
labels.add(PRIVATE);
tauth.setLabels(labels);
scan.setAuthorizations(tauth);
List<TResult> results = handler.getScannerResults(table, scan, 5);
assertEquals(4, results.size());
for (int i = 0; i < 4; i++) {
if (i < 3) {
assertArrayEquals(Bytes.toBytes("testGetScannerResults" + pad(i, (byte) 2)), results.get(i).getRow());
} else if (i == 3) {
continue;
} else {
assertArrayEquals(Bytes.toBytes("testGetScannerResults" + pad(i + 1, (byte) 2)), results.get(i).getRow());
}
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TColumn in project hbase by apache.
the class TestThriftHBaseServiceHandler method testLongLivedScan.
/**
* Tests keeping a HBase scanner alive for long periods of time. Each call to getScannerRow()
* should reset the ConnectionCache timeout for the scanner's connection.
*/
// Flakey. Diasabled by HBASE-24079. Renable with Fails with HBASE-24083.
@org.junit.Ignore
// Flakey. Diasabled by HBASE-24079. Renable with Fails with HBASE-24083.
@Test
public // testLongLivedScan(TestThriftHBaseServiceHandler.java:804)
void testLongLivedScan() throws Exception {
int numTrials = 6;
int trialPause = 1000;
int cleanUpInterval = 100;
Configuration conf = new Configuration(UTIL.getConfiguration());
// Set the ConnectionCache timeout to trigger halfway through the trials
conf.setInt(MAX_IDLETIME, (numTrials / 2) * trialPause);
conf.setInt(CLEANUP_INTERVAL, cleanUpInterval);
ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(conf, UserProvider.instantiate(conf));
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 < numTrials; i++) {
TPut put = new TPut(wrap(Bytes.toBytes("testScan" + i)), columnValues);
handler.put(table, put);
}
// create scan instance
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(Bytes.toBytes("testScan"));
scan.setStopRow(Bytes.toBytes("testScan\uffff"));
// Prevent the scanner from caching results
scan.setCaching(1);
// get scanner and rows
int scanId = handler.openScanner(table, scan);
for (int i = 0; i < numTrials; i++) {
// Make sure that the Scanner doesn't throw an exception after the ConnectionCache timeout
List<TResult> results = handler.getScannerRows(scanId, 1);
assertArrayEquals(Bytes.toBytes("testScan" + i), results.get(0).getRow());
Thread.sleep(trialPause);
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TColumn in project hbase by apache.
the class TestThriftHBaseServiceHandler method testDeleteFamilyVersion.
@Test
public void testDeleteFamilyVersion() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = Bytes.toBytes("testDeleteFamilyVersion");
ByteBuffer table = wrap(tableAname);
long timestamp1 = EnvironmentEdgeManager.currentTime() - 10;
long timestamp2 = EnvironmentEdgeManager.currentTime();
List<TColumnValue> columnValues = new ArrayList<>();
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<>();
TColumn deleteColumn = new TColumn(wrap(familyAname));
deleteColumn.setTimestamp(timestamp1);
deleteColumns.add(deleteColumn);
delete.setColumns(deleteColumns);
delete.setDeleteType(TDeleteType.DELETE_FAMILY_VERSION);
handler.deleteSingle(table, delete);
get = new TGet(wrap(rowName));
result = handler.get(table, get);
assertArrayEquals(rowName, result.getRow());
assertEquals(1, result.getColumnValuesSize());
assertEquals(timestamp2, result.getColumnValues().get(0).getTimestamp());
}
use of org.apache.hadoop.hbase.thrift2.generated.TColumn in project hbase by apache.
the class TestThriftHBaseServiceHandler method testReverseScan.
@Test
public void testReverseScan() 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(Bytes.toBytes("testReverseScan" + i)), columnValues);
handler.put(table, put);
}
// create reverse scan instance
TScan scan = new TScan();
scan.setReversed(true);
List<TColumn> columns = new ArrayList<>(1);
TColumn column = new TColumn();
column.setFamily(familyAname);
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow(Bytes.toBytes("testReverseScan\uffff"));
scan.setStopRow(Bytes.toBytes("testReverseScan"));
// 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(Bytes.toBytes("testReverseScan" + (9 - i)), results.get(i).getRow());
}
// 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) {
}
}
Aggregations