Search in sources :

Example 6 with Payload

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

the class InteropTester method gracefulShutdown.

public void gracefulShutdown() throws Exception {
    StreamingOutputCallRequest[] requests = new StreamingOutputCallRequest[3];
    requests[0] = new StreamingOutputCallRequest();
    requests[0].responseParameters = new ResponseParameters[1];
    requests[0].responseParameters[0] = new ResponseParameters();
    requests[0].responseParameters[0].size = 3;
    requests[0].payload = new Payload();
    requests[0].payload.body = new byte[2];
    requests[1] = new StreamingOutputCallRequest();
    requests[1].responseParameters = new ResponseParameters[1];
    requests[1].responseParameters[0] = new ResponseParameters();
    requests[1].responseParameters[0].size = 1;
    requests[1].payload = new Payload();
    requests[1].payload.body = new byte[7];
    requests[2] = new StreamingOutputCallRequest();
    requests[2].responseParameters = new ResponseParameters[1];
    requests[2].responseParameters[0] = new ResponseParameters();
    requests[2].responseParameters[0].size = 4;
    requests[2].payload = new Payload();
    requests[2].payload.body = new byte[1];
    StreamingOutputCallResponse[] goldenResponses = new StreamingOutputCallResponse[3];
    goldenResponses[0] = new StreamingOutputCallResponse();
    goldenResponses[0].payload = new Payload();
    goldenResponses[0].payload.type = Messages.COMPRESSABLE;
    goldenResponses[0].payload.body = new byte[3];
    goldenResponses[1] = new StreamingOutputCallResponse();
    goldenResponses[1].payload = new Payload();
    goldenResponses[1].payload.type = Messages.COMPRESSABLE;
    goldenResponses[1].payload.body = new byte[1];
    goldenResponses[2] = new StreamingOutputCallResponse();
    goldenResponses[2].payload = new Payload();
    goldenResponses[2].payload.type = Messages.COMPRESSABLE;
    goldenResponses[2].payload.body = new byte[4];
    ResponseObserver responseObserver = new ResponseObserver();
    StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver);
    requestObserver.onNext(requests[0]);
    Object response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    assertTrue(response instanceof Messages.StreamingOutputCallResponse);
    assertMessageEquals(goldenResponses[0], (Messages.StreamingOutputCallResponse) response);
    // Initiate graceful shutdown.
    channel.shutdown();
    // The previous ping-pong could have raced with the shutdown, but this one certainly shouldn't.
    requestObserver.onNext(requests[1]);
    response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    assertTrue(response instanceof Messages.StreamingOutputCallResponse);
    assertMessageEquals(goldenResponses[1], (Messages.StreamingOutputCallResponse) response);
    requestObserver.onNext(requests[2]);
    response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    assertTrue(response instanceof Messages.StreamingOutputCallResponse);
    assertMessageEquals(goldenResponses[2], (Messages.StreamingOutputCallResponse) response);
    requestObserver.onCompleted();
    assertEquals(responseObserver.magicTailResponse, responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
}
Also used : Messages(io.grpc.android.integrationtest.nano.Messages) ResponseParameters(io.grpc.android.integrationtest.nano.Messages.ResponseParameters) StreamingOutputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse) Payload(io.grpc.android.integrationtest.nano.Messages.Payload) StreamingOutputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse)

Example 7 with Payload

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

the class InteropTester method cancelAfterFirstResponse.

public void cancelAfterFirstResponse() throws Exception {
    final StreamingOutputCallRequest request = new StreamingOutputCallRequest();
    request.responseParameters = new Messages.ResponseParameters[1];
    request.responseParameters[0] = new ResponseParameters();
    request.responseParameters[0].size = 31415;
    request.payload = new Payload();
    request.payload.body = new byte[27182];
    final StreamingOutputCallResponse goldenResponse = new StreamingOutputCallResponse();
    goldenResponse.payload = new Payload();
    goldenResponse.payload.type = Messages.COMPRESSABLE;
    goldenResponse.payload.body = new byte[31415];
    ResponseObserver responseObserver = new ResponseObserver();
    StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver);
    requestObserver.onNext(request);
    Object response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    if (!(response instanceof Messages.StreamingOutputCallResponse)) {
        fail("Unexpected: " + response);
    }
    assertMessageEquals(goldenResponse, (Messages.StreamingOutputCallResponse) response);
    requestObserver.onError(new RuntimeException());
    response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    if (!(response instanceof Throwable)) {
        fail("Unexpected: " + response);
    }
    assertCodeEquals(io.grpc.Status.CANCELLED, io.grpc.Status.fromThrowable((Throwable) response));
}
Also used : Messages(io.grpc.android.integrationtest.nano.Messages) StatusRuntimeException(io.grpc.StatusRuntimeException) ResponseParameters(io.grpc.android.integrationtest.nano.Messages.ResponseParameters) Payload(io.grpc.android.integrationtest.nano.Messages.Payload) StreamingOutputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse)

Example 8 with Payload

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

the class InteropTester method pingPong.

public void pingPong() throws Exception {
    final Messages.StreamingOutputCallRequest[] requests = new Messages.StreamingOutputCallRequest[4];
    for (int i = 0; i < 4; i++) {
        requests[i] = new Messages.StreamingOutputCallRequest();
        requests[i].responseParameters = new Messages.ResponseParameters[1];
        requests[i].responseParameters[0] = new Messages.ResponseParameters();
        requests[i].payload = new Payload();
    }
    requests[0].responseParameters[0].size = 31415;
    requests[0].payload.body = new byte[27182];
    requests[1].responseParameters[0].size = 9;
    requests[1].payload.body = new byte[8];
    requests[2].responseParameters[0].size = 2653;
    requests[2].payload.body = new byte[1828];
    requests[3].responseParameters[0].size = 58979;
    requests[3].payload.body = new byte[45904];
    final Messages.StreamingOutputCallResponse[] goldenResponses = new Messages.StreamingOutputCallResponse[4];
    for (int i = 0; i < 4; i++) {
        goldenResponses[i] = new Messages.StreamingOutputCallResponse();
        goldenResponses[i].payload = new Payload();
        goldenResponses[i].payload.type = Messages.COMPRESSABLE;
    }
    goldenResponses[0].payload.body = new byte[31415];
    goldenResponses[1].payload.body = new byte[9];
    goldenResponses[2].payload.body = new byte[2653];
    goldenResponses[3].payload.body = new byte[58979];
    ResponseObserver responseObserver = new ResponseObserver();
    StreamObserver<Messages.StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver);
    for (int i = 0; i < requests.length; i++) {
        requestObserver.onNext(requests[i]);
        Object response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        if (!(response instanceof Messages.StreamingOutputCallResponse)) {
            fail("Unexpected: " + response);
        }
        assertMessageEquals(goldenResponses[i], (Messages.StreamingOutputCallResponse) response);
        assertTrue("More than 1 responses received for ping pong test.", responseObserver.responses.isEmpty());
    }
    requestObserver.onCompleted();
    assertEquals(responseObserver.magicTailResponse, responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
}
Also used : Messages(io.grpc.android.integrationtest.nano.Messages) StreamingOutputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse) ResponseParameters(io.grpc.android.integrationtest.nano.Messages.ResponseParameters) StreamingOutputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest) Payload(io.grpc.android.integrationtest.nano.Messages.Payload) StreamingOutputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse)

Example 9 with Payload

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

the class InteropTester method serverStreaming.

public void serverStreaming() throws Exception {
    final Messages.StreamingOutputCallRequest request = new Messages.StreamingOutputCallRequest();
    request.responseType = Messages.COMPRESSABLE;
    request.responseParameters = new Messages.ResponseParameters[4];
    for (int i = 0; i < 4; i++) {
        request.responseParameters[i] = new Messages.ResponseParameters();
    }
    request.responseParameters[0].size = 31415;
    request.responseParameters[1].size = 9;
    request.responseParameters[2].size = 2653;
    request.responseParameters[3].size = 58979;
    final Messages.StreamingOutputCallResponse[] goldenResponses = new Messages.StreamingOutputCallResponse[4];
    for (int i = 0; i < 4; i++) {
        goldenResponses[i] = new Messages.StreamingOutputCallResponse();
        goldenResponses[i].payload = new Payload();
        goldenResponses[i].payload.type = Messages.COMPRESSABLE;
    }
    goldenResponses[0].payload.body = new byte[31415];
    goldenResponses[1].payload.body = new byte[9];
    goldenResponses[2].payload.body = new byte[2653];
    goldenResponses[3].payload.body = new byte[58979];
    StreamRecorder<Messages.StreamingOutputCallResponse> recorder = StreamRecorder.create();
    asyncStub.streamingOutputCall(request, recorder);
    assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
    assertSuccess(recorder);
    assertMessageEquals(Arrays.asList(goldenResponses), recorder.getValues());
}
Also used : Messages(io.grpc.android.integrationtest.nano.Messages) StreamingOutputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse) ResponseParameters(io.grpc.android.integrationtest.nano.Messages.ResponseParameters) StreamingOutputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest) 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