@Test
public void testOnServiceEvent() 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);
  //Add HDFS service
  List<String> hostList = new ArrayList<String>();
  hostList.add("h1");
  hostList.add("h2");
  hostList.add("h3");
  Map<String, List<Integer>> hdfsTopology = new HashMap<String, List<Integer>>();
  hdfsTopology.put("NAMENODE", Collections.singletonList(0));
  hdfsTopology.put("SECONDARY_NAMENODE", Collections.singletonList(1));
  List<Integer> datanodeHosts = Arrays.asList(0, 1);
  hdfsTopology.put("DATANODE", new ArrayList<Integer>(datanodeHosts));
  addService(c1, hostList, hdfsTopology, "HDFS");
  // Check result
  Set<String> changedHosts = new HashSet<String>();
  changedHosts.add("h1");
  changedHosts.add("h2");
  List<HostVersionEntity> hostVersions = hostVersionDAO.findAll();
  assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION,
      RepositoryVersionState.INSTALLED);
  assertRepoVersionState(yaStackId.getStackId(), INSTALLED_VERSION_2,
      RepositoryVersionState.INSTALLED);
  for (HostVersionEntity hostVersionEntity : hostVersions) {
    if (hostVersionEntity.getRepositoryVersion().getVersion().equals(INSTALLED_VERSION) ||
            hostVersionEntity.getRepositoryVersion().getVersion().equals(INSTALLED_VERSION_2)) {
      if (changedHosts.contains(hostVersionEntity.getHostName())) {
        assertEquals(hostVersionEntity.getState(), RepositoryVersionState.OUT_OF_SYNC);
      } else {
        assertEquals(hostVersionEntity.getState(), RepositoryVersionState.INSTALLED);
      }
    }
  }
}