private static void loopUntilZKReady(Configuration conf, String msHost, int port)
          throws Exception {
    ZooKeeperHiveHelper zkHelper = MetastoreConf.getZKConfig(conf);
    String uri;
    if (msHost != null && !msHost.trim().isEmpty()) {
      uri = msHost;
    } else {
      uri = InetAddress.getLocalHost().getHostName();
    }
    uri = IPStackUtils.concatHostPort(uri, port);
    int retries = 0;
    while (true) {
      try {
        List<String> serverUris = zkHelper.getServerUris();
        // URI of the metastore server should be same as expected.
        if (!serverUris.equals(Collections.singletonList(uri))) {
            throw new Exception("Expected metastore URI " + uri + " but got " + serverUris);
        }
        return;
      } catch (Exception e) {
        if (retries++ > 60) { //give up
          // Metastore URI is not visible from the ZooKeeper yet.
          LOG.error("Unable to get metastore URI from the ZooKeeper: " + e.getMessage());
          throw e;
        }
        Thread.sleep(1000);
      }
    }
  }
A simple connect test to make sure that the metastore URI is available in the ZooKeeper
@throws Exception Timeout after 60 seconds
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java