Search in sources :

Example 1 with ClientOperationService

use of com.alibaba.nacos.naming.core.v2.service.ClientOperationService in project nacos by alibaba.

the class InstanceOperatorClientImplTest method testListInstance.

@Test
public void testListInstance() {
    Mockito.when(pushService.canEnablePush(Mockito.anyString())).thenReturn(true);
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setGroupName("DEFAULT_GROUP");
    serviceInfo.setName("B");
    Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
    ServiceMetadata metadata = new ServiceMetadata();
    Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(metadata));
    Subscriber subscriber = new Subscriber("2.2.2.2", "", "app", "1.1.1.1", "A", "B", 8848);
    instanceOperatorClient.listInstance("A", "B", subscriber, "C", true);
    Mockito.verify(clientOperationService).subscribeService(Mockito.any(), Mockito.any(), Mockito.anyString());
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) Test(org.junit.Test)

Example 2 with ClientOperationService

use of com.alibaba.nacos.naming.core.v2.service.ClientOperationService 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)

Aggregations

ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)2 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)2 Test (org.junit.Test)2 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 SubscribeServiceRequest (com.alibaba.nacos.api.naming.remote.request.SubscribeServiceRequest)1 SubscribeServiceResponse (com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse)1 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)1 Subscriber (com.alibaba.nacos.naming.pojo.Subscriber)1