private static void loopUntilHMSReady(String msHost, int port, AtomicBoolean houseKeepingStarted) throws Exception {
    int retries = 0;
    Exception exc = null;
    while (retries++ < 60) {
      try {
        Socket socket = new Socket();
        SocketAddress sockAddr;
        if (msHost == null) {
          sockAddr = new InetSocketAddress(port);
        } else {
          sockAddr = new InetSocketAddress(msHost, port);
        }
        socket.connect(sockAddr, 5000);
        socket.close();
        if (houseKeepingStarted == null || houseKeepingStarted.get()) {
          return;
        } else {
          LOG.info("HMS started, waiting for housekeeper threads to start.");
        }
      } catch (Exception e) {
        LOG.info("Waiting the HMS to start.");
        exc = e;
      }
      Thread.sleep(1000);
    }
    if (exc == null) {
      exc = new IllegalStateException("HMS started, but housekeeping threads were not started until 60 sec.");
    }
    // something is preventing metastore from starting
    // print the stack from all threads for debugging purposes
    LOG.error("Unable to connect to metastore server: " + exc.getMessage());
    LOG.info("Printing all thread stack traces for debugging before throwing exception.");
    LOG.info(MetaStoreTestUtils.getAllThreadStacksAsString());
    throw exc;
  }
A simple connect test to make sure that the metastore is up
@throws Exception Timeout after 60 seconds
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java