use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingHttpClientProxyTest method testCreateService.
@Test
public void testCreateService() 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);
// when
clientProxy.createService(new Service(), new NoneSelector());
// then
verify(nacosRestTemplate, times(1)).exchangeForm(endsWith(UtilAndComs.nacosUrlService), any(), any(), any(), eq(HttpMethod.POST), any());
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingHttpClientProxyTest method testUnsubscribe.
@Test
public void testUnsubscribe() throws Exception {
// TODO thrown.expect(UnsupportedOperationException.class);
// 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
clientProxy.unsubscribe(serviceName, groupName, clusters);
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class FailoverReactorTest method testIsFailoverSwitch.
@Test
public void testIsFailoverSwitch() throws NacosException {
ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
Mockito.when(holder.getServiceInfoMap()).thenReturn(new HashMap<>());
FailoverReactor failoverReactor = new FailoverReactor(holder, "/tmp");
Assert.assertFalse(failoverReactor.isFailoverSwitch());
failoverReactor.shutdown();
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder 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();
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class FailoverReactorTest method testAddDay.
@Test
public void testAddDay() throws NacosException {
ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
Mockito.when(holder.getServiceInfoMap()).thenReturn(new HashMap<>());
FailoverReactor failoverReactor = new FailoverReactor(holder, "/tmp");
Date date = new Date();
Date actual = failoverReactor.addDay(date, 1);
Assert.assertEquals(date.getTime() + 24 * 60 * 60 * 1000, actual.getTime());
failoverReactor.shutdown();
}
Aggregations