Search in sources :

Example 1 with HealthCheckRequest

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

the class ClusterRpcClientProxyTest method testSendRequest.

@Test
public void testSendRequest() {
    Member member = new Member();
    member.setIp("1.1.1.1");
    try {
        Response response = clusterRpcClientProxy.sendRequest(member, new HealthCheckRequest());
    } catch (NacosException e) {
        Assert.assertEquals(-401, e.getErrCode());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : Response(com.alibaba.nacos.api.remote.response.Response) HealthCheckRequest(com.alibaba.nacos.api.remote.request.HealthCheckRequest) Member(com.alibaba.nacos.core.cluster.Member) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 2 with HealthCheckRequest

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

the class ClusterRpcClientProxyTest method testAsyncRequest.

@Test
public void testAsyncRequest() {
    RequestCallBack requestCallBack = new RequestCallBack() {

        @Override
        public Executor getExecutor() {
            return null;
        }

        @Override
        public long getTimeout() {
            return 0;
        }

        @Override
        public void onResponse(Response response) {
        }

        @Override
        public void onException(Throwable e) {
            Assert.assertTrue(e instanceof NacosException);
        }
    };
    Member member = new Member();
    member.setIp("1.1.1.1");
    try {
        clusterRpcClientProxy.asyncRequest(member, new HealthCheckRequest(), requestCallBack);
    } catch (NacosException e) {
        Assert.assertEquals(500, e.getErrCode());
    }
}
Also used : Response(com.alibaba.nacos.api.remote.response.Response) RequestCallBack(com.alibaba.nacos.api.remote.RequestCallBack) HealthCheckRequest(com.alibaba.nacos.api.remote.request.HealthCheckRequest) Member(com.alibaba.nacos.core.cluster.Member) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 3 with HealthCheckRequest

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

the class RemoteRequestAuthFilterTest method testFilter.

@Test
public void testFilter() {
    Mockito.when(authConfigs.isAuthEnabled()).thenReturn(true);
    Request healthCheckRequest = new HealthCheckRequest();
    try {
        Response healthCheckResponse = remoteRequestAuthFilter.filter(healthCheckRequest, new RequestMeta(), MockRequestHandler.class);
        Assert.assertNull(healthCheckResponse);
    } catch (NacosException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : Response(com.alibaba.nacos.api.remote.response.Response) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) HealthCheckRequest(com.alibaba.nacos.api.remote.request.HealthCheckRequest) Request(com.alibaba.nacos.api.remote.request.Request) HealthCheckRequest(com.alibaba.nacos.api.remote.request.HealthCheckRequest) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 4 with HealthCheckRequest

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

the class GrpcRequestAcceptorTest method testHandleRequestSuccess.

@Test
public void testHandleRequestSuccess() {
    ApplicationUtils.setStarted(true);
    Mockito.when(requestHandlerRegistry.getByRequestType(Mockito.anyString())).thenReturn(mockHandler);
    Mockito.when(connectionManager.checkValid(Mockito.any())).thenReturn(true);
    String ip = "1.1.1.1";
    ConnectionMeta connectionMeta = new ConnectionMeta(connectId, ip, ip, 8888, 9848, "GRPC", "", "", new HashMap<>());
    Connection connection = new GrpcConnection(connectionMeta, null, null);
    Mockito.when(connectionManager.getConnection(Mockito.any())).thenReturn(connection);
    RequestMeta metadata = new RequestMeta();
    metadata.setClientIp("127.0.0.1");
    metadata.setConnectionId(connectId);
    HealthCheckRequest mockRequest = new HealthCheckRequest();
    Payload payload = GrpcUtils.convert(mockRequest, 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 HealthCheckResponse);
        }

        @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) HealthCheckResponse(com.alibaba.nacos.api.remote.response.HealthCheckResponse) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) Connection(com.alibaba.nacos.core.remote.Connection) ConnectionMeta(com.alibaba.nacos.core.remote.ConnectionMeta) Payload(com.alibaba.nacos.api.grpc.auto.Payload) HealthCheckRequest(com.alibaba.nacos.api.remote.request.HealthCheckRequest) Test(org.junit.Test)

Aggregations

HealthCheckRequest (com.alibaba.nacos.api.remote.request.HealthCheckRequest)4 Test (org.junit.Test)4 NacosException (com.alibaba.nacos.api.exception.NacosException)3 Response (com.alibaba.nacos.api.remote.response.Response)3 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)2 Member (com.alibaba.nacos.core.cluster.Member)2 Payload (com.alibaba.nacos.api.grpc.auto.Payload)1 RequestCallBack (com.alibaba.nacos.api.remote.RequestCallBack)1 Request (com.alibaba.nacos.api.remote.request.Request)1 HealthCheckResponse (com.alibaba.nacos.api.remote.response.HealthCheckResponse)1 Connection (com.alibaba.nacos.core.remote.Connection)1 ConnectionMeta (com.alibaba.nacos.core.remote.ConnectionMeta)1 StreamObserver (io.grpc.stub.StreamObserver)1