@Before public void beforeMethod() throws Exception { if (!INIT) { INIT = true; afterMethod(); } }
private void restartHBaseCluster() throws Exception { LOG.info("\n\nShutting down cluster"); TEST_UTIL.shutdownMiniHBaseCluster(); LOG.info("\n\nSleeping a bit"); Thread.sleep(2000); TEST_UTIL.restartHBaseCluster(NUM_SLAVES_BASE - 1); initialize(); } }
@Test public void testRSGroupsWithHBaseQuota() throws Exception { TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, true); restartHBaseCluster(); try { TEST_UTIL.waitFor(90000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return admin.isTableAvailable(QuotaTableUtil.QUOTA_TABLE_NAME); } }); } finally { TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, false); restartHBaseCluster(); } }
@After public void afterMethod() throws Exception { deleteTableIfNecessary(); deleteNamespaceIfNecessary(); deleteGroups(); int missing = NUM_SLAVES_BASE - getNumServers(); LOG.info("Restoring servers: "+missing); for(int i=0; i<missing; i++) {
@Test public void testNamespaceCreateAndAssign() throws Exception { LOG.info("testNamespaceCreateAndAssign"); String nsName = tablePrefix+"_foo"; final TableName tableName = TableName.valueOf(nsName, tablePrefix + "_testCreateAndAssign"); RSGroupInfo appInfo = addGroup("appInfo", 1); admin.createNamespace(NamespaceDescriptor.create(nsName) .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, "appInfo").build()); final HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor("f")); admin.createTable(desc); //wait for created table to be assigned TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return getTableRegionMap().get(desc.getTableName()) != null; } }); ServerName targetServer = ServerName.parseServerName(appInfo.getServers().iterator().next().toString()); AdminProtos.AdminService.BlockingInterface rs = ((ClusterConnection) admin.getConnection()).getAdmin(targetServer); //verify it was assigned to the right group Assert.assertEquals(1, ProtobufUtil.getOnlineRegions(rs).size()); }
@Test public void testMisplacedRegions() throws Exception { final TableName tableName = TableName.valueOf(tablePrefix+"_testMisplacedRegions"); LOG.info("testMisplacedRegions"); final RSGroupInfo RSGroupInfo = addGroup("testMisplacedRegions", 1); TEST_UTIL.createMultiRegionTable(tableName, new byte[]{'f'}, 15); TEST_UTIL.waitUntilAllRegionsAssigned(tableName); rsGroupAdminEndpoint.getGroupInfoManager() .moveTables(Sets.newHashSet(tableName), RSGroupInfo.getName()); admin.setBalancerRunning(true,true); assertTrue(rsGroupAdmin.balanceRSGroup(RSGroupInfo.getName())); admin.setBalancerRunning(false,true); assertTrue(observer.preBalanceRSGroupCalled); assertTrue(observer.postBalanceRSGroupCalled); TEST_UTIL.waitFor(60000, new Predicate<Exception>() { @Override public boolean evaluate() throws Exception { ServerName serverName = ServerName.valueOf(RSGroupInfo.getServers().iterator().next().toString(), 1); return admin.getConnection().getAdmin() .getOnlineRegions(serverName).size() == 15; } }); }
@BeforeClass public static void setUp() throws Exception { TEST_UTIL = new HBaseTestingUtility(); TEST_UTIL.getConfiguration().setFloat( "hbase.master.balancer.stochastic.tableSkewCost", 6000); TEST_UTIL.getConfiguration().set( HConstants.HBASE_MASTER_LOADBALANCER_CLASS, RSGroupBasedLoadBalancer.class.getName()); TEST_UTIL.getConfiguration().set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, RSGroupAdminEndpoint.class.getName() + "," + CPMasterObserver.class.getName()); TEST_UTIL.startMiniCluster(NUM_SLAVES_BASE - 1); TEST_UTIL.getConfiguration().setInt( ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, NUM_SLAVES_BASE - 1); TEST_UTIL.getConfiguration().setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true); initialize(); }