Search in sources :

Example 1 with Payload

use of io.grpc.android.integrationtest.nano.Messages.Payload in project grpc-java by grpc.

the class InteropTester method veryLargeRequest.

public void veryLargeRequest() throws Exception {
    if (shouldSkip()) {
        return;
    }
    final SimpleRequest request = new SimpleRequest();
    request.payload = new Payload();
    request.payload.type = Messages.COMPRESSABLE;
    request.payload.body = new byte[unaryPayloadLength()];
    request.responseSize = 10;
    request.responseType = Messages.COMPRESSABLE;
    final SimpleResponse goldenResponse = new SimpleResponse();
    goldenResponse.payload = new Payload();
    goldenResponse.payload.type = Messages.COMPRESSABLE;
    goldenResponse.payload.body = new byte[10];
    assertMessageEquals(goldenResponse, blockingStub.unaryCall(request));
}
Also used : SimpleResponse(io.grpc.android.integrationtest.nano.Messages.SimpleResponse) Payload(io.grpc.android.integrationtest.nano.Messages.Payload) SimpleRequest(io.grpc.android.integrationtest.nano.Messages.SimpleRequest)

Example 2 with Payload

use of io.grpc.android.integrationtest.nano.Messages.Payload in project grpc-java by grpc.

the class InteropTester method clientStreaming.

public void clientStreaming() throws Exception {
    final Messages.StreamingInputCallRequest[] requests = new Messages.StreamingInputCallRequest[4];
    for (int i = 0; i < 4; i++) {
        requests[i] = new Messages.StreamingInputCallRequest();
        requests[i].payload = new Payload();
    }
    requests[0].payload.body = new byte[27182];
    requests[1].payload.body = new byte[8];
    requests[2].payload.body = new byte[1828];
    requests[3].payload.body = new byte[45904];
    final Messages.StreamingInputCallResponse goldenResponse = new Messages.StreamingInputCallResponse();
    goldenResponse.aggregatedPayloadSize = 74922;
    StreamRecorder<Messages.StreamingInputCallResponse> responseObserver = StreamRecorder.create();
    StreamObserver<Messages.StreamingInputCallRequest> requestObserver = asyncStub.streamingInputCall(responseObserver);
    for (Messages.StreamingInputCallRequest request : requests) {
        requestObserver.onNext(request);
    }
    requestObserver.onCompleted();
    assertMessageEquals(goldenResponse, responseObserver.firstValue().get());
}
Also used : StreamingInputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingInputCallRequest) StreamingInputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingInputCallRequest) Messages(io.grpc.android.integrationtest.nano.Messages) Payload(io.grpc.android.integrationtest.nano.Messages.Payload) StreamingInputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingInputCallResponse) StreamingInputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingInputCallResponse)

Example 3 with Payload

use of io.grpc.android.integrationtest.nano.Messages.Payload in project grpc-java by grpc.

the class InteropTester method veryLargeResponse.

public void veryLargeResponse() throws Exception {
    if (shouldSkip()) {
        return;
    }
    final SimpleRequest request = new SimpleRequest();
    request.responseSize = unaryPayloadLength();
    request.responseType = Messages.COMPRESSABLE;
    SimpleResponse resp = blockingStub.unaryCall(request);
    final SimpleResponse goldenResponse = new SimpleResponse();
    goldenResponse.payload = new Payload();
    goldenResponse.payload.type = Messages.COMPRESSABLE;
    goldenResponse.payload.body = new byte[unaryPayloadLength()];
    assertMessageSizeEquals(goldenResponse, resp);
}
Also used : SimpleResponse(io.grpc.android.integrationtest.nano.Messages.SimpleResponse) Payload(io.grpc.android.integrationtest.nano.Messages.Payload) SimpleRequest(io.grpc.android.integrationtest.nano.Messages.SimpleRequest)

Example 4 with Payload

use of io.grpc.android.integrationtest.nano.Messages.Payload in project grpc-java by grpc.

the class InteropTester method largeUnary.

public void largeUnary() {
    if (shouldSkip()) {
        return;
    }
    final Messages.SimpleRequest request = new Messages.SimpleRequest();
    request.responseSize = 314159;
    request.responseType = Messages.COMPRESSABLE;
    request.payload = new Payload();
    request.payload.body = new byte[271828];
    final Messages.SimpleResponse goldenResponse = new Messages.SimpleResponse();
    goldenResponse.payload = new Payload();
    goldenResponse.payload.body = new byte[314159];
    Messages.SimpleResponse response = blockingStub.unaryCall(request);
    assertMessageEquals(goldenResponse, response);
}
Also used : SimpleResponse(io.grpc.android.integrationtest.nano.Messages.SimpleResponse) Messages(io.grpc.android.integrationtest.nano.Messages) SimpleRequest(io.grpc.android.integrationtest.nano.Messages.SimpleRequest) SimpleResponse(io.grpc.android.integrationtest.nano.Messages.SimpleResponse) Payload(io.grpc.android.integrationtest.nano.Messages.Payload) SimpleRequest(io.grpc.android.integrationtest.nano.Messages.SimpleRequest)

Example 5 with Payload

use of io.grpc.android.integrationtest.nano.Messages.Payload in project grpc-java by grpc.

the class InteropTester method serverStreamingShouldBeFlowControlled.

public void serverStreamingShouldBeFlowControlled() throws Exception {
    final StreamingOutputCallRequest request = new StreamingOutputCallRequest();
    request.responseType = Messages.COMPRESSABLE;
    request.responseParameters = new ResponseParameters[2];
    request.responseParameters[0] = new ResponseParameters();
    request.responseParameters[0].size = 100000;
    request.responseParameters[1] = new ResponseParameters();
    request.responseParameters[1].size = 100001;
    final StreamingOutputCallResponse[] goldenResponses = new StreamingOutputCallResponse[2];
    goldenResponses[0] = new StreamingOutputCallResponse();
    goldenResponses[0].payload = new Payload();
    goldenResponses[0].payload.type = Messages.COMPRESSABLE;
    goldenResponses[0].payload.body = new byte[100000];
    goldenResponses[1] = new StreamingOutputCallResponse();
    goldenResponses[1].payload = new Payload();
    goldenResponses[1].payload.type = Messages.COMPRESSABLE;
    goldenResponses[1].payload.body = new byte[100001];
    long start = System.nanoTime();
    final ArrayBlockingQueue<Object> queue = new ArrayBlockingQueue<Object>(10);
    ClientCall<StreamingOutputCallRequest, StreamingOutputCallResponse> call = channel.newCall(TestServiceGrpc.METHOD_STREAMING_OUTPUT_CALL, CallOptions.DEFAULT);
    call.start(new ClientCall.Listener<StreamingOutputCallResponse>() {

        @Override
        public void onHeaders(Metadata headers) {
        }

        @Override
        public void onMessage(final StreamingOutputCallResponse message) {
            queue.add(message);
        }

        @Override
        public void onClose(io.grpc.Status status, Metadata trailers) {
            queue.add(status);
        }
    }, new Metadata());
    call.sendMessage(request);
    call.halfClose();
    // Time how long it takes to get the first response.
    call.request(1);
    assertMessageEquals(goldenResponses[0], (StreamingOutputCallResponse) queue.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
    long firstCallDuration = System.nanoTime() - start;
    // Without giving additional flow control, make sure that we don't get another response. We wait
    // until we are comfortable the next message isn't coming. We may have very low nanoTime
    // resolution (like on Windows) or be using a testing, in-process transport where message
    // handling is instantaneous. In both cases, firstCallDuration may be 0, so round up sleep time
    // to at least 1ms.
    assertNull(queue.poll(Math.max(firstCallDuration * 4, 1 * 1000 * 1000), TimeUnit.NANOSECONDS));
    // Make sure that everything still completes.
    call.request(1);
    assertMessageEquals(goldenResponses[1], (StreamingOutputCallResponse) queue.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
    assertCodeEquals(io.grpc.Status.OK, (io.grpc.Status) queue.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
}
Also used : ResponseParameters(io.grpc.android.integrationtest.nano.Messages.ResponseParameters) Metadata(io.grpc.Metadata) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ClientCall(io.grpc.ClientCall) Payload(io.grpc.android.integrationtest.nano.Messages.Payload) StreamingOutputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse)

Aggregations

Payload (io.grpc.android.integrationtest.nano.Messages.Payload)9 Messages (io.grpc.android.integrationtest.nano.Messages)6 ResponseParameters (io.grpc.android.integrationtest.nano.Messages.ResponseParameters)5 StreamingOutputCallRequest (io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest)5 StreamingOutputCallResponse (io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse)5 SimpleRequest (io.grpc.android.integrationtest.nano.Messages.SimpleRequest)3 SimpleResponse (io.grpc.android.integrationtest.nano.Messages.SimpleResponse)3 ClientCall (io.grpc.ClientCall)1 Metadata (io.grpc.Metadata)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 StreamingInputCallRequest (io.grpc.android.integrationtest.nano.Messages.StreamingInputCallRequest)1 StreamingInputCallResponse (io.grpc.android.integrationtest.nano.Messages.StreamingInputCallResponse)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1