@Test
  public void testIndependentStagesExecutionDisabled() throws Exception {
    Clusters fsm = mock(Clusters.class);
    Cluster oneClusterMock = mock(Cluster.class);
    Service serviceObj = mock(Service.class);
    ServiceComponent scomp = mock(ServiceComponent.class);
    ServiceComponentHost sch = mock(ServiceComponentHost.class);
    UnitOfWork unitOfWork = mock(UnitOfWork.class);
    AgentCommandsPublisher agentCommandsPublisher = mock(AgentCommandsPublisher.class);
    when(fsm.getCluster(anyString())).thenReturn(oneClusterMock);
    when(oneClusterMock.getService(anyString())).thenReturn(serviceObj);
    when(serviceObj.getServiceComponent(anyString())).thenReturn(scomp);
    when(scomp.getServiceComponentHost(anyString())).thenReturn(sch);
    when(serviceObj.getCluster()).thenReturn(oneClusterMock);

    String hostname1 = "ahost.ambari.apache.org";
    String hostname2 = "bhost.ambari.apache.org";
    String hostname3 = "chost.ambari.apache.org";
    String hostname4 = "chost.ambari.apache.org";

    Long hostId1 = 1L;
    Long hostId2 = 2L;
    Long hostId3 = 3L;
    Long hostId4 = 4L;
    HashMap<String, ServiceComponentHost> hosts =
        new HashMap<>();
    hosts.put(hostname1, sch);
    hosts.put(hostname2, sch);
    hosts.put(hostname3, sch);
    hosts.put(hostname4, sch);
    when(scomp.getServiceComponentHosts()).thenReturn(hosts);

    Host host1 = mock(Host.class);
    when(fsm.getHost(hostname1)).thenReturn(host1);
    when(host1.getState()).thenReturn(HostState.HEALTHY);
    when(host1.getHostName()).thenReturn(hostname1);
    when(host1.getHostId()).thenReturn(hostId1);

    Host host2 = mock(Host.class);
    when(fsm.getHost(hostname2)).thenReturn(host2);
    when(host2.getState()).thenReturn(HostState.HEALTHY);
    when(host2.getHostName()).thenReturn(hostname2);
    when(host2.getHostId()).thenReturn(hostId2);

    Host host3 = mock(Host.class);
    when(fsm.getHost(hostname3)).thenReturn(host3);
    when(host3.getState()).thenReturn(HostState.HEALTHY);
    when(host3.getHostName()).thenReturn(hostname3);
    when(host3.getHostId()).thenReturn(hostId3);

    Host host4 = mock(Host.class);
    when(fsm.getHost(hostname4)).thenReturn(host4);
    when(host4.getState()).thenReturn(HostState.HEALTHY);
    when(host4.getHostName()).thenReturn(hostname4);
    when(host4.getHostId()).thenReturn(hostId4);

    List<Stage> stages = new ArrayList<>();
    Stage stage = getStageWithSingleTask(
        hostname1, "cluster1", Role.HIVE_CLIENT,
        RoleCommand.INSTALL, Service.Type.HIVE, 1, 1, 1);
    Map<String, String> hiveSite = new TreeMap<>();
    hiveSite.put("javax.jdo.option.ConnectionPassword", "password");
    hiveSite.put("hive.server2.thrift.port", "10000");
    Map<String, Map<String, String>> configurations =
        new TreeMap<>();
    configurations.put("hive-site", hiveSite);
    stage.getExecutionCommands(hostname1).get(0).getExecutionCommand().setConfigurations(configurations);
    stages.add(stage);

    stages.add( // Stage with the same hostname, should not be scheduled
        getStageWithSingleTask(
            hostname1, "cluster1", Role.GANGLIA_MONITOR,
            RoleCommand.START, Service.Type.GANGLIA, 2, 2, 2));

    stages.add(
        getStageWithSingleTask(
            hostname2, "cluster1", Role.HIVE_CLIENT,
            RoleCommand.INSTALL, Service.Type.HIVE, 3, 3, 3));

    stages.add(
        getStageWithSingleTask(
            hostname3, "cluster1", Role.DATANODE,
            RoleCommand.START, Service.Type.HDFS, 4, 4, 4));

    stages.add( // Stage with the same request id, should not be scheduled
        getStageWithSingleTask(
            hostname4, "cluster1", Role.GANGLIA_MONITOR,
            RoleCommand.START, Service.Type.GANGLIA, 5, 5, 4));

    ActionDBAccessor db = mock(ActionDBAccessor.class);
    HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class);
    Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class));

    RequestEntity request = mock(RequestEntity.class);
    when(request.isExclusive()).thenReturn(false);
    when(request.getClusterHostInfo()).thenReturn(CLUSTER_HOST_INFO);
    when(db.getRequestEntity(anyLong())).thenReturn(request);

    when(db.getCommandsInProgressCount()).thenReturn(stages.size());
    when(db.getFirstStageInProgressPerRequest()).thenReturn(stages);

    Properties properties = new Properties();
    properties.put(Configuration.PARALLEL_STAGE_EXECUTION.getKey(), "false");
    Configuration conf = new Configuration(properties);
    ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, fsm, 3,
        new HostsMap((String) null),
        unitOfWork, null, conf, entityManagerProviderMock,
        hostRoleCommandDAOMock, (HostRoleCommandFactory)null, agentCommandsPublisher));


    doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString());

    scheduler.doWork();

    Assert.assertEquals(HostRoleStatus.QUEUED, stages.get(0).getHostRoleStatus(hostname1, "HIVE_CLIENT"));
    Assert.assertEquals(HostRoleStatus.PENDING, stages.get(1).getHostRoleStatus(hostname1, "GANGLIA_MONITOR"));
    Assert.assertEquals(HostRoleStatus.PENDING, stages.get(2).getHostRoleStatus(hostname2, "HIVE_CLIENT"));
    Assert.assertEquals(HostRoleStatus.PENDING, stages.get(3).getHostRoleStatus(hostname3, "DATANODE"));
    Assert.assertEquals(HostRoleStatus.PENDING, stages.get(4).getHostRoleStatus(hostname4, "GANGLIA_MONITOR"));
    Assert.assertFalse(stages.get(0).getExecutionCommands(hostname1).get(0).getExecutionCommand().
        getConfigurations().containsKey("javax.jdo.option.ConnectionPassword"));
  }
Verifies that ActionScheduler respects "disable parallel stage execution option"
ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java