@Test
  public void testDeleteClusterCreateHost() throws Exception {

    String STACK_ID = "HDP-2.0.1";

    String CLUSTER_NAME = getUniqueName();
    String HOST1 = getUniqueName();
    String HOST2 = getUniqueName();

    Clusters clusters = injector.getInstance(Clusters.class);

    clusters.addHost(HOST1);
    Host host = clusters.getHost(HOST1);
    setOsFamily(host, "redhat", "6.3");
    clusters.getHost(HOST1).setState(HostState.HEALTHY);
    clusters.updateHostMappings(host);

    clusters.addHost(HOST2);

    host = clusters.getHost(HOST2);
    clusters.updateHostMappings(host);
    setOsFamily(host, "redhat", "6.3");

    AmbariManagementController amc = injector.getInstance(AmbariManagementController.class);

    ClusterRequest cr = new ClusterRequest(null, CLUSTER_NAME, STACK_ID, null);
    amc.createCluster(cr);

    long clusterId = clusters.getCluster(CLUSTER_NAME).getClusterId();

    ConfigurationRequest configRequest = new ConfigurationRequest(CLUSTER_NAME, "global", "version1",
        new HashMap<String, String>() {{ put("a", "b"); }}, null);
    ClusterRequest ur = new ClusterRequest(clusterId, CLUSTER_NAME, STACK_ID, null);
    ur.setDesiredConfig(Collections.singletonList(configRequest));
    amc.updateClusters(Collections.singleton(ur), new HashMap<>());

    // add some hosts
    Set<HostRequest> hrs = new HashSet<>();
    hrs.add(new HostRequest(HOST1, CLUSTER_NAME));
    HostResourceProviderTest.createHosts(amc, hrs);

    Set<ServiceRequest> serviceRequests = new HashSet<>();
    serviceRequests.add(new ServiceRequest(CLUSTER_NAME, "HDFS", repositoryVersion201.getId(), null));
    serviceRequests.add(new ServiceRequest(CLUSTER_NAME, "MAPREDUCE2", repositoryVersion201.getId(), null));
    serviceRequests.add(new ServiceRequest(CLUSTER_NAME, "YARN", repositoryVersion201.getId(), null));

    ServiceResourceProviderTest.createServices(amc, repositoryVersionDAO, serviceRequests);

    Set<ServiceComponentRequest> serviceComponentRequests = new HashSet<>();
    serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "NAMENODE", null));
    serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "SECONDARY_NAMENODE", null));
    serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "DATANODE", null));
    serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "MAPREDUCE2", "HISTORYSERVER", null));
    serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "YARN", "RESOURCEMANAGER", null));
    serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "YARN", "NODEMANAGER", null));
    serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "HDFS_CLIENT", null));

    ComponentResourceProviderTest.createComponents(amc, serviceComponentRequests);

    Set<ServiceComponentHostRequest> componentHostRequests = new HashSet<>();
    componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, "HDFS", "DATANODE", HOST1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, "HDFS", "NAMENODE", HOST1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, "HDFS", "SECONDARY_NAMENODE", HOST1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, "MAPREDUCE2", "HISTORYSERVER", HOST1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, "YARN", "RESOURCEMANAGER", HOST1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, "YARN", "NODEMANAGER", HOST1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, "HDFS", "HDFS_CLIENT", HOST1, null));

    amc.createHostComponents(componentHostRequests);

    RequestResourceFilter resourceFilter = new RequestResourceFilter("HDFS", null, null);
    ExecuteActionRequest ar = new ExecuteActionRequest(CLUSTER_NAME, Role.HDFS_SERVICE_CHECK.name(), null, false);
    ar.getResourceFilters().add(resourceFilter);
    amc.createAction(ar, null);


    // change mind, delete the cluster
    amc.deleteCluster(cr);

    assertNotNull(clusters.getHost(HOST1));
    assertNotNull(clusters.getHost(HOST2));

    HostDAO dao = injector.getInstance(HostDAO.class);

    assertNotNull(dao.findByName(HOST1));
    assertNotNull(dao.findByName(HOST2));

  }
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