use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingHttpClientProxyTest method testGetBeatReactor.
@Test
public void testGetBeatReactor() throws Exception {
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);
String namespaceId = "aaa";
NamingHttpClientProxy clientProxy = new NamingHttpClientProxy(namespaceId, proxy, mgr, props, holder);
BeatReactor mockBeatReactor = mock(BeatReactor.class);
final Field mockBeatReactorField = NamingHttpClientProxy.class.getDeclaredField("beatReactor");
mockBeatReactorField.setAccessible(true);
mockBeatReactorField.set(clientProxy, mockBeatReactor);
// when
BeatReactor beatReactor = clientProxy.getBeatReactor();
// then
Assert.assertEquals(mockBeatReactor, beatReactor);
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingHttpClientProxyTest method testSendBeat.
@Test
public void testSendBeat() 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);
BeatInfo beat = new BeatInfo();
// when
clientProxy.sendBeat(beat, true);
// then
verify(nacosRestTemplate, times(1)).exchangeForm(endsWith("/instance/beat"), any(), any(), any(), eq(HttpMethod.PUT), any());
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingHttpClientProxyTest method testUpdateInstance.
@Test
public void testUpdateInstance() throws Exception {
// given
NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
HttpRestResult<Object> a = new HttpRestResult<Object>();
a.setData("127.0.0.1:8848");
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";
Instance instance = new Instance();
// when
clientProxy.updateInstance(serviceName, groupName, instance);
// then
verify(nacosRestTemplate, times(1)).exchangeForm(any(), any(), any(), any(), eq(HttpMethod.PUT), any());
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingHttpClientProxyTest method testUpdateService.
@Test
public void testUpdateService() 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";
// when
clientProxy.updateService(new Service(), new NoneSelector());
// then
verify(nacosRestTemplate, times(1)).exchangeForm(endsWith(UtilAndComs.nacosUrlService), any(), any(), any(), eq(HttpMethod.PUT), any());
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingHttpClientProxyTest method testReqApi.
@Test
public void testReqApi() throws Exception {
// given
NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
when(nacosRestTemplate.exchangeForm(any(), any(), any(), any(), any(), any())).thenAnswer(invocationOnMock -> {
// return url
HttpRestResult<Object> res = new HttpRestResult<Object>();
res.setData(invocationOnMock.getArgument(0));
res.setCode(200);
return res;
});
SecurityProxy proxy = mock(SecurityProxy.class);
ServerListManager mgr = mock(ServerListManager.class);
when(mgr.getServerList()).thenReturn(Arrays.asList("localhost"));
ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
NamingHttpClientProxy clientProxy = new NamingHttpClientProxy("namespaceId", proxy, mgr, new Properties(), holder);
final Field nacosRestTemplateField = NamingHttpClientProxy.class.getDeclaredField("nacosRestTemplate");
nacosRestTemplateField.setAccessible(true);
nacosRestTemplateField.set(clientProxy, nacosRestTemplate);
String api = "/api";
Map<String, String> params = new HashMap<>();
String method = HttpMethod.GET;
// when
String res = clientProxy.reqApi(api, params, method);
// then
Assert.assertEquals("http://localhost:8848/api", res);
}
Aggregations