@Test
  public void testInitializeAtHaRMCluster() throws AmbariException {

    ClusterImpl cluster = createMock(ClusterImpl.class);
    ServiceComponentHost sch1 = createMock(ServiceComponentHostImpl.class);
    ServiceComponentHost sch2 = createMock(ServiceComponentHostImpl.class);
    expect(cluster.getService("GLUSTERFS")).andReturn(null);
    expect(cluster.getClusterId()).andReturn(1L);

    Map<String, ServiceComponentHost> hostComponents = new HashMap<>();
    hostComponents.put("1",sch1);
    hostComponents.put("2",sch2);

    Service yarnService = createMock(Service.class);
    ServiceComponent resourcemanagerSC = createMock(ServiceComponent.class);

    expect(cluster.getService("YARN")).andReturn(yarnService).atLeastOnce();
    expect(cluster.getService("HDFS")).andReturn(null);
    expect(yarnService.getServiceComponent("RESOURCEMANAGER")).andReturn(resourcemanagerSC).anyTimes();
    expect(resourcemanagerSC.getServiceComponentHosts()).andReturn(hostComponents).anyTimes();
//    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
    expect(yarnService.getDesiredStackId()).andReturn(new StackId("HDP", "2.0.6"));
    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
        .put("YARN", yarnService)
        .build()).anyTimes();

    replay(cluster, yarnService, sch1, sch2, resourcemanagerSC);

    RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
    Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies();
    assertTrue("Dependencies are loaded after initialization", deps.size() > 0);
    verify(cluster, yarnService);
    // Check that GLUSTERFS components are not present in dependencies
    // Checking blocked roles
    assertFalse(dependenciesContainBlockedRole(deps, Role.PEERSTATUS));
    assertFalse(dependenciesContainBlockedRole(deps, Role.GLUSTERFS_SERVICE_CHECK));
    assertFalse(dependenciesContainBlockedRole(deps, Role.GLUSTERFS_CLIENT));
    // Checking blocker roles
    assertFalse(dependenciesContainBlockerRole(deps, Role.PEERSTATUS));
    assertFalse(dependenciesContainBlockerRole(deps, Role.GLUSTERFS_SERVICE_CHECK));
    assertFalse(dependenciesContainBlockerRole(deps, Role.GLUSTERFS_CLIENT));

    // And that some HDFS components are present (section has been loaded)
    assertTrue(dependenciesContainBlockerRole(deps, Role.DATANODE));
    // Check that some HA RM dependencies are present
    RoleCommandPair rmPair = new RoleCommandPair(Role.RESOURCEMANAGER, RoleCommand.START);
    Set<RoleCommandPair> rmRoleCommandPairs = deps.get(rmPair);
    assertNotNull(rmRoleCommandPairs);
    boolean isZookeeperStartPresent = false;
    for (RoleCommandPair pair : rmRoleCommandPairs) {
      if (pair.getCmd() == RoleCommand.START && pair.getRole() == Role.ZOOKEEPER_SERVER) {
        isZookeeperStartPresent = true;
      }
    }
    assertTrue(isZookeeperStartPresent);
  }
Tests building dependencies in HA-enabled HDFS cluster. Uses real
dependency mapping file (role_command_order.json)
ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java