org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(14.9k)|赞(0)|评价(0)|浏览(165)

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

MiniZooKeeperCluster介绍

[英]TODO: Most of the code in this class is ripped from ZooKeeper tests. Instead of redoing it, we should contribute updates to their code which let us more easily access testing helper objects.
[中]TODO:这个类中的大部分代码都是从ZooKeeper测试中提取的。我们不应该重做,而是应该为他们的代码提供更新,让我们更容易地访问测试助手对象。

代码示例

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

@Test(timeout = 60000)
public void testMasterInitWithSameClientServerZKQuorum() throws Exception {
 Configuration conf = new Configuration(TESTUTIL.getConfiguration());
 conf.set(HConstants.CLIENT_ZOOKEEPER_QUORUM, HConstants.LOCALHOST);
 conf.setInt(HConstants.CLIENT_ZOOKEEPER_CLIENT_PORT, TESTUTIL.getZkCluster().getClientPort());
 HMaster master = new HMaster(conf);
 master.start();
 // the master will abort due to IllegalArgumentException so we should finish within 60 seconds
 master.join();
}

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

setupTestEnv();
shutdown();
 createDir(dir);
 int tickTimeToUse;
 if (this.tickTime > 0) {
 if (hasValidClientPortInList(i)) {
  currentClientPort = clientPortList.get(i);
 } else {
  tentativePort = selectClientPort(tentativePort); // update the seed
  currentClientPort = tentativePort;
     currentClientPort, e);
   if (hasValidClientPortInList(i)) {
    return -1;
   tentativePort = selectClientPort(tentativePort);
   currentClientPort = tentativePort;
   continue;
 if (!waitForServerUp(currentClientPort, connectionTimeout)) {
  throw new IOException("Waiting for startup of standalone server");

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

int webPort = 0;
int outputFormatServicePort = 0;
boolean usePortsFromConf = conf.getBoolean("minillap.usePortsFromConf", false);
LOG.info("MiniLlap configured to use ports from conf: {}", usePortsFromConf);
if (usePortsFromConf) {
 rpcPort = HiveConf.getIntVar(conf, HiveConf.ConfVars.LLAP_DAEMON_RPC_PORT);
 mngPort = HiveConf.getIntVar(conf, HiveConf.ConfVars.LLAP_MANAGEMENT_RPC_PORT);
 shufflePort = conf.getInt(ShuffleHandler.SHUFFLE_PORT_CONFIG_KEY, ShuffleHandler.DEFAULT_SHUFFLE_PORT);
 webPort = HiveConf.getIntVar(conf, ConfVars.LLAP_DAEMON_WEB_PORT);
 outputFormatServicePort = HiveConf.getIntVar(conf, ConfVars.LLAP_DAEMON_OUTPUT_SERVICE_PORT);
 miniZooKeeperCluster = new MiniZooKeeperCluster();
 miniZooKeeperCluster.startup(zkWorkDir);
} else {
conf.set(ConfVars.LLAP_DAEMON_SERVICE_HOSTS.varname, "@" + clusterNameTrimmed);
conf.set(ConfVars.HIVE_ZOOKEEPER_QUORUM.varname, "localhost");
conf.setInt(ConfVars.HIVE_ZOOKEEPER_CLIENT_PORT.varname, miniZooKeeperCluster.getClientPort());
clusterSpecificConfiguration.set(ConfVars.LLAP_DAEMON_SERVICE_HOSTS.varname, "@" + clusterNameTrimmed);
clusterSpecificConfiguration.set(ConfVars.HIVE_ZOOKEEPER_QUORUM.varname, "localhost");
clusterSpecificConfiguration.setInt(ConfVars.HIVE_ZOOKEEPER_CLIENT_PORT.varname, miniZooKeeperCluster.getClientPort());

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

/**
 * Start a mini ZK cluster. If the property "test.hbase.zookeeper.property.clientPort" is set the
 * port mentioned is used as the default port for ZooKeeper.
 */
private MiniZooKeeperCluster startMiniZKCluster(File dir, int zooKeeperServerNum,
  int[] clientPortList) throws Exception {
 if (this.zkCluster != null) {
  throw new IOException("Cluster already running at " + dir);
 }
 this.passedZkCluster = false;
 this.zkCluster = new MiniZooKeeperCluster(this.getConfiguration());
 int defPort = this.conf.getInt("test.hbase.zookeeper.property.clientPort", 0);
 if (defPort > 0) {
  // If there is a port in the config file, we use it.
  this.zkCluster.setDefaultClientPort(defPort);
 }
 if (clientPortList != null) {
  // Ignore extra client ports
  int clientPortListSize = (clientPortList.length <= zooKeeperServerNum) ? clientPortList.length
    : zooKeeperServerNum;
  for (int i = 0; i < clientPortListSize; i++) {
   this.zkCluster.addClientPort(clientPortList[i]);
  }
 }
 int clientPort = this.zkCluster.startup(dir, zooKeeperServerNum);
 this.conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, Integer.toString(clientPort));
 return this.zkCluster;
}

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

final MiniZooKeeperCluster zooKeeperCluster = new MiniZooKeeperCluster(conf);
File zkDataPath = new File(conf.get(HConstants.ZOOKEEPER_DATA_DIR));
String zkserver = conf.get(HConstants.ZOOKEEPER_QUORUM);
if (zkserver != null) {
 String[] zkservers = zkserver.split(",");
 zkClientPort = conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, 0);
zooKeeperCluster.setDefaultClientPort(zkClientPort);
int zkTickTime = conf.getInt(HConstants.ZOOKEEPER_TICK_TIME, 0);
if (zkTickTime > 0) {
 zooKeeperCluster.setTickTime(zkTickTime);
conf.setInt(HConstants.ZK_SESSION_TIMEOUT, localZKClusterSessionTimeout);
LOG.info("Starting a zookeeper cluster");
int clientPort = zooKeeperCluster.startup(zkDataPath);
if (clientPort != zkClientPort) {
 String errorMsg = "Could not start ZK at requested port of " +

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

@BeforeClass
public static void setUp() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  hbaseTestUtil = new HBaseTestingUtility(conf);
  setUpConfigForMiniCluster(conf);
  conf.set(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
  hbaseTestUtil.startMiniCluster();
  // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver
  zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
  url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum;
  DriverManager.registerDriver(PhoenixDriver.INSTANCE);
}

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

String replicationSourceImplName = conf.get("replication.replicationsource.implementation");
final String peerId = "FakePeer";
final ReplicationPeerConfig peerConfig = ReplicationPeerConfig.newBuilder()
 .setClusterKey("localhost:" + utility.getZkCluster().getClientPort() + ":/hbase").build();
try {
 DummyServer server = new DummyServer();
 conf.set("replication.replicationsource.implementation",
   FailInitializeDummyReplicationSource.class.getName());
 manager.getReplicationPeers();
 assertFalse(rq.getAllQueues(server.getServerName()).contains(peerId));
} finally {
 conf.set("replication.replicationsource.implementation", replicationSourceImplName);
 removePeerAndWait(peerId);

代码示例来源:origin: Impetus/Kundera

public void startCluster()
  Configuration conf = new Configuration();
  System.setProperty("test.build.data", workingDirectory.getAbsolutePath());
  conf.set("test.build.data", new File(workingDirectory, "zookeeper").getAbsolutePath());
  conf.set("fs.default.name", "file:///");
  conf.set("zookeeper.session.timeout", "180000");
  conf.set("hbase.zookeeper.peerport", "2888");
  utility = new HBaseTestingUtility(hbaseConf);
      utility.getConfiguration().set("dfs.datanode.data.dir.perm", perms);
    try
      zkCluster = new MiniZooKeeperCluster(conf);
      zkCluster.setDefaultClientPort(2181);
      zkCluster.setTickTime(18000);
      zkDir = new File(utility.getDataTestDir().toString()).getAbsoluteFile();
      zkCluster.startup(zkDir);
      utility.setZkCluster(zkCluster);
      utility.startMiniCluster();

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

@BeforeClass
public static void setUp() throws Exception {
 PORT = UTIL.startMiniZKCluster().getClientPort();
 ZooKeeper zk = ZooKeeperHelper.getConnectedZooKeeper("localhost:" + PORT, 10000);
 DATA = new byte[10];
 ThreadLocalRandom.current().nextBytes(DATA);
 zk.create(PATH, DATA, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
 for (int i = 0; i < CHILDREN; i++) {
  zk.create(PATH + "/c" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
 }
 zk.close();
 Configuration conf = UTIL.getConfiguration();
 conf.set(HConstants.ZOOKEEPER_QUORUM, "localhost:" + PORT);
 conf.setInt(ReadOnlyZKClient.RECOVERY_RETRY, 3);
 conf.setInt(ReadOnlyZKClient.RECOVERY_RETRY_INTERVAL_MILLIS, 100);
 conf.setInt(ReadOnlyZKClient.KEEPALIVE_MILLIS, 3000);
 RO_ZK = new ReadOnlyZKClient(conf);
 // only connect when necessary
 assertNull(RO_ZK.zookeeper);
}

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

@BeforeClass
public static void beforeAllTests() throws Exception {
 int clientZkPort = 21828;
 clientZkCluster = new MiniZooKeeperCluster(TEST_UTIL.getConfiguration());
 clientZkCluster.setDefaultClientPort(clientZkPort);
 clientZkCluster.startup(clientZkDir);
 // reduce the retry number and start log counter
 TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
 TEST_UTIL.getConfiguration().setInt("hbase.client.start.log.errors.counter", -1);
 TEST_UTIL.getConfiguration().setInt("zookeeper.recovery.retry", 1);
 // core settings for testing client ZK cluster
 TEST_UTIL.getConfiguration().set(HConstants.CLIENT_ZOOKEEPER_QUORUM, HConstants.LOCALHOST);
 TEST_UTIL.getConfiguration().setInt(HConstants.CLIENT_ZOOKEEPER_CLIENT_PORT, clientZkPort);
 // reduce zk session timeout to easier trigger session expiration
 TEST_UTIL.getConfiguration().setInt(HConstants.ZK_SESSION_TIMEOUT, ZK_SESSION_TIMEOUT);
 // Start a cluster with 2 masters and 3 regionservers.
 StartMiniClusterOption option = StartMiniClusterOption.builder()
   .numMasters(2).numRegionServers(3).numDataNodes(3).build();
 TEST_UTIL.startMiniCluster(option);
}

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

@BeforeClass
public static void setUp() throws Exception {
 UTIL.startMiniZKCluster().getClientPort();
 ZKW = new ZKWatcher(new Configuration(UTIL.getConfiguration()), TestZKUtil.class.getName(),
   new WarnOnlyAbortable());
}

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

System.setProperty("config.resource", "/application-co.conf");
Configuration conf = HBaseConfiguration.create();
conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, AggregateProtocolEndPoint.class.getName());
conf.set("zookeeper.znode.parent", getZkZnodeParent());
conf.setInt("hbase.master.info.port", -1);//avoid port clobbering
conf.setInt("hbase.regionserver.info.port", -1);//avoid port clobbering
hbase = new HBaseTestingUtility(conf);
boolean successToStart = false;
while (attempts < 3) {
  try {
    attempts ++;
    hbase.startMiniCluster();
    successToStart = true;
  } catch (Exception e) {
    LOG.error("Error to start mini cluster (tried {} times): {}", attempts, e.getMessage(), e);
    try {
      hbase.shutdownMiniCluster();
    } catch (Exception e1) {
      LOG.warn(e.getMessage(), e);
System.setProperty("storage.hbase.coprocessorEnabled", String.valueOf(true));
System.setProperty("storage.hbase.zookeeperZnodeParent", getZkZnodeParent());
System.setProperty("storage.hbase.zookeeperPropertyClientPort", String.valueOf(hbase.getZkCluster().getClientPort()));

代码示例来源:origin: cdapio/cdap

@BeforeClass
public static void startUp() throws Exception {
 HBaseTestingUtility testUtil = new HBaseTestingUtility();
 zkCluster = testUtil.startMiniZKCluster();
 zkConnectString = testUtil.getConfiguration().get(HConstants.ZOOKEEPER_QUORUM) + ":"
  + zkCluster.getClientPort();
 LOG.info("Running ZK cluster at " + zkConnectString);
 CConfiguration cConf = CConfiguration.create();
 cConf.set(Constants.Zookeeper.QUORUM, zkConnectString);
 injector1 = Guice.createInjector(new ConfigModule(cConf, testUtil.getConfiguration()),
                 new ZKClientModule());
 injector2 = Guice.createInjector(new ConfigModule(cConf, testUtil.getConfiguration()),
                  new ZKClientModule());
}

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

private String getZKClusterKey() {
 return String.format("127.0.0.1:%d:%s", UTIL.getZkCluster().getClientPort(),
  CONF.get(HConstants.ZOOKEEPER_ZNODE_PARENT));
}

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

+ "issues with test execution via MiniDFSCluster");
hbaseTestUtil = new HBaseTestingUtility();
conf = hbaseTestUtil.getConfiguration();
setUpConfigForMiniCluster(conf);
conf.set(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
conf.set("hive.metastore.schema.verification","false");
hiveOutputDir = new Path(hbaseTestUtil.getDataTestDir(), "hive_output").toString();
File outputDir = new File(hiveOutputDir);
outputDir.mkdirs();
zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
props.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));

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

public void setZkCluster(MiniZooKeeperCluster zkCluster) {
 this.passedZkCluster = true;
 this.zkCluster = zkCluster;
 conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, zkCluster.getClientPort());
}

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

int defaultClientPort = 8888;
int i, j;
HBaseTestingUtility hbt = new HBaseTestingUtility();
MiniZooKeeperCluster cluster1 = hbt.startMiniZKCluster(clientPortList1.length, clientPortList1);
try {
 List<Integer> clientPortListInCluster = cluster1.getClientPortList();
 hbt.shutdownMiniZKCluster();
hbt.getConfiguration().setInt("test.hbase.zookeeper.property.clientPort", defaultClientPort);
int [] clientPortList2 = {2222, 2223};
MiniZooKeeperCluster cluster2 =
 List<Integer> clientPortListInCluster = cluster2.getClientPortList();
hbt.getConfiguration().setInt("test.hbase.zookeeper.property.clientPort", defaultClientPort);
int [] clientPortList3 = {3333, -3334, 3335, 0};
MiniZooKeeperCluster cluster3 =
 List<Integer> clientPortListInCluster = cluster3.getClientPortList();
 List<Integer> clientPortListInCluster = cluster4.getClientPortList();
 MiniZooKeeperCluster cluster5 =
   hbt.startMiniZKCluster(clientPortList5.length, clientPortList5);
 assertTrue(cluster5.getClientPort() == -1); // expected failure
} catch (Exception e) {

代码示例来源:origin: co.cask.hbase/hbase

return -1;
setupTestEnv();
shutdown();
int tentativePort = selectClientPort();
 recreateDir(dir);
 int tickTimeToUse;
 if (this.tickTime > 0) {
   standaloneServerFactory.configure(
    new InetSocketAddress(tentativePort),
    configuration.getInt(HConstants.ZOOKEEPER_MAX_CLIENT_CNXNS,
     1000));
  } catch (BindException e) {
 if (!waitForServerUp(tentativePort, CONNECTION_TIMEOUT)) {
  throw new IOException("Waiting for startup of standalone server");

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

@BeforeClass
public static void setUp() throws Exception {
 UTIL.startMiniCluster(3);
 UTIL.getAdmin()
   .createTable(TableDescriptorBuilder.newBuilder(NAME)
     .setCoprocessor(ZooKeeperScanPolicyObserver.class.getName())
     .setValue(ZooKeeperScanPolicyObserver.ZK_ENSEMBLE_KEY,
      "localhost:" + UTIL.getZkCluster().getClientPort())
     .setValue(ZooKeeperScanPolicyObserver.ZK_SESSION_TIMEOUT_KEY, "2000")
     .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build()).build());
 TABLE = UTIL.getConnection().getTable(NAME);
}

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

@Test
public void testTimestampPredicate() throws Exception {
  String testName = "testTimeStampPredicate";
  hbaseTestUtil.getTestFileSystem().createNewFile(new Path(hiveLogDir, testName + ".out"));
  createFile("10\t2013-01-02 01:01:01.123\n", new Path(hiveOutputDir, testName + ".out").toString());
  createFile(StringUtil.EMPTY_STRING, new Path(hiveLogDir, testName + ".out").toString());
      "   'phoenix.zookeeper.quorum'='localhost'," + HiveTestUtil.CRLF +
      "   'phoenix.zookeeper.client.port'='" +
      hbaseTestUtil.getZkCluster().getClientPort() + "'," + HiveTestUtil.CRLF +
      "   'phoenix.column.mapping' = 'id:ID, ts:TS'," + HiveTestUtil.CRLF +
      "   'phoenix.rowkeys'='id');" + HiveTestUtil.CRLF);
      " '2015-01-02 12:01:02.123457789' AND id = 10;" + HiveTestUtil.CRLF);
  String fullPath = new Path(hbaseTestUtil.getDataTestDir(), testName).toString();
  createFile(sb.toString(), fullPath);
  runTest(testName, fullPath);

相关文章