use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class BalancerTest method testSelectHost.
@Test
public void testSelectHost() {
List<Instance> hosts = new ArrayList<>();
Instance instance1 = new Instance();
hosts.add(instance1);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setHosts(hosts);
final Instance actual = Balancer.RandomByWeight.selectHost(serviceInfo);
Assert.assertEquals(instance1, actual);
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class BalancerTest method testSelectHostEmpty.
@Test
public void testSelectHostEmpty() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("no host to srv for serviceInfo: null");
ServiceInfo serviceInfo = new ServiceInfo();
Balancer.RandomByWeight.selectHost(serviceInfo);
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class InstancesChangeNotifierTest method testDeregisterListener.
@Test
public void testDeregisterListener() {
String group = "a";
String name = "b";
String clusters = "c";
InstancesChangeNotifier instancesChangeNotifier = new InstancesChangeNotifier();
EventListener listener = Mockito.mock(EventListener.class);
instancesChangeNotifier.registerListener(group, name, clusters, listener);
List<ServiceInfo> subscribeServices = instancesChangeNotifier.getSubscribeServices();
Assert.assertEquals(1, subscribeServices.size());
instancesChangeNotifier.deregisterListener(group, name, clusters, listener);
List<ServiceInfo> subscribeServices2 = instancesChangeNotifier.getSubscribeServices();
Assert.assertEquals(0, subscribeServices2.size());
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class PushExecutorDelegateTest method setUp.
@Before
public void setUp() throws Exception {
serviceMetadata = new ServiceMetadata();
pushdata = new PushDataWrapper(serviceMetadata, new ServiceInfo("G@@S"));
delegate = new PushExecutorDelegate(pushExecutorRpc, pushExecutorUdp);
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class NacosNamingServiceTest method testSelectOneHealthyInstance8.
@Test
public void testSelectOneHealthyInstance8() throws NacosException {
// given
Instance healthyInstance = new Instance();
healthyInstance.setIp("1.1.1.1");
healthyInstance.setPort(1000);
List<Instance> hosts = new ArrayList<>();
hosts.add(healthyInstance);
ServiceInfo infoWithHealthyInstance = new ServiceInfo();
infoWithHealthyInstance.setHosts(hosts);
when(proxy.queryInstancesOfService(anyString(), anyString(), anyString(), anyInt(), anyBoolean())).thenReturn(infoWithHealthyInstance);
String serviceName = "service1";
String groupName = "group1";
List<String> clusterList = Arrays.asList("cluster1", "cluster2");
// when
client.selectOneHealthyInstance(serviceName, groupName, clusterList, false);
// then
verify(proxy, times(1)).queryInstancesOfService(serviceName, groupName, "cluster1,cluster2", 0, false);
}
Aggregations