io.grpc.testing.integration.TestServiceGrpc Java Examples

The following examples show how to use io.grpc.testing.integration.TestServiceGrpc. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StubConfigTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigureDeadline() {
  Deadline deadline = Deadline.after(2, NANOSECONDS);
  // Create a default stub
  TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel);
  assertNull(stub.getCallOptions().getDeadline());
  // Reconfigure it
  TestServiceGrpc.TestServiceBlockingStub reconfiguredStub = stub.withDeadline(deadline);
  // New altered config
  assertEquals(deadline, reconfiguredStub.getCallOptions().getDeadline());
  // Default config unchanged
  assertNull(stub.getCallOptions().getDeadline());
}
 
Example #2
Source File: StubConfigTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testStubCallOptionsPopulatedToNewCall() {
  TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel);
  CallOptions options1 = stub.getCallOptions();
  SimpleRequest request = SimpleRequest.getDefaultInstance();
  stub.unaryCall(request, responseObserver);
  verify(channel).newCall(same(TestServiceGrpc.getUnaryCallMethod()), same(options1));
  stub = stub.withDeadlineAfter(2, NANOSECONDS);
  CallOptions options2 = stub.getCallOptions();
  assertNotSame(options1, options2);
  stub.unaryCall(request, responseObserver);
  verify(channel).newCall(same(TestServiceGrpc.getUnaryCallMethod()), same(options2));
}
 
Example #3
Source File: GrpcServiceTestBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamingOutMethodWithBlockingClient() {
    Iterator<Messages.StreamingOutputCallResponse> iterator = TestServiceGrpc
            .newBlockingStub(channel)
            .streamingOutputCall(Messages.StreamingOutputCallRequest.newBuilder().build());
    assertThat(iterator).isNotNull();
    List<String> list = new CopyOnWriteArrayList<>();
    iterator.forEachRemaining(so -> {
        String content = so.getPayload().getBody().toStringUtf8();
        list.add(content);
    });
    assertThat(list).containsExactly("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
}
 
Example #4
Source File: GrpcServiceTestBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void testUnimplementedMethodWithBlockingClient() {
    assertThatThrownBy(
            () -> TestServiceGrpc.newBlockingStub(channel).unimplementedCall(EmptyProtos.Empty.newBuilder().build()))
                    .isInstanceOf(StatusRuntimeException.class).hasMessageContaining("UNIMPLEMENTED");
}
 
Example #5
Source File: ArmeriaGrpcServerInteropTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public void sendsTimeoutHeader() {
    final long configuredTimeoutMinutes = 100;
    final TestServiceGrpc.TestServiceBlockingStub stub =
            blockingStub.withDeadlineAfter(configuredTimeoutMinutes, TimeUnit.MINUTES);
    stub.emptyCall(EMPTY);
    final long transferredTimeoutMinutes = TimeUnit.MILLISECONDS.toMinutes(
            ctxCapture.get().requestTimeoutMillis());
    Assert.assertTrue(
            "configuredTimeoutMinutes=" + configuredTimeoutMinutes +
            ", transferredTimeoutMinutes=" + transferredTimeoutMinutes,
            configuredTimeoutMinutes - transferredTimeoutMinutes >= 0 &&
            configuredTimeoutMinutes - transferredTimeoutMinutes <= 1);
}
 
Example #6
Source File: StubConfigTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigureDeadline() {
  Deadline deadline = Deadline.after(2, NANOSECONDS);
  // Create a default stub
  TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel);
  assertNull(stub.getCallOptions().getDeadline());
  // Reconfigure it
  TestServiceGrpc.TestServiceBlockingStub reconfiguredStub = stub.withDeadline(deadline);
  // New altered config
  assertEquals(deadline, reconfiguredStub.getCallOptions().getDeadline());
  // Default config unchanged
  assertNull(stub.getCallOptions().getDeadline());
}
 
Example #7
Source File: StubConfigTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testStubCallOptionsPopulatedToNewCall() {
  TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel);
  CallOptions options1 = stub.getCallOptions();
  SimpleRequest request = SimpleRequest.getDefaultInstance();
  stub.unaryCall(request, responseObserver);
  verify(channel).newCall(same(TestServiceGrpc.getUnaryCallMethod()), same(options1));
  stub = stub.withDeadlineAfter(2, NANOSECONDS);
  CallOptions options2 = stub.getCallOptions();
  assertNotSame(options1, options2);
  stub.unaryCall(request, responseObserver);
  verify(channel).newCall(same(TestServiceGrpc.getUnaryCallMethod()), same(options2));
}
 
Example #8
Source File: GrpcServiceTestBase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Test
public void testEmptyWithBlockingClient() {
    EmptyProtos.Empty empty = TestServiceGrpc.newBlockingStub(channel)
            .emptyCall(EmptyProtos.Empty.newBuilder().build());
    assertThat(empty).isNotNull();
}
 
Example #9
Source File: GrpcServiceTestBase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Test
public void testUnaryMethodWithBlockingClient() {
    Messages.SimpleResponse response = TestServiceGrpc.newBlockingStub(channel)
            .unaryCall(Messages.SimpleRequest.newBuilder().build());
    assertThat(response).isNotNull();
}