use of com.alibaba.nacos.api.naming.remote.response.ServiceListResponse in project nacos by alibaba.
the class NamingGrpcClientProxyTest method testGetServiceList.
@Test
public void testGetServiceList() throws Exception {
ServiceListResponse res = new ServiceListResponse();
List<String> services = Arrays.asList("service1", "service2");
res.setServiceNames(services);
res.setCount(5);
when(this.rpcClient.request(any())).thenReturn(res);
AbstractSelector selector = new NoneSelector();
ListView<String> serviceList = client.getServiceList(1, 10, GROUP_NAME, selector);
Assert.assertEquals(5, serviceList.getCount());
Assert.assertEquals(services, serviceList.getData());
}
use of com.alibaba.nacos.api.naming.remote.response.ServiceListResponse in project nacos by alibaba.
the class NamingGrpcClientProxy method getServiceList.
@Override
public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
ServiceListRequest request = new ServiceListRequest(namespaceId, groupName, pageNo, pageSize);
if (selector != null) {
if (SelectorType.valueOf(selector.getType()) == SelectorType.label) {
request.setSelector(JacksonUtils.toJson(selector));
}
}
ServiceListResponse response = requestToServer(request, ServiceListResponse.class);
ListView<String> result = new ListView<String>();
result.setCount(response.getCount());
result.setData(response.getServiceNames());
return result;
}
use of com.alibaba.nacos.api.naming.remote.response.ServiceListResponse in project nacos by alibaba.
the class ServiceListRequestHandler method handle.
@Override
@Secured(action = ActionTypes.READ)
public ServiceListResponse handle(ServiceListRequest request, RequestMeta meta) throws NacosException {
Collection<Service> serviceSet = ServiceManager.getInstance().getSingletons(request.getNamespace());
ServiceListResponse result = ServiceListResponse.buildSuccessResponse(0, new LinkedList<>());
if (!serviceSet.isEmpty()) {
Collection<String> serviceNameSet = selectServiceWithGroupName(serviceSet, request.getGroupName());
// TODO select service by selector
List<String> serviceNameList = ServiceUtil.pageServiceName(request.getPageNo(), request.getPageSize(), serviceNameSet);
result.setCount(serviceNameSet.size());
result.setServiceNames(serviceNameList);
}
return result;
}
use of com.alibaba.nacos.api.naming.remote.response.ServiceListResponse in project nacos by alibaba.
the class ServiceListRequestHandlerTest method testHandle.
@Test
public void testHandle() throws NacosException {
ServiceListRequest serviceListRequest = new ServiceListRequest();
serviceListRequest.setNamespace("A");
serviceListRequest.setPageNo(1);
serviceListRequest.setPageSize(10);
serviceListRequest.setGroupName("B");
ServiceListRequestHandler serviceListRequestHandler = new ServiceListRequestHandler();
ServiceListResponse serviceListResponse = serviceListRequestHandler.handle(serviceListRequest, new RequestMeta());
Assert.assertEquals(serviceListResponse.getCount(), 1);
Assert.assertTrue(serviceListResponse.getServiceNames().contains("C"));
}
Aggregations