Search in sources :

Example 1 with ConnectResetResponse

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

Aggregations

Payload (com.alibaba.nacos.api.grpc.auto.Payload)1 ConnectResetRequest (com.alibaba.nacos.api.remote.request.ConnectResetRequest)1 ConnectionSetupRequest (com.alibaba.nacos.api.remote.request.ConnectionSetupRequest)1 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)1 ConnectResetResponse (com.alibaba.nacos.api.remote.response.ConnectResetResponse)1 Response (com.alibaba.nacos.api.remote.response.Response)1 StreamObserver (io.grpc.stub.StreamObserver)1 Test (org.junit.Test)1