Hi, I am working with the grpc extension. I have f...
# help
d
Hi, I am working with the grpc extension. I have followed the documentation and I am trying to work in a mock for an Google api Bytestream. I have followed the documentation and I am getting problems to register a new stub in the
WireMockGrpcService
. I am getting the following error:
connection is not kept alive
Copy code
java.lang.NullPointerException: Cannot invoke "org.apache.hc.client5.http.io.ManagedHttpClientConnection.isConsistent()" because "conn" is null
I have tried everything but I don't see what is the option or step that I am missing. My code is the following:
Copy code
@RegisterExtension
  public static WireMockExtension wm =
      WireMockExtension.newInstance()
          .options(
              wireMockConfig()
                  .dynamicPort()
                  .withRootDirectory("src/test/resources/wiremock")
                  .extensions(new GrpcExtensionFactory())
          )
          .build();

  @BeforeEach
  void init() {
    mockGreetingService =
        new WireMockGrpcService(new WireMock(wm.getPort()), ByteStreamGrpc.SERVICE_NAME);

    channel = ManagedChannelBuilder.forAddress("localhost", wm.getPort()).usePlaintext().build();
    client = ByteStreamGrpc.newStub(channel);
  }
and I am getting my exception in:
Copy code
@Test
  public void firstTest() {
    mockGreetingService.stubFor(
        method("Write")
            .willReturn(message(WriteResponse.newBuilder().setCommittedSize(20).build())));
I would appreciate any help 🙏
t
Can you post the full stack trace?
d
Copy code
java.lang.NullPointerException: Cannot invoke "org.apache.hc.client5.http.io.ManagedHttpClientConnection.isConsistent()" because "conn" is null

	at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.release(PoolingHttpClientConnectionManager.java:412)
	at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.discardEndpoint(InternalExecRuntime.java:246)
	at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.releaseEndpoint(InternalExecRuntime.java:260)
	at org.apache.hc.client5.http.impl.classic.ResponseEntityProxy.releaseConnection(ResponseEntityProxy.java:80)
	at org.apache.hc.client5.http.impl.classic.ResponseEntityProxy.eofDetected(ResponseEntityProxy.java:115)
	at org.apache.hc.core5.http.io.EofSensorInputStream.checkEOF(EofSensorInputStream.java:199)
	at org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:136)
	at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:270)
	at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:313)
	at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:188)
	at java.base/java.io.InputStreamReader.read(InputStreamReader.java:177)
	at java.base/java.io.Reader.read(Reader.java:250)
	at org.apache.hc.core5.http.io.entity.EntityUtils.toCharArrayBuffer(EntityUtils.java:179)
	at org.apache.hc.core5.http.io.entity.EntityUtils.toString(EntityUtils.java:222)
	at org.apache.hc.core5.http.io.entity.EntityUtils.toString(EntityUtils.java:283)
	at org.apache.hc.core5.http.io.entity.EntityUtils.toString(EntityUtils.java:244)
	at com.github.tomakehurst.wiremock.common.HttpClientUtils.getEntityAsStringAndCloseStream(HttpClientUtils.java:35)
	at com.github.tomakehurst.wiremock.client.HttpAdminClient.safelyExecuteRequest(HttpAdminClient.java:535)
	at com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:507)
	at com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:483)
	at com.github.tomakehurst.wiremock.client.HttpAdminClient.addStubMapping(HttpAdminClient.java:150)
	at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:446)
	at org.wiremock.grpc.dsl.WireMockGrpcService.stubFor(WireMockGrpcService.java:39)
I don't see any special on it, to be honest
t
Pretty odd that the problem is happening on stub creation. Think I’d need to be able to get in there with the debugger to figure out what’s happening there.
Is there any chance you’re pulling in a different version of the Apache HTTP client than the usual one WireMock uses?
d
you were right, I just checked the http clients in the maven file and I saw there were a different http client there
thanks
now, I am having a different error, when I do the request itself, I get the following error:
Copy code
java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: UNIMPLEMENTED: Method not found: google.bytestream.ByteStream/Write
it is a bit weird since I did an stub for that method
Copy code
@BeforeEach
  void init() {
    mockGreetingService =
        new WireMockGrpcService(new WireMock(wm.getPort()), ByteStreamGrpc.SERVICE_NAME);

    channel = ManagedChannelBuilder.forAddress("localhost", wm.getPort()).usePlaintext().build();
    client = ByteStreamGrpc.newStub(channel);
  }

  @AfterEach
  void tearDown() {
    channel.shutdown();
  }

  @Test
  public void dynamic_response_via_JSON() {
    mockGreetingService.stubFor(
        method("write")
            .willReturn(message(WriteResponse.newBuilder().setCommittedSize(20).build())));
i
Hi, I'm currently working with the grpc extension, and I've encountered the following error when executing the grpc call:
Copy code
io.grpc.StatusRuntimeException: UNKNOWN: HTTP status code 200
invalid content-type: null
headers: Metadata(:status=200,grpc-status-name=OK,matched-stub-id=00e9561b-a02a-4553-bf36-6be6d397766e)
DATA-----------------------------
{
}
DATA-----------------------------

	at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:268)
	at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:249)
	at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:167)
My stub is the following one:
Copy code
private final WireMockGrpcService wireMockGrpcService =
            new WireMockGrpcService(
                    new WireMock(getPort()),
                    UnaryEnvelopeRelayServiceGrpc.SERVICE_NAME
            );

    private ManagedChannel channel;
    @BeforeEach
    void init() {
        channel = ManagedChannelBuilder.forAddress("localhost", getPort()).usePlaintext().build();
        enricherClient = new EnricherClient(UnaryEnvelopeRelayServiceGrpc.newBlockingStub(channel));
    }

    @AfterEach
    void tearDown() {
        channel.shutdown();
    }

    @Test
    void should_return_failure_when_initiation_fails() {
        wireMockGrpcService.stubFor(
                method("relay")
                        .willReturn(message(Envelope.newBuilder().build())));
Any idea what could be causing this issue?
t
Your setup looks OK to me. Can you share the context needed to replicate i.e. your proto file, WireMock version and how you’re making the actual request?
126 Views