@Test public void testGetHostsForServiceComponent() { Cluster cluster = createNiceMock(Cluster.class); String service = "SERVICE"; String component = "COMPONENT"; List<ServiceComponentHost> components = new ArrayList<ServiceComponentHost>(); ServiceComponentHost component1 = createNiceMock(ServiceComponentHost.class); expect(component1.getHostName()).andReturn("host1"); components.add(component1); ServiceComponentHost component2 = createNiceMock(ServiceComponentHost.class); expect(component2.getHostName()).andReturn("host2"); components.add(component2); expect(cluster.getServiceComponentHosts(service,component)).andReturn(components); replay(cluster, component1, component2); ClusterImpl clusterImpl = new ClusterImpl(cluster); List<String> hosts = clusterImpl.getHostsForServiceComponent(service,component); Assert.assertEquals(2, hosts.size()); Assert.assertEquals("host1",hosts.get(0)); Assert.assertEquals("host2",hosts.get(1)); verify(cluster, component1, component2); }
@Override public List<String> getHostsForServiceComponent(String serviceName, String componentName){ List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(serviceName, componentName); List<String> hosts = new ArrayList<String>(); for (ServiceComponentHost serviceComponentHost : serviceComponentHosts) { hosts.add(serviceComponentHost.getHostName()); } return hosts; }
ClusterImpl implements Cluster { @Override public List<String> getHostsForServiceComponent(String serviceName, String componentName){ List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(serviceName, componentName); List<String> hosts = new ArrayList<String>(); for (ServiceComponentHost serviceComponentHost : serviceComponentHosts) { hosts.add(serviceComponentHost.getHostName()); } return hosts; } }
ClusterImpl implements Cluster { @Override public List<String> getHostsForServiceComponent(String serviceName, String componentName){ List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(serviceName, componentName); List<String> hosts = new ArrayList<String>(); for (ServiceComponentHost serviceComponentHost : serviceComponentHosts) { hosts.add(serviceComponentHost.getHostName()); } return hosts; } ClusterImpl(org.apache.ambari.server.state.Cluster cluster); }
ClusterImpl implements Cluster { @Override public List<String> getHostsForServiceComponent(String serviceName, String componentName){ List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(serviceName, componentName); List<String> hosts = new ArrayList<String>(); for (ServiceComponentHost serviceComponentHost : serviceComponentHosts) { hosts.add(serviceComponentHost.getHostName()); } return hosts; } ClusterImpl(org.apache.ambari.server.state.Cluster cluster); @Override String getName(); @Override String getConfigurationValue(String type, String key); @Override Map<String, String> getConfigByType(String type); @Override List<String> getHostsForServiceComponent(String serviceName, String componentName); }
ClusterImpl implements Cluster { @Override public List<String> getHostsForServiceComponent(String serviceName, String componentName){ List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(serviceName, componentName); List<String> hosts = new ArrayList<String>(); for (ServiceComponentHost serviceComponentHost : serviceComponentHosts) { hosts.add(serviceComponentHost.getHostName()); } return hosts; } ClusterImpl(org.apache.ambari.server.state.Cluster cluster); @Override String getName(); @Override String getConfigurationValue(String type, String key); @Override Map<String, String> getConfigByType(String type); @Override List<String> getHostsForServiceComponent(String serviceName, String componentName);  }