@Test
  public void testGetHosts() throws Exception, AuthorizationException {
    final String cluster1 = getUniqueName();
    final String cluster2 = getUniqueName();
    final String host1 = getUniqueName();
    final String host2 = getUniqueName();
    final String host3 = getUniqueName();
    final String host4 = getUniqueName();

    setupClusterWithHosts(cluster1, "HDP-0.2",
        new ArrayList<String>() {{
          add(host1);
          add(host2);
        }},
        "centos5");

    setupClusterWithHosts(cluster2, "HDP-0.2",
        new ArrayList<String>() {{
          add(host3);
        }},
        "centos5");
    clusters.addHost(host4);
    setOsFamily(clusters.getHost(host4), "redhat", "5.9");

    Map<String, String> attrs = new HashMap<>();
    attrs.put("a1", "b1");
    clusters.getHost(host3).setHostAttributes(attrs);
    attrs.put("a2", "b2");
    clusters.getHost(host4).setHostAttributes(attrs);

    HostRequest r = new HostRequest(null, null);

    Set<HostResponse> resps = HostResourceProviderTest.getHosts(controller, Collections.singleton(r));

    Set<String> foundHosts = new HashSet<>();

    for (HostResponse resp : resps) {
      if (resp.getHostname().equals(host1)) {
        Assert.assertEquals(cluster1, resp.getClusterName());
        Assert.assertEquals(2, resp.getHostAttributes().size());
        Assert.assertEquals(MaintenanceState.OFF, resp.getMaintenanceState());
        foundHosts.add(resp.getHostname());
      } else if (resp.getHostname().equals(host2)) {
        Assert.assertEquals(cluster1, resp.getClusterName());
        Assert.assertEquals(2, resp.getHostAttributes().size());
        Assert.assertEquals(MaintenanceState.OFF, resp.getMaintenanceState());
        foundHosts.add(resp.getHostname());
      } else if (resp.getHostname().equals(host3)) {
        Assert.assertEquals(cluster2, resp.getClusterName());
        Assert.assertEquals(3, resp.getHostAttributes().size());
        Assert.assertEquals(MaintenanceState.OFF, resp.getMaintenanceState());
        foundHosts.add(resp.getHostname());
      } else if (resp.getHostname().equals(host4)) {
        //todo: why wouldn't this be null?
        Assert.assertEquals("", resp.getClusterName());
        Assert.assertEquals(4, resp.getHostAttributes().size());
        Assert.assertEquals(null, resp.getMaintenanceState());
        foundHosts.add(resp.getHostname());
      }
    }

    Assert.assertEquals(4, foundHosts.size());

    r = new HostRequest(host1, null);
    resps = HostResourceProviderTest.getHosts(controller, Collections.singleton(r));
    Assert.assertEquals(1, resps.size());
    HostResponse resp = resps.iterator().next();
    Assert.assertEquals(host1, resp.getHostname());
    Assert.assertEquals(cluster1, resp.getClusterName());
    Assert.assertEquals(MaintenanceState.OFF, resp.getMaintenanceState());
    Assert.assertEquals(2, resp.getHostAttributes().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