MCPcopy Create free account
hub / github.com/grpc/grpc-java / assertRpcFails

Method assertRpcFails

okhttp/src/test/java/io/grpc/okhttp/TlsTest.java:763–782  ·  view source on GitHub ↗
(ManagedChannel channel)

Source from the content-addressed store, hash-verified

761 }
762
763 private static Status assertRpcFails(ManagedChannel channel) {
764 Status status = null;
765 SimpleServiceGrpc.SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel);
766 try {
767 stub.unaryRpc(SimpleRequest.getDefaultInstance());
768 assertWithMessage("TLS handshake should have failed, but didn't; received RPC response")
769 .fail();
770 } catch (StatusRuntimeException e) {
771 assertWithMessage(Throwables.getStackTraceAsString(e))
772 .that(e.getStatus().getCode()).isEqualTo(Status.Code.UNAVAILABLE);
773 status = e.getStatus();
774 }
775 // We really want to see TRANSIENT_FAILURE here, but if the test runs slowly the 1s backoff
776 // may be exceeded by the time the failure happens (since it counts from the start of the
777 // attempt). Even so, CONNECTING is a strong indicator that the handshake failed; otherwise we'd
778 // expect READY or IDLE.
779 assertThat(channel.getState(false))
780 .isAnyOf(ConnectivityState.TRANSIENT_FAILURE, ConnectivityState.CONNECTING);
781 return status;
782 }
783
784 private static final class SimpleServiceImpl extends SimpleServiceGrpc.SimpleServiceImplBase {
785 @Override

Calls 7

newBlockingStubMethod · 0.95
getCodeMethod · 0.80
unaryRpcMethod · 0.65
getStatusMethod · 0.65
getStateMethod · 0.65
getDefaultInstanceMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected