use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest 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));
}
use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest 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));
}
use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest in project grpc-java by grpc.
the class InteropTester method timeoutOnSleepingServer.
/** Start a fullDuplexCall which the server will not respond, and verify the deadline expires. */
public void timeoutOnSleepingServer() throws Exception {
TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel).withDeadlineAfter(1, TimeUnit.MILLISECONDS);
StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
StreamObserver<StreamingOutputCallRequest> requestObserver = stub.fullDuplexCall(recorder);
try {
StreamingOutputCallRequest request = new StreamingOutputCallRequest();
request.payload = new Messages.Payload();
request.payload.body = new byte[27182];
requestObserver.onNext(request);
} catch (IllegalStateException expected) {
// This can happen if the stream has already been terminated due to deadline exceeded.
}
assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
assertCodeEquals(io.grpc.Status.DEADLINE_EXCEEDED, io.grpc.Status.fromThrowable(recorder.getError()));
}
use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest in project grpc-java by grpc.
the class InteropTester method deadlineExceeded.
public void deadlineExceeded() {
// warm up the channel and JVM
blockingStub.emptyCall(new EmptyProtos.Empty());
TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel).withDeadlineAfter(10, TimeUnit.MILLISECONDS);
StreamingOutputCallRequest request = new StreamingOutputCallRequest();
request.responseParameters = new ResponseParameters[1];
request.responseParameters[0] = new ResponseParameters();
request.responseParameters[0].intervalUs = 20000;
try {
stub.streamingOutputCall(request).next();
fail("Expected deadline to be exceeded");
} catch (StatusRuntimeException ex) {
assertCodeEquals(io.grpc.Status.DEADLINE_EXCEEDED, ex.getStatus());
}
}
Aggregations