Search in sources :

Example 1 with QueryServiceResponse

use of com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse in project nacos by alibaba.

the class NamingGrpcClientProxyTest method testQueryInstancesOfService.

@Test
public void testQueryInstancesOfService() throws Exception {
    QueryServiceResponse res = new QueryServiceResponse();
    ServiceInfo info = new ServiceInfo(GROUP_NAME + "@@" + SERVICE_NAME + "@@" + CLUSTERS);
    res.setServiceInfo(info);
    when(this.rpcClient.request(any())).thenReturn(res);
    ServiceInfo actual = client.queryInstancesOfService(SERVICE_NAME, GROUP_NAME, CLUSTERS, 0, false);
    Assert.assertEquals(info, actual);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) QueryServiceResponse(com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse) Test(org.junit.Test)

Example 2 with QueryServiceResponse

use of com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse in project nacos by alibaba.

the class NamingGrpcClientProxy method queryInstancesOfService.

@Override
public ServiceInfo queryInstancesOfService(String serviceName, String groupName, String clusters, int udpPort, boolean healthyOnly) throws NacosException {
    ServiceQueryRequest request = new ServiceQueryRequest(namespaceId, serviceName, groupName);
    request.setCluster(clusters);
    request.setHealthyOnly(healthyOnly);
    request.setUdpPort(udpPort);
    QueryServiceResponse response = requestToServer(request, QueryServiceResponse.class);
    return response.getServiceInfo();
}
Also used : QueryServiceResponse(com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse) ServiceQueryRequest(com.alibaba.nacos.api.naming.remote.request.ServiceQueryRequest)

Example 3 with QueryServiceResponse

use of com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse 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)

Aggregations

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