Search in sources :

Example 21 with RequestMeta

use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.

the class GrpcBiStreamRequestAcceptorTest method testConnectionSetupRequest.

@Test
public void testConnectionSetupRequest() {
    StreamObserver<Payload> streamObserver = new StreamObserver<Payload>() {

        @Override
        public void onNext(Payload payload) {
            System.out.println("Receive data from server, data: " + payload);
            Assert.assertNotNull(payload);
            ConnectResetRequest connectResetRequest = (ConnectResetRequest) GrpcUtils.parse(payload);
            Response response = new ConnectResetResponse();
            response.setRequestId(connectResetRequest.getRequestId());
            Payload res = GrpcUtils.convert(response);
            payloadStreamObserver.onNext(res);
            payloadStreamObserver.onCompleted();
        }

        @Override
        public void onError(Throwable throwable) {
            Assert.fail(throwable.getMessage());
        }

        @Override
        public void onCompleted() {
            System.out.println("complete");
        }
    };
    payloadStreamObserver = streamStub.requestBiStream(streamObserver);
    RequestMeta metadata = new RequestMeta();
    metadata.setClientIp("127.0.0.1");
    metadata.setConnectionId(connectId);
    ConnectionSetupRequest connectionSetupRequest = new ConnectionSetupRequest();
    connectionSetupRequest.setRequestId(requestId);
    connectionSetupRequest.setClientVersion("2.0.3");
    Payload payload = GrpcUtils.convert(connectionSetupRequest, metadata);
    payloadStreamObserver.onNext(payload);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ConnectResetResponse(com.alibaba.nacos.api.remote.response.ConnectResetResponse) Response(com.alibaba.nacos.api.remote.response.Response) ConnectResetResponse(com.alibaba.nacos.api.remote.response.ConnectResetResponse) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) Payload(com.alibaba.nacos.api.grpc.auto.Payload) ConnectionSetupRequest(com.alibaba.nacos.api.remote.request.ConnectionSetupRequest) ConnectResetRequest(com.alibaba.nacos.api.remote.request.ConnectResetRequest) Test(org.junit.Test)

Example 22 with RequestMeta

use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.

the class GrpcRequestFilterTest method testFilter.

@Test
public void testFilter() throws NacosException {
    Mockito.when(upgradeJudgement.isUseGrpcFeatures()).thenReturn(true).thenReturn(false);
    Response response = grpcRequestFilter.filter(new InstanceRequest(), new RequestMeta(), InstanceRequestHandler.class);
    Assert.assertNull(response);
    try {
        grpcRequestFilter.filter(new InstanceRequest(), new RequestMeta(), InstanceRequestHandler.class);
    } catch (Exception e) {
        Assert.assertTrue(e instanceof NacosException);
    }
}
Also used : Response(com.alibaba.nacos.api.remote.response.Response) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) InstanceRequest(com.alibaba.nacos.api.naming.remote.request.InstanceRequest) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 23 with RequestMeta

use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.

the class DistroDataRequestHandlerTest method testHandle.

@Test
public void testHandle() throws NacosException {
    Mockito.when(distroProtocol.onVerify(Mockito.any(), Mockito.anyString())).thenReturn(false);
    DistroDataRequest distroDataRequest = new DistroDataRequest();
    distroDataRequest.setDataOperation(VERIFY);
    RequestMeta requestMeta = new RequestMeta();
    DistroDataResponse response = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
    Assert.assertEquals(response.getErrorCode(), ResponseCode.FAIL.getCode());
    DistroData distroData = new DistroData();
    Mockito.when(distroProtocol.onSnapshot(Mockito.any())).thenReturn(distroData);
    distroDataRequest.setDataOperation(SNAPSHOT);
    DistroDataResponse response1 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
    Assert.assertEquals(response1.getDistroData(), distroData);
    distroDataRequest.setDataOperation(DELETE);
    Mockito.when(distroProtocol.onReceive(Mockito.any())).thenReturn(false);
    DistroDataResponse response2 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
    Assert.assertEquals(response2.getErrorCode(), ResponseCode.FAIL.getCode());
    distroDataRequest.setDataOperation(QUERY);
    Mockito.when(distroProtocol.onQuery(Mockito.any())).thenReturn(distroData);
    distroDataRequest.setDistroData(new DistroData());
    DistroDataResponse response3 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
    Assert.assertEquals(response3.getDistroData(), distroData);
    distroDataRequest.setDataOperation(ADD);
    DistroDataResponse response4 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
    Assert.assertNull(response4.getDistroData());
}
Also used : DistroDataRequest(com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) DistroDataResponse(com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData) Test(org.junit.Test)

Example 24 with RequestMeta

use of com.alibaba.nacos.api.remote.request.RequestMeta 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"));
}
Also used : RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) ServiceListRequest(com.alibaba.nacos.api.naming.remote.request.ServiceListRequest) ServiceListResponse(com.alibaba.nacos.api.naming.remote.response.ServiceListResponse) Test(org.junit.Test)

Example 25 with RequestMeta

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

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