@Test
  public void testDeleteHostComponentInVariousStates() throws Exception {
    String cluster1 = getUniqueName();
    createCluster(cluster1);
    clusters.getCluster(cluster1).setDesiredStackVersion(new StackId("HDP-1.3.1"));
    String hdfs = "HDFS";
    String mapred = "MAPREDUCE";
    createService(cluster1, hdfs, null);
    createService(cluster1, mapred, null);
    String componentName1 = "NAMENODE";
    String componentName2 = "DATANODE";
    String componentName3 = "HDFS_CLIENT";
    String componentName4 = "JOBTRACKER";
    String componentName5 = "TASKTRACKER";
    String componentName6 = "MAPREDUCE_CLIENT";

    createServiceComponent(cluster1, hdfs, componentName1, State.INIT);
    createServiceComponent(cluster1, hdfs, componentName2, State.INIT);
    createServiceComponent(cluster1, hdfs, componentName3, State.INIT);
    createServiceComponent(cluster1, mapred, componentName4, State.INIT);
    createServiceComponent(cluster1, mapred, componentName5, State.INIT);
    createServiceComponent(cluster1, mapred, componentName6, State.INIT);

    String host1 = getUniqueName();

    addHostToCluster(host1, cluster1);

    createServiceComponentHost(cluster1, hdfs, componentName1, host1, null);
    createServiceComponentHost(cluster1, hdfs, componentName2, host1, null);
    createServiceComponentHost(cluster1, hdfs, componentName3, host1, null);
    createServiceComponentHost(cluster1, mapred, componentName4, host1, null);
    createServiceComponentHost(cluster1, mapred, componentName5, host1, null);
    createServiceComponentHost(cluster1, mapred, componentName6, host1, null);

    // Install
    installService(cluster1, hdfs, false, false);
    installService(cluster1, mapred, false, false);

    Cluster cluster = clusters.getCluster(cluster1);
    Service s1 = cluster.getService(hdfs);
    Service s2 = cluster.getService(mapred);
    ServiceComponent sc1 = s1.getServiceComponent(componentName1);
    sc1.getServiceComponentHosts().values().iterator().next().setState(State.STARTED);

    Set<ServiceComponentHostRequest> schRequests = new HashSet<>();
    // delete HC
    schRequests.clear();
    schRequests.add(new ServiceComponentHostRequest(cluster1, hdfs, componentName1, host1, null));
    try {
      controller.deleteHostComponents(schRequests);
      Assert.fail("Expect failure while deleting.");
    } catch (Exception ex) {
      Assert.assertTrue(ex.getMessage().contains(
          "Current host component state prohibiting component removal"));
    }

    sc1.getServiceComponentHosts().values().iterator().next().setDesiredState(State.STARTED);
    sc1.getServiceComponentHosts().values().iterator().next().setState(State.UNKNOWN);
    ServiceComponent sc2 = s1.getServiceComponent(componentName2);
    sc2.getServiceComponentHosts().values().iterator().next().setState(State.INIT);
    ServiceComponent sc3 = s1.getServiceComponent(componentName3);
    sc3.getServiceComponentHosts().values().iterator().next().setState(State.INSTALL_FAILED);
    ServiceComponent sc4 = s2.getServiceComponent(componentName4);
    sc4.getServiceComponentHosts().values().iterator().next().setDesiredState(State.INSTALLED);
    sc4.getServiceComponentHosts().values().iterator().next().setState(State.DISABLED);
    ServiceComponent sc5 = s2.getServiceComponent(componentName5);
    sc5.getServiceComponentHosts().values().iterator().next().setState(State.INSTALLED);
    ServiceComponent sc6 = s2.getServiceComponent(componentName6);
    sc6.getServiceComponentHosts().values().iterator().next().setState(State.INIT);

    schRequests.clear();
    schRequests.add(new ServiceComponentHostRequest(cluster1, hdfs, componentName1, host1, null));
    schRequests.add(new ServiceComponentHostRequest(cluster1, hdfs, componentName2, host1, null));
    schRequests.add(new ServiceComponentHostRequest(cluster1, hdfs, componentName3, host1, null));
    schRequests.add(new ServiceComponentHostRequest(cluster1, mapred, componentName4, host1, null));
    schRequests.add(new ServiceComponentHostRequest(cluster1, mapred, componentName5, host1, null));
    schRequests.add(new ServiceComponentHostRequest(cluster1, mapred, componentName6, host1, null));
    DeleteStatusMetaData deleteStatusMetaData = controller.deleteHostComponents(schRequests);
    Assert.assertEquals(0, deleteStatusMetaData.getExceptionForKeys().size());
  }
Create a cluster with a service, and verify that the request tasks have the correct output log and error log paths.
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java