Search in sources :

Example 26 with RequestMeta

use of com.alibaba.nacos.api.remote.request.RequestMeta 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

RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)26 Test (org.junit.Test)20 NacosException (com.alibaba.nacos.api.exception.NacosException)10 Payload (com.alibaba.nacos.api.grpc.auto.Payload)8 StreamObserver (io.grpc.stub.StreamObserver)7 Response (com.alibaba.nacos.api.remote.response.Response)6 InstanceRequest (com.alibaba.nacos.api.naming.remote.request.InstanceRequest)5 ErrorResponse (com.alibaba.nacos.api.remote.response.ErrorResponse)5 Instance (com.alibaba.nacos.api.naming.pojo.Instance)3 ServerCheckRequest (com.alibaba.nacos.api.remote.request.ServerCheckRequest)3 ServerLoaderInfoResponse (com.alibaba.nacos.api.remote.response.ServerLoaderInfoResponse)3 ConfigQueryRequest (com.alibaba.nacos.api.config.remote.request.ConfigQueryRequest)2 ConfigQueryResponse (com.alibaba.nacos.api.config.remote.response.ConfigQueryResponse)2 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)2 RequestCallBack (com.alibaba.nacos.api.remote.RequestCallBack)2 HealthCheckRequest (com.alibaba.nacos.api.remote.request.HealthCheckRequest)2 Request (com.alibaba.nacos.api.remote.request.Request)2 ServerLoaderInfoRequest (com.alibaba.nacos.api.remote.request.ServerLoaderInfoRequest)2 ServerReloadRequest (com.alibaba.nacos.api.remote.request.ServerReloadRequest)2 ServerCheckResponse (com.alibaba.nacos.api.remote.response.ServerCheckResponse)2