use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestSyncTable method assertEqualTables.
private void assertEqualTables(int expectedRows, TableName sourceTableName, TableName targetTableName) throws Exception {
Table sourceTable = TEST_UTIL.getConnection().getTable(sourceTableName);
Table targetTable = TEST_UTIL.getConnection().getTable(targetTableName);
ResultScanner sourceScanner = sourceTable.getScanner(new Scan());
ResultScanner targetScanner = targetTable.getScanner(new Scan());
for (int i = 0; i < expectedRows; i++) {
Result sourceRow = sourceScanner.next();
Result targetRow = targetScanner.next();
LOG.debug("SOURCE row: " + (sourceRow == null ? "null" : Bytes.toInt(sourceRow.getRow())) + " cells:" + sourceRow);
LOG.debug("TARGET row: " + (targetRow == null ? "null" : Bytes.toInt(targetRow.getRow())) + " cells:" + targetRow);
if (sourceRow == null) {
Assert.fail("Expected " + expectedRows + " source rows but only found " + i);
}
if (targetRow == null) {
Assert.fail("Expected " + expectedRows + " target rows but only found " + i);
}
Cell[] sourceCells = sourceRow.rawCells();
Cell[] targetCells = targetRow.rawCells();
if (sourceCells.length != targetCells.length) {
LOG.debug("Source cells: " + Arrays.toString(sourceCells));
LOG.debug("Target cells: " + Arrays.toString(targetCells));
Assert.fail("Row " + Bytes.toInt(sourceRow.getRow()) + " has " + sourceCells.length + " cells in source table but " + targetCells.length + " cells in target table");
}
for (int j = 0; j < sourceCells.length; j++) {
Cell sourceCell = sourceCells[j];
Cell targetCell = targetCells[j];
try {
if (!CellUtil.matchingRow(sourceCell, targetCell)) {
Assert.fail("Rows don't match");
}
if (!CellUtil.matchingFamily(sourceCell, targetCell)) {
Assert.fail("Families don't match");
}
if (!CellUtil.matchingQualifier(sourceCell, targetCell)) {
Assert.fail("Qualifiers don't match");
}
if (!CellUtil.matchingTimestamp(sourceCell, targetCell)) {
Assert.fail("Timestamps don't match");
}
if (!CellUtil.matchingValue(sourceCell, targetCell)) {
Assert.fail("Values don't match");
}
} catch (Throwable t) {
LOG.debug("Source cell: " + sourceCell + " target cell: " + targetCell);
Throwables.propagate(t);
}
}
}
Result sourceRow = sourceScanner.next();
if (sourceRow != null) {
Assert.fail("Source table has more than " + expectedRows + " rows. Next row: " + Bytes.toInt(sourceRow.getRow()));
}
Result targetRow = targetScanner.next();
if (targetRow != null) {
Assert.fail("Target table has more than " + expectedRows + " rows. Next row: " + Bytes.toInt(targetRow.getRow()));
}
sourceScanner.close();
targetScanner.close();
sourceTable.close();
targetTable.close();
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestTableInputFormat method createIOEScannerTable.
/**
* Create a table that IOE's on first scanner next call
*
* @throws IOException
*/
static Table createIOEScannerTable(byte[] name, final int failCnt) throws IOException {
// build up a mock scanner stuff to fail the first time
Answer<ResultScanner> a = new Answer<ResultScanner>() {
int cnt = 0;
@Override
public ResultScanner answer(InvocationOnMock invocation) throws Throwable {
// first invocation return the busted mock scanner
if (cnt++ < failCnt) {
// create mock ResultScanner that always fails.
Scan scan = mock(Scan.class);
// avoid npe
doReturn("bogus".getBytes()).when(scan).getStartRow();
ResultScanner scanner = mock(ResultScanner.class);
// simulate TimeoutException / IOException
doThrow(new IOException("Injected exception")).when(scanner).next();
return scanner;
}
// otherwise return the real scanner.
return (ResultScanner) invocation.callRealMethod();
}
};
Table htable = spy(createTable(name));
doAnswer(a).when(htable).getScanner((Scan) anyObject());
return htable;
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class MobTestUtil method assertCellsValue.
public static void assertCellsValue(Table table, Scan scan, byte[] expectedValue, int expectedCount) throws IOException {
ResultScanner results = table.getScanner(scan);
int count = 0;
for (Result res : results) {
List<Cell> cells = res.listCells();
for (Cell cell : cells) {
// Verify the value
Assert.assertArrayEquals(expectedValue, CellUtil.cloneValue(cell));
count++;
}
}
results.close();
Assert.assertEquals(expectedCount, count);
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestVisibilityLabels method testVisibilityLabelsOnRSRestart.
@Test(timeout = 60 * 1000)
public void testVisibilityLabelsOnRSRestart() throws Exception {
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
for (RegionServerThread rsThread : regionServerThreads) {
rsThread.getRegionServer().abort("Aborting ");
}
// Start one new RS
RegionServerThread rs = TEST_UTIL.getHBaseCluster().startRegionServer();
waitForLabelsRegionAvailability(rs.getRegionServer());
try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL + ")", PRIVATE)) {
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 TestVisibilityLabels method testClearUserAuths.
@Test
public void testClearUserAuths() throws Throwable {
PrivilegedExceptionAction<Void> action = new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
String[] auths = { SECRET, CONFIDENTIAL, PRIVATE };
String user = "testUser";
try (Connection conn = ConnectionFactory.createConnection(conf)) {
VisibilityClient.setAuths(conn, auths, user);
} catch (Throwable e) {
fail("Should not have failed");
}
// Removing the auths for SECRET and CONFIDENTIAL for the user.
// Passing a non existing auth also.
auths = new String[] { SECRET, PUBLIC, CONFIDENTIAL };
VisibilityLabelsResponse response = null;
try (Connection conn = ConnectionFactory.createConnection(conf)) {
response = VisibilityClient.clearAuths(conn, auths, user);
} catch (Throwable e) {
fail("Should not have failed");
}
List<RegionActionResult> resultList = response.getResultList();
assertEquals(3, resultList.size());
assertTrue(resultList.get(0).getException().getValue().isEmpty());
assertEquals("org.apache.hadoop.hbase.DoNotRetryIOException", resultList.get(1).getException().getName());
assertTrue(Bytes.toString(resultList.get(1).getException().getValue().toByteArray()).contains("org.apache.hadoop.hbase.security.visibility.InvalidLabelException: " + "Label 'public' is not set for the user testUser"));
assertTrue(resultList.get(2).getException().getValue().isEmpty());
try (Connection connection = ConnectionFactory.createConnection(conf);
Table ht = connection.getTable(LABELS_TABLE_NAME)) {
ResultScanner scanner = ht.getScanner(new Scan());
Result result = null;
List<Result> results = new ArrayList<>();
while ((result = scanner.next()) != null) {
results.add(result);
}
List<String> curAuths = extractAuths(user, results);
assertTrue(curAuths.contains(PRIVATE));
assertEquals(1, curAuths.size());
}
GetAuthsResponse authsResponse = null;
try (Connection conn = ConnectionFactory.createConnection(conf)) {
authsResponse = VisibilityClient.getAuths(conn, user);
} catch (Throwable e) {
fail("Should not have failed");
}
List<String> authsList = new ArrayList<>(authsResponse.getAuthList().size());
for (ByteString authBS : authsResponse.getAuthList()) {
authsList.add(Bytes.toString(authBS.toByteArray()));
}
assertEquals(1, authsList.size());
assertTrue(authsList.contains(PRIVATE));
return null;
}
};
SUPERUSER.runAs(action);
}
Aggregations