public InteropTester(String testCase, ManagedChannel channel, TestListener listener) {
   this.testCase = testCase;
   this.listener = listener;
   this.channel = channel;
   blockingStub = TestServiceGrpc.newBlockingStub(channel);
   asyncStub = TestServiceGrpc.newStub(channel);
 }
 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);
 }
 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());
   }
 }
  /** 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()));
  }
 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()));
 }