@Override public List<LoadQueueItem> call() throws Exception { List<LoadQueueItem> toRetry = tryAtomicRegionLoad(serviceCallable, table.getName(), first, lqis); return toRetry; } };
/** * Invokes Table#delete to delete test data (i.e. the row) * * @param table Standard Table object * @throws IOException If IO problem is encountered */ static void deleteRow(final Table table) throws IOException { System.out.println("Deleting row [" + Bytes.toString(MY_ROW_ID) + "] from Table [" + table.getName().getNameAsString() + "]."); table.delete(new Delete(MY_ROW_ID)); }
/** * Invokes Table#delete to delete test data (i.e. the row) * * @param table Standard Table object * @throws IOException If IO problem is encountered */ static void deleteRow(final Table table) throws IOException { System.out.println("Deleting row [" + Bytes.toString(MY_ROW_ID) + "] from Table [" + table.getName().getNameAsString() + "]."); table.delete(new Delete(MY_ROW_ID)); }
@Override public Table getTable(TableName tableName) throws IOException { Table table = Mockito.mock(Table.class); Mockito.when(table.getName()).thenReturn(tableName); return table; }
@Override public Table getTable(TableName tableName) throws IOException { Table table = mock(Table.class); when(table.getName()).thenReturn(tableName); return table; }
@Override protected void closeHTable() { if (table != null) { try { table.close(); } catch (Exception e) { LOG.error("Error in closing the table "+table.getName(), e); } } }
@Override protected void closeTable() { for (Table table : userVsTable.values()) { try { table.close(); } catch (Exception e) { LOG.error("Error while closing the table " + table.getName(), e); } } }
@Override public void loadData(final Table table, byte[]... families) throws Exception { SnapshotTestingUtils.loadData(UTIL, table.getName(), 1000, families); }
private static void waitOnSplit(Connection c, final Table t, int originalCount) throws Exception { for (int i = 0; i < 200; i++) { Threads.sleepWithoutInterrupt(500); try (RegionLocator locator = c.getRegionLocator(t.getName())) { if (locator.getAllRegionLocations().size() > originalCount) { return; } } } throw new Exception("Split did not increase the number of regions"); }
RegionSplitter(Table table) throws IOException { this.table = table; this.tableName = table.getName(); this.family = table.getTableDescriptor().getFamiliesKeys().iterator().next(); admin = TEST_UTIL.getAdmin(); rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0); connection = TEST_UTIL.getConnection(); }
private List<HRegionLocation> splitTable(final Table t) throws IOException, InterruptedException { // Split this table in two. Admin admin = TEST_UTIL.getAdmin(); admin.split(t.getName()); admin.close(); List<HRegionLocation> regions = waitOnSplit(t); assertTrue(regions.size() > 1); return regions; }
@Test public void testOpeningReadOnlyRegionBasic() throws Exception { String snapshotDir = client.createSnapshot(baseDir, SNAPSHOT_NAME); RegionInfo firstRegion = TEST_UTIL.getConnection().getRegionLocator( table.getName()).getAllRegionLocations().stream().findFirst().get().getRegion(); Path tableDir = FSUtils.getTableDir(new Path(snapshotDir), TABLE_NAME); HRegion snapshottedRegion = openSnapshotRegion(firstRegion, tableDir); Assert.assertNotNull(snapshottedRegion); snapshottedRegion.close(); }
@Override public Void run() throws Exception { Get g = new Get(row1); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(table.getName())) { Result result = t.get(g); assertTrue(!result.isEmpty()); } return null; } };
@Override public Void run() throws Exception { Get g = new Get(row1); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(table.getName())) { Result result = t.get(g); assertTrue(result.isEmpty()); } return null; } };
private void moveRegion(Table table, int index) throws IOException{ List<Pair<RegionInfo, ServerName>> regions = MetaTableAccessor .getTableRegionsAndLocations(TEST_UTIL.getConnection(), table.getName()); assertEquals(1, regions.size()); RegionInfo regionInfo = regions.get(0).getFirst(); ServerName name = TEST_UTIL.getHBaseCluster().getRegionServer(index).getServerName(); TEST_UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(name.getServerName())); }
@Override public Void run() throws Exception { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(table.getName())) { ResultScanner scanner = t.getScanner(s); Result[] result = scanner.next(5); assertTrue(result.length == 2); } return null; } };
@Override protected String rpcCall() throws Exception { byte[] regionName = getLocation().getRegionInfo().getRegionName(); RegionSpecifier region = RequestConverter.buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName); PrepareBulkLoadRequest request = PrepareBulkLoadRequest.newBuilder() .setTableName(ProtobufUtil.toProtoTableName(table.getName())) .setRegion(region).build(); PrepareBulkLoadResponse response = getStub().prepareBulkLoad(null, request); return response.getBulkToken(); } };
private void assertAllOnLine(final Table t) throws IOException { List<HRegionLocation> regions; try(RegionLocator rl = TEST_UTIL.getConnection().getRegionLocator(t.getName())) { regions = rl.getAllRegionLocations(); } for (HRegionLocation e: regions) { byte [] startkey = e.getRegionInfo().getStartKey(); Scan s = new Scan(startkey); ResultScanner scanner = t.getScanner(s); Result r = scanner.next(); org.junit.Assert.assertTrue(r != null && r.size() > 0); scanner.close(); } } }
@Test(expected = TableNotEnabledException.class) public void testWritingToDisabledTable() throws IOException { try (Admin admin = UTIL.getConnection().getAdmin(); Table table = UTIL.getConnection().getTable(TABLE_FOR_NEGATIVE_TESTS)) { admin.disableTable(table.getName()); runTestOnTable(table); fail("Should not have reached here, should have thrown an exception"); } }