当前位置: 首页>>代码示例>>Java>>正文


Java HBaseTestingUtility.getAllOnlineRegions方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.HBaseTestingUtility.getAllOnlineRegions方法的典型用法代码示例。如果您正苦于以下问题:Java HBaseTestingUtility.getAllOnlineRegions方法的具体用法?Java HBaseTestingUtility.getAllOnlineRegions怎么用?Java HBaseTestingUtility.getAllOnlineRegions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.HBaseTestingUtility的用法示例。


在下文中一共展示了HBaseTestingUtility.getAllOnlineRegions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testForCheckingIfEnableAndDisableWorksFineAfterSwitch

import org.apache.hadoop.hbase.HBaseTestingUtility; //导入方法依赖的package包/类
@Test
public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch()
    throws Exception {
  final int NUM_MASTERS = 2;
  final int NUM_RS = 1;
  final int NUM_REGIONS_TO_CREATE = 4;

  // Start the cluster
  log("Starting cluster");
  Configuration conf = HBaseConfiguration.create();
  HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
  TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  log("Waiting for active/ready master");
  cluster.waitForActiveAndReadyMaster();
  ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "testmasterRestart", null);
  HMaster master = cluster.getMaster();

  // Create a table with regions
  TableName table = TableName.valueOf("tableRestart");
  byte[] family = Bytes.toBytes("family");
  log("Creating table with " + NUM_REGIONS_TO_CREATE + " regions");
  HTable ht = TEST_UTIL.createMultiRegionTable(table, family, NUM_REGIONS_TO_CREATE);
  int numRegions = -1;
  try (RegionLocator r = ht.getRegionLocator()) {
    numRegions = r.getStartKeys().length;
  }
  numRegions += 1; // catalogs
  log("Waiting for no more RIT\n");
  blockUntilNoRIT(zkw, master);
  log("Disabling table\n");
  TEST_UTIL.getHBaseAdmin().disableTable(table);

  NavigableSet<String> regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
  assertEquals(
      "The number of regions for the table tableRestart should be 0 and only"
          + "the catalog and namespace tables should be present.", 2, regions.size());

  List<MasterThread> masterThreads = cluster.getMasterThreads();
  MasterThread activeMaster = null;
  if (masterThreads.get(0).getMaster().isActiveMaster()) {
    activeMaster = masterThreads.get(0);
  } else {
    activeMaster = masterThreads.get(1);
  }
  activeMaster.getMaster().stop(
      "stopping the active master so that the backup can become active");
  cluster.hbaseCluster.waitOnMaster(activeMaster);
  cluster.waitForActiveAndReadyMaster();

  assertTrue("The table should not be in enabled state", cluster.getMaster()
      .getAssignmentManager().getTableStateManager().isTableState(
      TableName.valueOf("tableRestart"), ZooKeeperProtos.Table.State.DISABLED,
      ZooKeeperProtos.Table.State.DISABLING));
  log("Enabling table\n");
  // Need a new Admin, the previous one is on the old master
  Admin admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
  admin.enableTable(table);
  admin.close();
  log("Waiting for no more RIT\n");
  blockUntilNoRIT(zkw, master);
  log("Verifying there are " + numRegions + " assigned on cluster\n");
  regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
  assertEquals("The assigned regions were not onlined after master"
      + " switch except for the catalog and namespace tables.",
        6, regions.size());
  assertTrue("The table should be in enabled state", cluster.getMaster()
      .getAssignmentManager().getTableStateManager()
      .isTableState(TableName.valueOf("tableRestart"), ZooKeeperProtos.Table.State.ENABLED));
  ht.close();
  TEST_UTIL.shutdownMiniCluster();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:73,代码来源:TestMasterRestartAfterDisablingTable.java


注:本文中的org.apache.hadoop.hbase.HBaseTestingUtility.getAllOnlineRegions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。