Search in sources :

Example 11 with RequestMeta

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

the class ConfigChangeBatchListenRequestHandlerTest method setUp.

@Before
public void setUp() {
    configQueryRequestHandler = new ConfigChangeBatchListenRequestHandler();
    ReflectionTestUtils.setField(configQueryRequestHandler, "configChangeListenContext", configChangeListenContext);
    requestMeta = new RequestMeta();
    requestMeta.setClientIp("1.1.1.1");
    Mockito.mockStatic(ConfigCacheService.class);
}
Also used : RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) Before(org.junit.Before)

Example 12 with RequestMeta

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

the class ConfigRemoveRequestHandlerTest method testHandle.

@Test
public void testHandle() {
    ConfigRemoveRequest configRemoveRequest = new ConfigRemoveRequest();
    configRemoveRequest.setRequestId("requestId");
    configRemoveRequest.setGroup("group");
    configRemoveRequest.setDataId("dataId");
    configRemoveRequest.setTenant("tenant");
    RequestMeta meta = new RequestMeta();
    meta.setClientIp("1.1.1.1");
    try {
        ConfigRemoveResponse configRemoveResponse = configRemoveRequestHandler.handle(configRemoveRequest, meta);
        Assert.assertEquals(ResponseCode.SUCCESS.getCode(), configRemoveResponse.getResultCode());
    } catch (NacosException e) {
        e.printStackTrace();
    }
}
Also used : ConfigRemoveRequest(com.alibaba.nacos.api.config.remote.request.ConfigRemoveRequest) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) ConfigRemoveResponse(com.alibaba.nacos.api.config.remote.response.ConfigRemoveResponse) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 13 with RequestMeta

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

the class InternalConfigChangeNotifier method loadLocalConfigLikeClient.

private String loadLocalConfigLikeClient(String dataId, String group) throws NacosException {
    ConfigQueryRequest queryRequest = new ConfigQueryRequest();
    queryRequest.setDataId(dataId);
    queryRequest.setGroup(group);
    RequestMeta meta = new RequestMeta();
    meta.setClientIp(NetUtils.localIP());
    ConfigQueryResponse handle = configQueryRequestHandler.handle(queryRequest, meta);
    if (handle == null) {
        throw new NacosException(NacosException.SERVER_ERROR, "load local config fail,response is null");
    }
    if (handle.isSuccess()) {
        return handle.getContent();
    } else if (handle.getErrorCode() == ConfigQueryResponse.CONFIG_NOT_FOUND) {
        return null;
    } else {
        Loggers.REMOTE.error("connection limit rule load fail,errorCode={}", handle.getErrorCode());
        throw new NacosException(NacosException.SERVER_ERROR, "load local config fail,error code=" + handle.getErrorCode());
    }
}
Also used : RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) ConfigQueryResponse(com.alibaba.nacos.api.config.remote.response.ConfigQueryResponse) ConfigQueryRequest(com.alibaba.nacos.api.config.remote.request.ConfigQueryRequest) NacosException(com.alibaba.nacos.api.exception.NacosException)

Example 14 with RequestMeta

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

the class GrpcRequestAcceptorTest method testHandleRequestError.

@Test
public void testHandleRequestError() {
    ApplicationUtils.setStarted(true);
    Mockito.when(requestHandlerRegistry.getByRequestType(Mockito.anyString())).thenReturn(mockHandler);
    Mockito.when(connectionManager.checkValid(Mockito.any())).thenReturn(true);
    RequestMeta metadata = new RequestMeta();
    metadata.setClientIp("127.0.0.1");
    metadata.setConnectionId(connectId);
    InstanceRequest instanceRequest = new InstanceRequest();
    Payload payload = GrpcUtils.convert(instanceRequest, metadata);
    StreamObserver<Payload> streamObserver = new StreamObserver<Payload>() {

        @Override
        public void onNext(Payload payload) {
            System.out.println("Receive data from server: " + payload);
            Object res = GrpcUtils.parse(payload);
            Assert.assertTrue(res instanceof ErrorResponse);
            ErrorResponse errorResponse = (ErrorResponse) res;
            Assert.assertEquals(errorResponse.getErrorCode(), NacosException.SERVER_ERROR);
        }

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

        @Override
        public void onCompleted() {
            System.out.println("complete");
        }
    };
    streamStub.request(payload, streamObserver);
    ApplicationUtils.setStarted(false);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) Payload(com.alibaba.nacos.api.grpc.auto.Payload) InstanceRequest(com.alibaba.nacos.api.naming.remote.request.InstanceRequest) ErrorResponse(com.alibaba.nacos.api.remote.response.ErrorResponse) Test(org.junit.Test)

Example 15 with RequestMeta

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

the class GrpcRequestAcceptorTest method testConnectionNotRegister.

@Test
public void testConnectionNotRegister() {
    ApplicationUtils.setStarted(true);
    Mockito.when(requestHandlerRegistry.getByRequestType(Mockito.anyString())).thenReturn(mockHandler);
    Mockito.when(connectionManager.checkValid(Mockito.any())).thenReturn(false);
    RequestMeta metadata = new RequestMeta();
    metadata.setClientIp("127.0.0.1");
    metadata.setConnectionId(connectId);
    InstanceRequest instanceRequest = new InstanceRequest();
    instanceRequest.setRequestId(requestId);
    Payload request = GrpcUtils.convert(instanceRequest, metadata);
    StreamObserver<Payload> streamObserver = new StreamObserver<Payload>() {

        @Override
        public void onNext(Payload payload) {
            System.out.println("Receive data from server: " + payload);
            Object res = GrpcUtils.parse(payload);
            Assert.assertTrue(res instanceof ErrorResponse);
            ErrorResponse errorResponse = (ErrorResponse) res;
            Assert.assertEquals(errorResponse.getErrorCode(), NacosException.UN_REGISTER);
        }

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

        @Override
        public void onCompleted() {
            System.out.println("complete");
        }
    };
    streamStub.request(request, streamObserver);
    ApplicationUtils.setStarted(false);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) Payload(com.alibaba.nacos.api.grpc.auto.Payload) InstanceRequest(com.alibaba.nacos.api.naming.remote.request.InstanceRequest) ErrorResponse(com.alibaba.nacos.api.remote.response.ErrorResponse) 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