use of com.alibaba.nacos.api.naming.remote.request.SubscribeServiceRequest in project nacos by alibaba.
the class NamingGrpcClientProxy method doUnsubscribe.
/**
* Execute unsubscribe operation.
*
* @param serviceName service name
* @param groupName group name
* @param clusters clusters, current only support subscribe all clusters, maybe deprecated
* @throws NacosException nacos exception
*/
public void doUnsubscribe(String serviceName, String groupName, String clusters) throws NacosException {
SubscribeServiceRequest request = new SubscribeServiceRequest(namespaceId, serviceName, groupName, clusters, false);
requestToServer(request, SubscribeServiceResponse.class);
redoService.removeSubscriberForRedo(serviceName, groupName, clusters);
}
use of com.alibaba.nacos.api.naming.remote.request.SubscribeServiceRequest in project nacos by alibaba.
the class NamingGrpcClientProxyTest method testUnsubscribe.
@Test
public void testUnsubscribe() throws Exception {
SubscribeServiceResponse res = new SubscribeServiceResponse();
ServiceInfo info = new ServiceInfo(GROUP_NAME + "@@" + SERVICE_NAME + "@@" + CLUSTERS);
res.setServiceInfo(info);
when(this.rpcClient.request(any())).thenReturn(res);
client.unsubscribe(SERVICE_NAME, GROUP_NAME, CLUSTERS);
verify(this.rpcClient, times(1)).request(argThat(request -> {
if (request instanceof SubscribeServiceRequest) {
SubscribeServiceRequest request1 = (SubscribeServiceRequest) request;
// not subscribe
return !request1.isSubscribe();
}
return false;
}));
}
use of com.alibaba.nacos.api.naming.remote.request.SubscribeServiceRequest in project nacos by alibaba.
the class NamingGrpcClientProxy method doSubscribe.
/**
* Execute subscribe operation.
*
* @param serviceName service name
* @param groupName group name
* @param clusters clusters, current only support subscribe all clusters, maybe deprecated
* @return current service info of subscribe service
* @throws NacosException nacos exception
*/
public ServiceInfo doSubscribe(String serviceName, String groupName, String clusters) throws NacosException {
SubscribeServiceRequest request = new SubscribeServiceRequest(namespaceId, groupName, serviceName, clusters, true);
SubscribeServiceResponse response = requestToServer(request, SubscribeServiceResponse.class);
redoService.subscriberRegistered(serviceName, groupName, clusters);
return response.getServiceInfo();
}
use of com.alibaba.nacos.api.naming.remote.request.SubscribeServiceRequest 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());
}
Aggregations