use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest 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.StreamingOutputCallRequest 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.StreamingOutputCallRequest 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.StreamingOutputCallRequest in project grpc-java by grpc.
the class InteropTester method deadlineNotExceeded.
public void deadlineNotExceeded() {
// warm up the channel and JVM
blockingStub.emptyCall(new EmptyProtos.Empty());
StreamingOutputCallRequest request = new StreamingOutputCallRequest();
request.responseParameters = new ResponseParameters[1];
request.responseParameters[0] = new ResponseParameters();
request.responseParameters[0].intervalUs = 0;
TestServiceGrpc.newBlockingStub(channel).withDeadlineAfter(10, TimeUnit.SECONDS).streamingOutputCall(request);
}
use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest 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));
}
Aggregations