@Override
  public void run() {
    while (shouldRun) {
      try {
        if (shouldSendRegistration) {
          sendRegistration();
        } else if (numberOfHeartbeats > 0
            && (currentHeartbeatCount < numberOfHeartbeats)) {
          sendHeartBeat();
        }
        Thread.sleep(sleepTime);
      } catch (InterruptedException e) {
      } catch (Exception ex) {
        LOG.info("Exception received ", ex);
        throw new RuntimeException(ex);
      }
    }
  }
The purpose of this class is to simulate the agent.
ambari-server/src/test/java/org/apache/ambari/server/agent/LocalAgentSimulator.java