use of com.alibaba.nacos.client.naming.core.ServerListManager in project nacos by alibaba.
the class NacosNamingMaintainServiceTest method setUp.
@Before
public void setUp() throws Exception {
Properties prop = new Properties();
prop.setProperty(PropertyKeyConst.NAMESPACE, "public");
prop.setProperty("serverAddr", "localhost");
nacosNamingMaintainService = new NacosNamingMaintainService(prop);
serverProxy = mock(NamingHttpClientProxy.class);
serverListManager = mock(ServerListManager.class);
securityProxy = mock(SecurityProxy.class);
executorService = mock(ScheduledExecutorService.class);
Field serverProxyField = NacosNamingMaintainService.class.getDeclaredField("serverProxy");
serverProxyField.setAccessible(true);
serverProxyField.set(nacosNamingMaintainService, serverProxy);
Field serverListManagerField = NacosNamingMaintainService.class.getDeclaredField("serverListManager");
serverListManagerField.setAccessible(true);
serverListManagerField.set(nacosNamingMaintainService, serverListManager);
Field securityProxyFiled = NacosNamingMaintainService.class.getDeclaredField("securityProxy");
securityProxyFiled.setAccessible(true);
securityProxyFiled.set(nacosNamingMaintainService, securityProxy);
Field executorServiceField = NacosNamingMaintainService.class.getDeclaredField("executorService");
executorServiceField.setAccessible(true);
executorServiceField.set(nacosNamingMaintainService, executorService);
}
use of com.alibaba.nacos.client.naming.core.ServerListManager in project nacos by alibaba.
the class NamingHttpClientProxyTest method testServerHealthy.
@Test
public void testServerHealthy() throws Exception {
// given
NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
HttpRestResult<Object> a = new HttpRestResult<Object>();
a.setData("{\"status\":\"UP\"}");
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
boolean serverHealthy = clientProxy.serverHealthy();
// then
verify(nacosRestTemplate, times(1)).exchangeForm(endsWith("/operator/metrics"), any(), any(), any(), eq(HttpMethod.GET), any());
Assert.assertTrue(serverHealthy);
}
use of com.alibaba.nacos.client.naming.core.ServerListManager in project nacos by alibaba.
the class NamingHttpClientProxyTest method testRegisterService.
@Test
public void testRegisterService() 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.registerService(serviceName, groupName, instance);
// then
verify(nacosRestTemplate, times(1)).exchangeForm(any(), any(), any(), any(), any(), any());
}
use of com.alibaba.nacos.client.naming.core.ServerListManager in project nacos by alibaba.
the class NamingHttpClientProxyTest method testGetNamespaceId.
@Test
public void testGetNamespaceId() {
// 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);
String namespaceId = "aaa";
NamingHttpClientProxy clientProxy = new NamingHttpClientProxy(namespaceId, proxy, mgr, props, holder);
// final Field nacosRestTemplateField = NamingHttpClientProxy.class.getDeclaredField("nacosRestTemplate");
// nacosRestTemplateField.setAccessible(true);
// nacosRestTemplateField.set(clientProxy, nacosRestTemplate);
// when
String actualNamespaceId = clientProxy.getNamespaceId();
Assert.assertEquals(namespaceId, actualNamespaceId);
}
use of com.alibaba.nacos.client.naming.core.ServerListManager 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);
}
Aggregations