Example #1
0
 public void cancelAfterBegin() throws Exception {
   StreamRecorder<StreamingInputCallResponse> responseObserver = StreamRecorder.create();
   StreamObserver<StreamingInputCallRequest> requestObserver =
       asyncStub.streamingInputCall(responseObserver);
   requestObserver.onError(new RuntimeException());
   assertTrue(responseObserver.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
   assertEquals(Arrays.<StreamingInputCallResponse>asList(), responseObserver.getValues());
   assertCodeEquals(
       io.grpc.Status.CANCELLED, io.grpc.Status.fromThrowable(responseObserver.getError()));
 }
Example #2
0
  /** Start a fullDuplexCall which the server will not respond, and verify the deadline expires. */
  public void timeoutOnSleepingServer() throws Exception {
    TestServiceGrpc.TestService 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()));
  }
Example #3
0
 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()));
 }
Example #4
0
 private static void assertSuccess(StreamRecorder<?> recorder) {
   if (recorder.getError() != null) {
     throw new AssertionError(recorder.getError());
   }
 }