Search in sources :

Example 41 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class NacosNamingServiceTest method testSelectOneHealthyInstance4.

@Test
public void testSelectOneHealthyInstance4() 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";
    // when
    client.selectOneHealthyInstance(serviceName, groupName, false);
    // then
    verify(proxy, times(1)).queryInstancesOfService(serviceName, groupName, "", 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)

Example 42 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class NacosNamingServiceTest method testSelectOneHealthyInstance1.

@Test
public void testSelectOneHealthyInstance1() 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.subscribe(anyString(), anyString(), anyString())).thenReturn(infoWithHealthyInstance);
    String serviceName = "service1";
    // when
    client.selectOneHealthyInstance(serviceName);
    // then
    verify(proxy, times(1)).subscribe(serviceName, Constants.DEFAULT_GROUP, "");
}
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)

Example 43 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class NacosNamingServiceTest method testSelectOneHealthyInstance7.

@Test
public void testSelectOneHealthyInstance7() 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";
    List<String> clusterList = Arrays.asList("cluster1", "cluster2");
    // when
    client.selectOneHealthyInstance(serviceName, clusterList, false);
    // then
    verify(proxy, times(1)).queryInstancesOfService(serviceName, Constants.DEFAULT_GROUP, "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)

Example 44 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class FailoverReactorTest method testGetService.

@Test
public void testGetService() throws NacosException {
    ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
    Mockito.when(holder.getServiceInfoMap()).thenReturn(new HashMap<>());
    FailoverReactor failoverReactor = new FailoverReactor(holder, "/tmp");
    ServiceInfo info = failoverReactor.getService("aa@@bb");
    Assert.assertEquals(new ServiceInfo("aa@@bb").toString(), info.toString());
    failoverReactor.shutdown();
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) Test(org.junit.Test)

Example 45 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class ServiceInfoHolderTest method testProcessServiceInfo2.

@Test
public void testProcessServiceInfo2() {
    Properties prop = new Properties();
    ServiceInfoHolder holder = new ServiceInfoHolder("aa", prop);
    String json = "{\"groupName\":\"a\",\"name\":\"b\",\"clusters\":\"c\"}";
    ServiceInfo actual = holder.processServiceInfo(json);
    ServiceInfo expect = new ServiceInfo("a@@b@@c");
    expect.setJsonFromServer(json);
    Assert.assertEquals(expect.getKey(), actual.getKey());
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Properties(java.util.Properties) 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