use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestVisibilityLabels method testVisibilityLabelsOnKillingOfRSContainingLabelsTable.
@Test
public void testVisibilityLabelsOnKillingOfRSContainingLabelsTable() throws Exception {
List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
int liveRS = 0;
for (RegionServerThread rsThreads : regionServerThreads) {
if (!rsThreads.getRegionServer().isAborted()) {
liveRS++;
}
}
if (liveRS == 1) {
TEST_UTIL.getHBaseCluster().startRegionServer();
}
Thread t1 = new Thread() {
public void run() {
List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
for (RegionServerThread rsThread : regionServerThreads) {
List<Region> onlineRegions = rsThread.getRegionServer().getOnlineRegions(LABELS_TABLE_NAME);
if (onlineRegions.size() > 0) {
rsThread.getRegionServer().abort("Aborting ");
killedRS = true;
break;
}
}
}
};
t1.start();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Thread t = new Thread() {
public void run() {
try {
while (!killedRS) {
Thread.sleep(1);
}
createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL + ")", PRIVATE);
} catch (Exception e) {
}
}
};
t.start();
regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
while (!killedRS) {
Thread.sleep(10);
}
regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
for (RegionServerThread rsThread : regionServerThreads) {
while (true) {
if (!rsThread.getRegionServer().isAborted()) {
List<Region> onlineRegions = rsThread.getRegionServer().getOnlineRegions(LABELS_TABLE_NAME);
if (onlineRegions.size() > 0) {
break;
} else {
Thread.sleep(10);
}
} else {
break;
}
}
}
TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000);
t.join();
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET));
ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3);
assertTrue(next.length == 1);
}
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class ThriftHBaseServiceHandler method openScanner.
@Override
public int openScanner(ByteBuffer table, TScan scan) throws TIOError, TException {
Table htable = getTable(table);
ResultScanner resultScanner = null;
try {
resultScanner = htable.getScanner(scanFromThrift(scan));
} catch (IOException e) {
throw getTIOError(e);
} finally {
closeTable(htable);
}
return addScanner(resultScanner);
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class ThriftHBaseServiceHandler method getScannerResults.
@Override
public List<TResult> getScannerResults(ByteBuffer table, TScan scan, int numRows) throws TIOError, TException {
Table htable = getTable(table);
List<TResult> results = null;
ResultScanner scanner = null;
try {
scanner = htable.getScanner(scanFromThrift(scan));
results = resultsFromHBase(scanner.next(numRows));
} catch (IOException e) {
throw getTIOError(e);
} finally {
if (scanner != null) {
scanner.close();
}
closeTable(htable);
}
return results;
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class ThriftHBaseServiceHandler method getScannerRows.
@Override
public List<TResult> getScannerRows(int scannerId, int numRows) throws TIOError, TIllegalArgument, TException {
ResultScanner scanner = getScanner(scannerId);
if (scanner == null) {
TIllegalArgument ex = new TIllegalArgument();
ex.setMessage("Invalid scanner Id");
throw ex;
}
try {
connectionCache.updateConnectionAccessTime();
return resultsFromHBase(scanner.next(numRows));
} catch (IOException e) {
throw getTIOError(e);
}
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestHRegionOnCluster method putDataAndVerify.
private void putDataAndVerify(Table table, String row, byte[] family, String value, int verifyNum) throws IOException {
System.out.println("=========Putting data :" + row);
Put put = new Put(Bytes.toBytes(row));
put.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes(value));
table.put(put);
ResultScanner resultScanner = table.getScanner(new Scan());
List<Result> results = new ArrayList<>();
while (true) {
Result r = resultScanner.next();
if (r == null)
break;
results.add(r);
}
resultScanner.close();
if (results.size() != verifyNum) {
System.out.println(results);
}
assertEquals(verifyNum, results.size());
}
Aggregations