https://linen.dev logo
#help
Title
# help
d

Daniel Ochoa Rodriguez

01/23/2024, 11:09 AM
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

Tom

01/24/2024, 9:27 AM
Can you post the full stack trace?
d

Daniel Ochoa Rodriguez

01/24/2024, 10:11 AM
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

Tom

01/24/2024, 11:22 AM
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

Daniel Ochoa Rodriguez

01/24/2024, 12:21 PM
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())));
4 Views