@Test
  public void testOnServiceComponentEvent() throws AmbariException {
    String INSTALLED_VERSION = "2.2.0-1000";
    String INSTALLED_VERSION_2 = "2.1.1-2000";
    StackId stackId = new StackId(this.stackId);
    StackId yaStackId = new StackId(yetAnotherStackId);

    createClusterAndHosts(INSTALLED_VERSION, stackId);
    addRepoVersion(INSTALLED_VERSION_2, yaStackId);

    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
    assertRepoVersionState(INSTALLED_VERSION_2, RepositoryVersionState.INSTALLED);

    //Add ZOOKEEPER_CLIENT component
    List<String> hostList = new ArrayList<>();
    hostList.add("h1");
    hostList.add("h2");
    hostList.add("h3");
    addServiceComponent(c1, hostList, "ZOOKEEPER", "ZOOKEEPER_CLIENT");

    // Check result
    Set<String> changedHosts = new HashSet<>();
    changedHosts.add("h1");
    changedHosts.add("h2");
    changedHosts.add("h3");

    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.OUT_OF_SYNC);

    List<HostVersionEntity> hostVersions = hostVersionDAO.findAll();

    for (HostVersionEntity hostVersionEntity : hostVersions) {
      RepositoryVersionEntity repoVersion = hostVersionEntity.getRepositoryVersion();

      if (repoVersion.getVersion().equals(INSTALLED_VERSION_2)) {
        assertEquals(RepositoryVersionState.INSTALLED, hostVersionEntity.getState());
      } else if (repoVersion.getVersion().equals(INSTALLED_VERSION)) {
        assertTrue(changedHosts.contains(hostVersionEntity.getHostName()));
        assertEquals(RepositoryVersionState.OUT_OF_SYNC, hostVersionEntity.getState());
      }
    }
  }
When a new service is added to a cluster with components, all INSTALLED host versions on
all affected hosts (where host new components are installed)
should transition to OUT_OF_SYNC state.
ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java