org.apache.hadoop.hbase.HBaseTestingUtility.getZooKeeperWatcher()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中org.apache.hadoop.hbase.HBaseTestingUtility.getZooKeeperWatcher()方法的一些代码示例,展示了HBaseTestingUtility.getZooKeeperWatcher()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HBaseTestingUtility.getZooKeeperWatcher()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.HBaseTestingUtility
类名称:HBaseTestingUtility
方法名:getZooKeeperWatcher

HBaseTestingUtility.getZooKeeperWatcher介绍

暂无

代码示例

代码示例来源:origin: apache/hbase

private void setExpireBefore(long time)
  throws KeeperException, InterruptedException, IOException {
 ZooKeeper zk = UTIL.getZooKeeperWatcher().getRecoverableZooKeeper().getZooKeeper();
 if (zk.exists(ZooKeeperScanPolicyObserver.NODE, false) == null) {
  zk.create(ZooKeeperScanPolicyObserver.NODE, Bytes.toBytes(time), ZooDefs.Ids.OPEN_ACL_UNSAFE,
   CreateMode.PERSISTENT);
 } else {
  zk.setData(ZooKeeperScanPolicyObserver.NODE, Bytes.toBytes(time), -1);
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testGetRegionsFromMetaTable() throws IOException, InterruptedException {
 List<RegionInfo> regions = MetaTableLocator.getMetaRegions(UTIL.getZooKeeperWatcher());
 assertTrue(regions.size() >= 1);
 assertTrue(MetaTableLocator.getMetaRegionsAndLocations(UTIL.getZooKeeperWatcher()).size() >= 1);
}

代码示例来源:origin: apache/hbase

/**
 * Create a stubbed out RegionServerService, mainly for getting FS.
 * This version is used by TestOpenRegionHandler
 */
public RegionServerServices createMockRegionServerService(ServerName name) throws IOException {
 final MockRegionServerServices rss = new MockRegionServerServices(getZooKeeperWatcher(), name);
 rss.setFileSystem(getTestFileSystem());
 return rss;
}

代码示例来源:origin: apache/hbase

@Before
public void setUp() throws Exception {
 Configuration conf = testUtil.getConfiguration();
 conf.set(HConstants.MASTER_PORT, "0");
 conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 2000);
 testUtil.startMiniZKCluster();
 ZKWatcher watcher = testUtil.getZooKeeperWatcher();
 ZKUtil.createWithParents(watcher, watcher.getZNodePaths().masterAddressZNode,
     Bytes.toBytes("fake:123"));
 master = new HMaster(conf);
 rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT);
}

代码示例来源:origin: apache/hbase

/**
 * Create a stubbed out RegionServerService, mainly for getting FS.
 * This version is used by TestTokenAuthentication
 */
public RegionServerServices createMockRegionServerService(RpcServerInterface rpc) throws
  IOException {
 final MockRegionServerServices rss = new MockRegionServerServices(getZooKeeperWatcher());
 rss.setFileSystem(getTestFileSystem());
 rss.setRpcServer(rpc);
 return rss;
}

代码示例来源:origin: apache/hbase

@After
public void after() throws Exception {
 TEST_UTIL.shutdownMiniHBaseCluster();
 TEST_UTIL.getTestFileSystem().delete(FSUtils.getRootDir(TEST_UTIL.getConfiguration()), true);
 ZKUtil.deleteNodeRecursively(TEST_UTIL.getZooKeeperWatcher(), "/hbase");
}

代码示例来源:origin: apache/hbase

@Test
public void testMirroring() throws Exception {
 final TableName tableName = TableName.valueOf(name.getMethodName());
 TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY_STR);
 ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
 assertTrue(TableState.State.ENABLED.equals(getTableStateInZK(zkw, tableName)));
 TEST_UTIL.getAdmin().disableTable(tableName);
 assertTrue(TableState.State.DISABLED.equals(getTableStateInZK(zkw, tableName)));
 TEST_UTIL.getAdmin().deleteTable(tableName);
 assertTrue(getTableStateInZK(zkw, tableName) == null);
}

代码示例来源:origin: apache/hbase

@After
public void clearPeerAndQueues() throws IOException, ReplicationException {
 try {
  admin.removeReplicationPeer(ID_ONE).join();
 } catch (Exception e) {
 }
 try {
  admin.removeReplicationPeer(ID_TWO).join();
 } catch (Exception e) {
 }
 ReplicationQueueStorage queueStorage = ReplicationStorageFactory
   .getReplicationQueueStorage(TEST_UTIL.getZooKeeperWatcher(), TEST_UTIL.getConfiguration());
 for (ServerName serverName : queueStorage.getListOfReplicators()) {
  for (String queue : queueStorage.getAllQueues(serverName)) {
   queueStorage.removeQueue(serverName, queue);
  }
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testZookeeperNodesForReplicas() throws Exception {
 // Checks all the znodes exist when meta's replicas are enabled
 ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
 Configuration conf = TEST_UTIL.getConfiguration();
 String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
   HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
 String primaryMetaZnode = ZNodePaths.joinZNode(baseZNode,
   conf.get("zookeeper.znode.metaserver", "meta-region-server"));
 // check that the data in the znode is parseable (this would also mean the znode exists)
 byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
 ProtobufUtil.toServerName(data);
 for (int i = 1; i < 3; i++) {
  String secZnode = ZNodePaths.joinZNode(baseZNode,
    conf.get("zookeeper.znode.metaserver", "meta-region-server") + "-" + i);
  String str = zkw.getZNodePaths().getZNodeForReplica(i);
  assertTrue(str.equals(secZnode));
  // check that the data in the znode is parseable (this would also mean the znode exists)
  data = ZKUtil.getData(zkw, secZnode);
  ProtobufUtil.toServerName(data);
 }
}

代码示例来源:origin: apache/hbase

@BeforeClass
public static void setUpBeforeClass() throws Exception {
 utility = new HBaseTestingUtility();
 utility.startMiniZKCluster();
 conf = utility.getConfiguration();
 ZKWatcher zk = HBaseTestingUtility.getZooKeeperWatcher(utility);
 ZKUtil.createWithParents(zk, zk.getZNodePaths().rsZNode);
}

代码示例来源:origin: apache/hbase

@After
public void after() throws Exception {
 try {
  TEST_UTIL.getHBaseCluster().waitForActiveAndReadyMaster(10000);
  // Some regionserver could fail to delete its znode.
  // So shutdown could hang. Let's kill them all instead.
  TEST_UTIL.getHBaseCluster().killAll();
  // Still need to clean things up
  TEST_UTIL.shutdownMiniHBaseCluster();
 } finally {
  TEST_UTIL.getTestFileSystem().delete(FSUtils.getRootDir(TEST_UTIL.getConfiguration()), true);
  ZKUtil.deleteNodeRecursively(TEST_UTIL.getZooKeeperWatcher(), "/hbase");
 }
}

代码示例来源:origin: apache/hbase

@Test
 public void testRegionServerHostnameReportedToMaster() throws Exception {
  TEST_UTIL.getConfiguration().setBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY,
  true);
  StartMiniClusterOption option = StartMiniClusterOption.builder()
    .numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
  TEST_UTIL.startMiniCluster(option);
  boolean tablesOnMaster = LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration());
  int expectedRS = NUM_RS + (tablesOnMaster? 1: 0);
  try (ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher()) {
   List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode);
   assertEquals(expectedRS, servers.size());
  }
 }
}

代码示例来源:origin: apache/hbase

@BeforeClass
public static void setUpBeforeClass() throws Exception {
 UTIL.startMiniCluster(1);
 QUEUE_STORAGE = ReplicationStorageFactory.getReplicationQueueStorage(UTIL.getZooKeeperWatcher(),
  UTIL.getConfiguration());
 QUEUE_STORAGE.addWAL(UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName(), PEER_ID,
  WAL_FILE_NAME);
}

代码示例来源:origin: apache/hbase

/**
 * Setup the config for the cluster
 */
@BeforeClass
public static void setupCluster() throws Exception {
 setupConf(UTIL.getConfiguration());
 UTIL.startMiniZKCluster();
 CONNECTION = (ClusterConnection)ConnectionFactory.createConnection(UTIL.getConfiguration());
 archivingClient = new ZKTableArchiveClient(UTIL.getConfiguration(), CONNECTION);
 // make hfile archiving node so we can archive files
 ZKWatcher watcher = UTIL.getZooKeeperWatcher();
 String archivingZNode = ZKTableArchiveClient.getArchiveZNode(UTIL.getConfiguration(), watcher);
 ZKUtil.createWithParents(watcher, archivingZNode);
 rss = mock(RegionServerServices.class);
}

代码示例来源:origin: apache/hbase

@Before
public void setUp() throws Exception {
 zkw = HBaseTestingUtility.getZooKeeperWatcher(utility);
 String fakeRs1 = ZNodePaths.joinZNode(zkw.getZNodePaths().rsZNode,
     "hostname1.example.org:1234");
 try {
  ZKClusterId.setClusterId(zkw, new ClusterId());
  rp = ReplicationFactory.getReplicationPeers(zkw, conf);
  rp.init();
  rt = ReplicationFactory.getReplicationTracker(zkw, new DummyServer(fakeRs1),
   new DummyServer(fakeRs1));
 } catch (Exception e) {
  fail("Exception during test setup: " + e);
 }
 rsRemovedCount = new AtomicInteger(0);
 rsRemovedData = "";
}

代码示例来源:origin: apache/hbase

@After
public void tearDown() throws Exception {
 for (ReplicationPeerDescription desc : hbaseAdmin.listReplicationPeers()) {
  hbaseAdmin.removeReplicationPeer(desc.getPeerId());
 }
 ReplicationQueueStorage queueStorage = ReplicationStorageFactory
   .getReplicationQueueStorage(TEST_UTIL.getZooKeeperWatcher(), TEST_UTIL.getConfiguration());
 for (ServerName serverName : queueStorage.getListOfReplicators()) {
  for (String queue : queueStorage.getAllQueues(serverName)) {
   queueStorage.removeQueue(serverName, queue);
  }
  queueStorage.removeReplicatorIfQueueIsEmpty(serverName);
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testClusterId() throws Exception  {
 TEST_UTIL.startMiniZKCluster();
 TEST_UTIL.startMiniDFSCluster(1);
 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
 //start region server, needs to be separate
 //so we get an unset clusterId
 rst = JVMClusterUtil.createRegionServerThread(conf, HRegionServer.class, 0);
 rst.start();
 //Make sure RS is in blocking state
 Thread.sleep(10000);
 StartMiniClusterOption option = StartMiniClusterOption.builder()
   .numMasters(1).numRegionServers(0).build();
 TEST_UTIL.startMiniHBaseCluster(option);
 rst.waitForServerOnline();
 String clusterId = ZKClusterId.readClusterIdZNode(TEST_UTIL.getZooKeeperWatcher());
 assertNotNull(clusterId);
 assertEquals(clusterId, rst.getRegionServer().getClusterId());
}

代码示例来源:origin: apache/hbase

@BeforeClass
public static void setUp() throws Exception {
 UTIL.startMiniCluster(1);
 QUEUE_STORAGE = ReplicationStorageFactory.getReplicationQueueStorage(UTIL.getZooKeeperWatcher(),
  UTIL.getConfiguration());
 createPeer();
 QUEUE_STORAGE.addWAL(UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName(), PEER_1,
  WAL_FILE_NAME);
 QUEUE_STORAGE.addWAL(UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName(), PEER_2,
  WAL_FILE_NAME);
}

代码示例来源:origin: apache/hbase

private void stopMasterAndValidateReplicaCount(final int originalReplicaCount,
  final int newReplicaCount)
  throws Exception {
 ServerName sn = TEST_UTIL.getHBaseClusterInterface().getClusterMetrics().getMasterName();
 TEST_UTIL.getHBaseClusterInterface().stopMaster(sn);
 TEST_UTIL.getHBaseClusterInterface().waitForMasterToStop(sn, 60000);
 List<String> metaZnodes = TEST_UTIL.getZooKeeperWatcher().getMetaReplicaNodes();
 assert(metaZnodes.size() == originalReplicaCount); //we should have what was configured before
 TEST_UTIL.getHBaseClusterInterface().getConf().setInt(HConstants.META_REPLICAS_NUM,
   newReplicaCount);
 if (TEST_UTIL.getHBaseCluster().countServedRegions() < newReplicaCount) {
  TEST_UTIL.getHBaseCluster().startRegionServer();
 }
 TEST_UTIL.getHBaseClusterInterface().startMaster(sn.getHostname(), 0);
 TEST_UTIL.getHBaseClusterInterface().waitForActiveAndReadyMaster();
 TEST_UTIL.waitFor(10000, predicateMetaHasReplicas(newReplicaCount));
 // also check if hbck returns without errors
 TEST_UTIL.getConfiguration().setInt(HConstants.META_REPLICAS_NUM,
   newReplicaCount);
 HBaseFsck hbck = HbckTestingUtil.doFsck(TEST_UTIL.getConfiguration(), false);
 HbckTestingUtil.assertNoErrors(hbck);
}

代码示例来源:origin: apache/hbase

@Ignore @Test // The close silently doesn't work any more since HBASE-14614. Fix.
public void testHBaseFsckWithFewerMetaReplicaZnodes() throws Exception {
 ClusterConnection c = (ClusterConnection)ConnectionFactory.createConnection(
   TEST_UTIL.getConfiguration());
 RegionLocations rl = c.locateRegion(TableName.META_TABLE_NAME, HConstants.EMPTY_START_ROW,
   false, false);
 HBaseFsckRepair.closeRegionSilentlyAndWait(c,
   rl.getRegionLocation(2).getServerName(), rl.getRegionLocation(2).getRegionInfo());
 ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
 ZKUtil.deleteNode(zkw, zkw.getZNodePaths().getZNodeForReplica(2));
 // check that problem exists
 HBaseFsck hbck = doFsck(TEST_UTIL.getConfiguration(), false);
 assertErrors(hbck, new ERROR_CODE[]{ERROR_CODE.UNKNOWN,ERROR_CODE.NO_META_REGION});
 // fix the problem
 hbck = doFsck(TEST_UTIL.getConfiguration(), true);
 // run hbck again to make sure we don't see any errors
 hbck = doFsck(TEST_UTIL.getConfiguration(), false);
 assertErrors(hbck, new ERROR_CODE[]{});
}

相关文章

HBaseTestingUtility类方法