Search in sources :

Example 6 with ServiceInfo

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);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Instance(com.alibaba.nacos.api.naming.pojo.Instance) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with ServiceInfo

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);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Test(org.junit.Test)

Example 8 with 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());
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) EventListener(com.alibaba.nacos.api.naming.listener.EventListener) Test(org.junit.Test)

Example 9 with ServiceInfo

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);
}
Also used : PushDataWrapper(com.alibaba.nacos.naming.push.v2.PushDataWrapper) ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) Before(org.junit.Before)

Example 10 with ServiceInfo

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);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Instance(com.alibaba.nacos.api.naming.pojo.Instance) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)74 Test (org.junit.Test)44 Instance (com.alibaba.nacos.api.naming.pojo.Instance)29 ArrayList (java.util.ArrayList)17 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)12 Properties (java.util.Properties)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 NacosException (com.alibaba.nacos.api.exception.NacosException)8 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)8 Before (org.junit.Before)8 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)7 Field (java.lang.reflect.Field)6 HashSet (java.util.HashSet)5 EventListener (com.alibaba.nacos.api.naming.listener.EventListener)4 SubscribeServiceResponse (com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse)4 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)4 HashMap (java.util.HashMap)4 QueryServiceResponse (com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse)3 Secured (com.alibaba.nacos.auth.annotation.Secured)3 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)3