@Test
  public void testGetServicesWithFilters() throws Exception {
    String cluster1 = getUniqueName();
    String cluster2 = getUniqueName();

    StackId stackId = new StackId("HDP-0.2");
    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId,
        stackId.getStackVersion());

    clusters.addCluster(cluster1, stackId);
    clusters.addCluster(cluster2, stackId);
    Cluster c1 = clusters.getCluster(cluster1);
    Cluster c2 = clusters.getCluster(cluster2);
    c1.setDesiredStackVersion(stackId);
    c2.setDesiredStackVersion(stackId);

    Service s1 = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
    Service s2 = serviceFactory.createNew(c1, "MAPREDUCE", repositoryVersion);
    Service s3 = serviceFactory.createNew(c1, "HBASE", repositoryVersion);
    Service s4 = serviceFactory.createNew(c2, "HIVE", repositoryVersion);
    Service s5 = serviceFactory.createNew(c2, "ZOOKEEPER", repositoryVersion);

    c1.addService(s1);
    c1.addService(s2);
    c1.addService(s3);
    c2.addService(s4);
    c2.addService(s5);

    s1.setDesiredState(State.INSTALLED);
    s2.setDesiredState(State.INSTALLED);
    s4.setDesiredState(State.INSTALLED);

    ServiceRequest r = new ServiceRequest(null, null, null, null, null);
    Set<ServiceResponse> resp;

    try {
      ServiceResourceProviderTest.getServices(controller, Collections.singleton(r));
      fail("Expected failure for invalid request");
    } catch (Exception e) {
      // Expected
    }

    r = new ServiceRequest(c1.getClusterName(), null, null, null, null);
    resp = ServiceResourceProviderTest.getServices(controller, Collections.singleton(r));
    Assert.assertEquals(3, resp.size());

    r = new ServiceRequest(c1.getClusterName(), s2.getName(), null, null, null);
    resp = ServiceResourceProviderTest.getServices(controller, Collections.singleton(r));
    Assert.assertEquals(1, resp.size());
    Assert.assertEquals(s2.getName(), resp.iterator().next().getServiceName());

    try {
      r = new ServiceRequest(c2.getClusterName(), s1.getName(), null, null, null);
      ServiceResourceProviderTest.getServices(controller, Collections.singleton(r));
      fail("Expected failure for invalid service");
    } catch (Exception e) {
      // Expected
    }

    r = new ServiceRequest(c1.getClusterName(), null, null, "INSTALLED", null);
    resp = ServiceResourceProviderTest.getServices(controller, Collections.singleton(r));
    Assert.assertEquals(2, resp.size());

    r = new ServiceRequest(c2.getClusterName(), null, null, "INIT", null);
    resp = ServiceResourceProviderTest.getServices(controller, Collections.singleton(r));
    Assert.assertEquals(1, resp.size());

    ServiceRequest r1, r2, r3;
    r1 = new ServiceRequest(c1.getClusterName(), null, null, "INSTALLED", null);
    r2 = new ServiceRequest(c2.getClusterName(), null, null, "INIT", null);
    r3 = new ServiceRequest(c2.getClusterName(), null, null, "INIT", null);

    Set<ServiceRequest> reqs = new HashSet<>();
    reqs.addAll(Arrays.asList(r1, r2, r3));
    resp = ServiceResourceProviderTest.getServices(controller, reqs);
    Assert.assertEquals(3, resp.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