Search in sources :

Example 1 with HealthCheckResponse

use of com.alibaba.nacos.api.remote.response.HealthCheckResponse 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)

Example 2 with HealthCheckResponse

use of com.alibaba.nacos.api.remote.response.HealthCheckResponse in project nacos by alibaba.

the class HealthCheckRequestHandlerTest method testHandle.

@Test
public void testHandle() {
    HealthCheckRequestHandler handler = new HealthCheckRequestHandler();
    HealthCheckResponse response = handler.handle(null, null);
    Assert.assertNotNull(response);
}
Also used : HealthCheckResponse(com.alibaba.nacos.api.remote.response.HealthCheckResponse) Test(org.junit.Test)

Aggregations

HealthCheckResponse (com.alibaba.nacos.api.remote.response.HealthCheckResponse)2 Test (org.junit.Test)2 Payload (com.alibaba.nacos.api.grpc.auto.Payload)1 HealthCheckRequest (com.alibaba.nacos.api.remote.request.HealthCheckRequest)1 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)1 Connection (com.alibaba.nacos.core.remote.Connection)1 ConnectionMeta (com.alibaba.nacos.core.remote.ConnectionMeta)1 StreamObserver (io.grpc.stub.StreamObserver)1