Search in sources :

Example 66 with ServiceInfo

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);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Before(org.junit.Before)

Example 67 with ServiceInfo

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");
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) QueryServiceResponse(com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse) Instance(com.alibaba.nacos.api.naming.pojo.Instance) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) ServiceQueryRequest(com.alibaba.nacos.api.naming.remote.request.ServiceQueryRequest) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) Test(org.junit.Test)

Example 68 with ServiceInfo

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());
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) SubscribeServiceRequest(com.alibaba.nacos.api.naming.remote.request.SubscribeServiceRequest) Instance(com.alibaba.nacos.api.naming.pojo.Instance) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) SubscribeServiceResponse(com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) Test(org.junit.Test)

Example 69 with ServiceInfo

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);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Field(java.lang.reflect.Field) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentMap(java.util.concurrent.ConcurrentMap) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Test(org.junit.Test)

Example 70 with ServiceInfo

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);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Test(org.junit.Test)

Aggregations

ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)74 Test (org.junit.Test)44 Instance (com.alibaba.nacos.api.naming.pojo.Instance)29 ArrayList (java.util.ArrayList)17 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)12 Properties (java.util.Properties)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 NacosException (com.alibaba.nacos.api.exception.NacosException)8 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)8 Before (org.junit.Before)8 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)7 Field (java.lang.reflect.Field)6 HashSet (java.util.HashSet)5 EventListener (com.alibaba.nacos.api.naming.listener.EventListener)4 SubscribeServiceResponse (com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse)4 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)4 HashMap (java.util.HashMap)4 QueryServiceResponse (com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse)3 Secured (com.alibaba.nacos.auth.annotation.Secured)3 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)3