use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class NamingPushRequestHandlerTest method testRequestReply.
@Test
public void testRequestReply() {
// given
ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
NamingPushRequestHandler handler = new NamingPushRequestHandler(holder);
ServiceInfo info = new ServiceInfo("name", "cluster1");
Request req = NotifySubscriberRequest.buildNotifySubscriberRequest(info);
// when
Response response = handler.requestReply(req);
// then
Assert.assertTrue(response instanceof NotifySubscriberResponse);
verify(holder, times(1)).processServiceInfo(info);
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class NamingHttpClientProxyTest method testQueryInstancesOfService.
@Test
public void testQueryInstancesOfService() throws Exception {
// given
NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
HttpRestResult<Object> a = new HttpRestResult<Object>();
a.setData("");
a.setCode(200);
when(nacosRestTemplate.exchangeForm(any(), any(), any(), any(), any(), any())).thenReturn(a);
SecurityProxy proxy = mock(SecurityProxy.class);
ServerListManager mgr = mock(ServerListManager.class);
when(mgr.getServerList()).thenReturn(Arrays.asList("localhost"));
Properties props = new Properties();
ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
NamingHttpClientProxy clientProxy = new NamingHttpClientProxy("namespaceId", proxy, mgr, props, holder);
final Field nacosRestTemplateField = NamingHttpClientProxy.class.getDeclaredField("nacosRestTemplate");
nacosRestTemplateField.setAccessible(true);
nacosRestTemplateField.set(clientProxy, nacosRestTemplate);
String serviceName = "service1";
String groupName = "group1";
String clusters = "cluster1";
// when
ServiceInfo serviceInfo = clientProxy.queryInstancesOfService(serviceName, groupName, clusters, 0, false);
// then
verify(nacosRestTemplate, times(1)).exchangeForm(any(), any(), any(), any(), eq(HttpMethod.GET), any());
Assert.assertEquals(groupName + "@@" + serviceName, serviceInfo.getName());
Assert.assertEquals(clusters, serviceInfo.getClusters());
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class NamingHttpClientProxyTest method testSubscribe.
@Test
public void testSubscribe() throws Exception {
// given
NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
HttpRestResult<Object> a = new HttpRestResult<Object>();
a.setData("");
a.setCode(200);
when(nacosRestTemplate.exchangeForm(any(), any(), any(), any(), any(), any())).thenReturn(a);
SecurityProxy proxy = mock(SecurityProxy.class);
ServerListManager mgr = mock(ServerListManager.class);
when(mgr.getServerList()).thenReturn(Arrays.asList("localhost"));
Properties props = new Properties();
ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
NamingHttpClientProxy clientProxy = new NamingHttpClientProxy("namespaceId", proxy, mgr, props, holder);
final Field nacosRestTemplateField = NamingHttpClientProxy.class.getDeclaredField("nacosRestTemplate");
nacosRestTemplateField.setAccessible(true);
nacosRestTemplateField.set(clientProxy, nacosRestTemplate);
String groupName = "group1";
String serviceName = "serviceName";
String clusters = "clusters";
// when
ServiceInfo serviceInfo = clientProxy.subscribe(serviceName, groupName, clusters);
// then
verify(nacosRestTemplate, times(1)).exchangeForm(endsWith("/instance/list"), any(), any(), any(), eq(HttpMethod.GET), any());
Assert.assertEquals(groupName + "@@" + serviceName, serviceInfo.getName());
Assert.assertEquals(clusters, serviceInfo.getClusters());
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class NacosNamingServiceTest method testSelectOneHealthyInstance3.
@Test
public void testSelectOneHealthyInstance3() 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";
// when
client.selectOneHealthyInstance(serviceName, false);
// then
verify(proxy, times(1)).queryInstancesOfService(serviceName, Constants.DEFAULT_GROUP, "", 0, false);
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class NacosNamingServiceTest method testSelectOneHealthyInstance6.
@Test
public void testSelectOneHealthyInstance6() 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";
String groupName = "group1";
List<String> clusterList = Arrays.asList("cluster1", "cluster2");
// when
client.selectOneHealthyInstance(serviceName, groupName, clusterList);
// then
verify(proxy, times(1)).subscribe(serviceName, groupName, "cluster1,cluster2");
}
Aggregations