use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class PushExecuteTaskTest method setUp.
@Before
public void setUp() {
MetricsMonitor.resetAll();
when(indexesManager.getAllClientsSubscribeService(service)).thenReturn(Collections.singletonList(clientId));
when(clientManager.getClient(clientId)).thenReturn(client);
when(client.getSubscriber(service)).thenReturn(subscriber);
when(serviceStorage.getPushData(service)).thenReturn(new ServiceInfo("G@@S"));
when(delayTaskExecuteEngine.getClientManager()).thenReturn(clientManager);
when(delayTaskExecuteEngine.getIndexesManager()).thenReturn(indexesManager);
when(delayTaskExecuteEngine.getPushExecutor()).thenReturn(pushExecutor);
when(delayTaskExecuteEngine.getServiceStorage()).thenReturn(serviceStorage);
when(delayTaskExecuteEngine.getMetadataManager()).thenReturn(metadataManager);
when(metadataManager.getServiceMetadata(service)).thenReturn(Optional.empty());
ApplicationUtils.injectContext(context);
when(context.getBean(TpsMonitorManager.class)).thenReturn(tpsMonitorManager);
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class ServiceQueryRequestHandlerTest method testHandle.
@Test
public void testHandle() throws NacosException {
Instance instance = new Instance();
instance.setIp("1.1.1.1");
List<Instance> instances = Arrays.asList(instance);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setGroupName("A");
serviceInfo.setGroupName("B");
serviceInfo.setName("C");
serviceInfo.setHosts(instances);
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
ServiceMetadata serviceMetadata = new ServiceMetadata();
Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(serviceMetadata));
ServiceQueryRequest serviceQueryRequest = new ServiceQueryRequest();
serviceQueryRequest.setNamespace("A");
serviceQueryRequest.setGroupName("B");
serviceQueryRequest.setServiceName("C");
serviceQueryRequest.setHealthyOnly(false);
QueryServiceResponse queryServiceResponse = serviceQueryRequestHandler.handle(serviceQueryRequest, new RequestMeta());
Assert.assertEquals(queryServiceResponse.getServiceInfo().getName(), "C");
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class SubscribeServiceRequestHandlerTest method testHandle.
@Test
public void testHandle() throws NacosException {
Instance instance = new Instance();
instance.setIp("1.1.1.1");
List<Instance> instances = Arrays.asList(instance);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setGroupName("A");
serviceInfo.setGroupName("B");
serviceInfo.setName("C");
serviceInfo.setHosts(instances);
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
ServiceMetadata serviceMetadata = new ServiceMetadata();
Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(serviceMetadata));
SubscribeServiceRequest subscribeServiceRequest = new SubscribeServiceRequest();
subscribeServiceRequest.setNamespace("A");
subscribeServiceRequest.setGroupName("B");
subscribeServiceRequest.setServiceName("C");
subscribeServiceRequest.setSubscribe(true);
SubscribeServiceResponse subscribeServiceResponse = subscribeServiceRequestHandler.handle(subscribeServiceRequest, new RequestMeta());
Assert.assertEquals(subscribeServiceResponse.getServiceInfo().getName(), "C");
Mockito.verify(clientOperationService).subscribeService(Mockito.any(), Mockito.any(), Mockito.anyString());
subscribeServiceRequest.setSubscribe(false);
subscribeServiceResponse = subscribeServiceRequestHandler.handle(subscribeServiceRequest, new RequestMeta());
Assert.assertEquals(subscribeServiceResponse.getServiceInfo().getName(), "C");
Mockito.verify(clientOperationService).subscribeService(Mockito.any(), Mockito.any(), Mockito.anyString());
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class ServiceStorageTest method testRemoveData.
@Test
public void testRemoveData() throws NoSuchFieldException, IllegalAccessException {
serviceStorage.removeData(SERVICE);
Field serviceClusterIndex = ServiceStorage.class.getDeclaredField("serviceClusterIndex");
serviceClusterIndex.setAccessible(true);
ConcurrentMap<Service, Set<String>> serviceSetConcurrentMap = (ConcurrentMap<Service, Set<String>>) serviceClusterIndex.get(serviceStorage);
Field serviceDataIndexes = ServiceStorage.class.getDeclaredField("serviceDataIndexes");
serviceDataIndexes.setAccessible(true);
ConcurrentMap<Service, ServiceInfo> infoConcurrentMap = (ConcurrentMap<Service, ServiceInfo>) serviceDataIndexes.get(serviceStorage);
Assert.assertEquals(serviceSetConcurrentMap.size(), 0);
Assert.assertEquals(infoConcurrentMap.size(), 0);
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class ServiceStorageTest method testGetData.
@Test
public void testGetData() {
ServiceInfo serviceInfo = serviceStorage.getData(SERVICE);
Assert.assertNotNull(serviceInfo);
}
Aggregations