private boolean awaitForLocked(long procId, long timeoutInMs) throws Exception {
    long deadline = EnvironmentEdgeManager.currentTime() + timeoutInMs;
    while (EnvironmentEdgeManager.currentTime() < deadline) {
      LockHeartbeatResponse response = masterRpcService.lockHeartbeat(null,
        LockHeartbeatRequest.newBuilder().setProcId(procId).build());
      if (response.getLockStatus() == LockHeartbeatResponse.LockStatus.LOCKED) {
        assertEquals(HEARTBEAT_TIMEOUT, response.getTimeoutMs());
        LOG.debug(String.format("Proc id %s acquired lock.", procId));
        return true;
      }
      Thread.sleep(100);
    }
    return false;
  }
Returns immediately if the lock is acquired.
@throws TimeoutException if lock couldn't be acquired.
hbase-server/src/test/java/org/apache/hadoop/hbase/master/locking/TestLockProcedure.java