@Test
  public void testHostRegistrationPopulatesIdMapping() throws Exception {
    String clusterName = UUID.randomUUID().toString();
    String hostName = UUID.randomUUID().toString();

    // required so that the event which does the work is executed synchornously
    EventBusSynchronizer.synchronizeAmbariEventPublisher(injector);

    Cluster cluster = createCluster(clusterName);
    Assert.assertNotNull(cluster);

    addHostToCluster(hostName, clusterName);
    Host host = clusters.getHost(hostName);
    Assert.assertNotNull(host);
    long currentTime = System.currentTimeMillis();

    HostRegistrationRequestEvent registrationEvent = new HostRegistrationRequestEvent(
        host.getHostName(),
        new AgentVersion(""), currentTime, new HostInfo(), new AgentEnv(), currentTime);

    host.handleEvent(registrationEvent);

    Long hostId = host.getHostId();
    Assert.assertNotNull(hostId);

    host = clusters.getHostById(hostId);
    Assert.assertNotNull(host);
  }
Tests that {@link HostRegisteredEvent} properly updates the
{@link Clusters} in-memory mapping of hostIds to hosts.

@throws AmbariException
ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java