use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse in project grpc-java by grpc.
the class InteropTester method deadlineExceededServerStreaming.
public void deadlineExceededServerStreaming() throws Exception {
// warm up the channel and JVM
blockingStub.emptyCall(new EmptyProtos.Empty());
ResponseParameters responseParameters = new ResponseParameters();
responseParameters.size = 1;
responseParameters.intervalUs = 10000;
StreamingOutputCallRequest request = new StreamingOutputCallRequest();
request.responseType = Messages.COMPRESSABLE;
request.responseParameters = new ResponseParameters[4];
request.responseParameters[0] = responseParameters;
request.responseParameters[1] = responseParameters;
request.responseParameters[2] = responseParameters;
request.responseParameters[3] = responseParameters;
StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
TestServiceGrpc.newStub(channel).withDeadlineAfter(30, TimeUnit.MILLISECONDS).streamingOutputCall(request, recorder);
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.StreamingOutputCallResponse in project grpc-java by grpc.
the class InteropTester method fullDuplexCallShouldSucceed.
public void fullDuplexCallShouldSucceed() throws Exception {
// Build the request.
Integer[] responseSizes = { 50, 100, 150, 200 };
final StreamingOutputCallRequest request = new StreamingOutputCallRequest();
request.responseParameters = new ResponseParameters[responseSizes.length];
request.responseType = Messages.COMPRESSABLE;
for (int i = 0; i < responseSizes.length; ++i) {
request.responseParameters[i] = new ResponseParameters();
request.responseParameters[i].size = responseSizes[i];
request.responseParameters[i].intervalUs = 0;
}
StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
StreamObserver<StreamingOutputCallRequest> requestStream = asyncStub.fullDuplexCall(recorder);
final int numRequests = 10;
for (int ix = numRequests; ix > 0; --ix) {
requestStream.onNext(request);
}
requestStream.onCompleted();
assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
assertSuccess(recorder);
assertEquals(responseSizes.length * numRequests, recorder.getValues().size());
for (int ix = 0; ix < recorder.getValues().size(); ++ix) {
StreamingOutputCallResponse response = recorder.getValues().get(ix);
assertEquals(Messages.COMPRESSABLE, response.payload.type);
int length = response.payload.body.length;
int expectedSize = responseSizes[ix % responseSizes.length];
assertEquals("comparison failed at index " + ix, expectedSize, length);
}
}
use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse in project grpc-java by grpc.
the class InteropTester method halfDuplexCallShouldSucceed.
public void halfDuplexCallShouldSucceed() throws Exception {
// Build the request.
Integer[] responseSizes = { 50, 100, 150, 200 };
final StreamingOutputCallRequest request = new StreamingOutputCallRequest();
request.responseParameters = new ResponseParameters[responseSizes.length];
request.responseType = Messages.COMPRESSABLE;
for (int i = 0; i < responseSizes.length; ++i) {
request.responseParameters[i] = new ResponseParameters();
request.responseParameters[i].size = responseSizes[i];
request.responseParameters[i].intervalUs = 0;
}
StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
StreamObserver<StreamingOutputCallRequest> requestStream = asyncStub.halfDuplexCall(recorder);
final int numRequests = 10;
for (int ix = numRequests; ix > 0; --ix) {
requestStream.onNext(request);
}
requestStream.onCompleted();
assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
assertSuccess(recorder);
assertEquals(responseSizes.length * numRequests, recorder.getValues().size());
for (int ix = 0; ix < recorder.getValues().size(); ++ix) {
StreamingOutputCallResponse response = recorder.getValues().get(ix);
assertEquals(Messages.COMPRESSABLE, response.payload.type);
int length = response.payload.body.length;
int expectedSize = responseSizes[ix % responseSizes.length];
assertEquals("comparison failed at index " + ix, expectedSize, length);
}
}
use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse 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));
}
use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse 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));
}
Aggregations