code: @Test public void testGetServiceComponentHostsWithFilters() throws AmbariException {
    clusters.addCluster("c1");
    Cluster c1=clusters.getCluster("c1");
    c1.setDesiredStackVersion(new StackId("HDP-0.2"));
    clusters.addHost("h1");
    clusters.addHost("h2");
    clusters.addHost("h3");
    clusters.getHost("h1").setOsType("centos5");
    clusters.getHost("h2").setOsType("centos5");
    clusters.getHost("h3").setOsType("centos5");
    clusters.getHost("h1").persist();
    clusters.getHost("h2").persist();
    clusters.getHost("h3").persist();
    clusters.mapHostToCluster("h1","c1");
    clusters.mapHostToCluster("h2","c1");
    clusters.mapHostToCluster("h3","c1");
    Service s1=serviceFactory.createNew(c1,"HDFS");
    Service s2=serviceFactory.createNew(c1,"MAPREDUCE");
    Service s3=serviceFactory.createNew(c1,"HBASE");
    c1.addService(s1);
    c1.addService(s2);
    c1.addService(s3);
    s1.setDesiredState(State.INSTALLED);
    s2.setDesiredState(State.INSTALLED);
    s1.persist();
    s2.persist();
    s3.persist();
    ServiceComponent sc1=serviceComponentFactory.createNew(s1,"DATANODE");
    ServiceComponent sc2=serviceComponentFactory.createNew(s1,"NAMENODE");
    ServiceComponent sc3=serviceComponentFactory.createNew(s3,"HBASE_REGIONSERVER");
    s1.addServiceComponent(sc1);
    s1.addServiceComponent(sc2);
    s3.addServiceComponent(sc3);
    sc1.setDesiredState(State.UNINSTALLED);
    sc3.setDesiredState(State.UNINSTALLED);
    sc1.persist();
    sc2.persist();
    sc3.persist();
    ServiceComponentHost sch1=serviceComponentHostFactory.createNew(sc1,"h1",false);
    ServiceComponentHost sch2=serviceComponentHostFactory.createNew(sc1,"h2",false);
    ServiceComponentHost sch3=serviceComponentHostFactory.createNew(sc1,"h3",false);
    ServiceComponentHost sch4=serviceComponentHostFactory.createNew(sc2,"h1",false);
    ServiceComponentHost sch5=serviceComponentHostFactory.createNew(sc2,"h2",false);
    ServiceComponentHost sch6=serviceComponentHostFactory.createNew(sc3,"h3",false);
    sc1.addServiceComponentHost(sch1);
    sc1.addServiceComponentHost(sch2);
    sc1.addServiceComponentHost(sch3);
    sc2.addServiceComponentHost(sch4);
    sc2.addServiceComponentHost(sch5);
    sc3.addServiceComponentHost(sch6);
    sch1.setDesiredState(State.INSTALLED);
    sch2.setDesiredState(State.INIT);
    sch4.setDesiredState(State.INSTALLED);
    sch5.setDesiredState(State.UNINSTALLED);
    sch1.persist();
    sch2.persist();
    sch3.persist();
    sch4.persist();
    sch5.persist();
    sch6.persist();
    ServiceComponentHostRequest r=new ServiceComponentHostRequest(null,null,null,null,null,null);
    try {
      controller.getHostComponents(Collections.singleton(r));
      fail("Expected failure for invalid cluster");
    }
   catch (  Exception e) {
    }
    r=new ServiceComponentHostRequest(c1.getClusterName(),null,null,null,null,null);
    Set<ServiceComponentHostResponse> resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(6,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),s1.getName(),null,null,null,null);
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(5,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),null,sc3.getName(),null,null,null);
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(1,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),null,null,"h2",null,null);
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(2,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),null,null,null,null,State.UNINSTALLED.toString());
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(1,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),s1.getName(),null,null,null,State.INIT.toString());
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(2,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),null,sc3.getName(),null,null,State.INSTALLED.toString());
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(0,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),null,null,"h2",null,State.INIT.toString());
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(1,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),s3.getName(),null,"h1",null,null);
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(0,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),s3.getName(),sc3.getName(),"h3",null,State.INSTALLED.toString());
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(0,resps.size());
    r=new ServiceComponentHostRequest(c1.getClusterName(),s3.getName(),sc3.getName(),"h3",null,null);
    resps=controller.getHostComponents(Collections.singleton(r));
    Assert.assertEquals(1,resps.size());
    ServiceComponentHostRequest r1, r2, r3;
    r1=new ServiceComponentHostRequest(c1.getClusterName(),null,null,"h3",null,null);
    r2=new ServiceComponentHostRequest(c1.getClusterName(),s3.getName(),sc3.getName(),"h2",null,null);
    r3=new ServiceComponentHostRequest(c1.getClusterName(),null,null,"h2",null,null);
    Set<ServiceComponentHostRequest> reqs=new HashSet<ServiceComponentHostRequest>();
    reqs.addAll(Arrays.asList(r1,r2,r3));
    resps=controller.getHostComponents(reqs);
    Assert.assertEquals(4,resps.size());
  }
  