Pact-jvm: Spring Boot consumer test no longer works after upgrading to 4.0.0

Created on 5 Oct 2019  路  2Comments  路  Source: pact-foundation/pact-jvm

I recently tried to upgrade my consumer test (Junit5, Spring Boot 2.1.9) from 3.x to 4.x. The test fails because the mocked server does not respond. (Neither in the test nor from curl.) It still works in the last beta version 4.0.0-beta.6.

Exception:

I/O error on GET request for "http://localhost:8081/users/1": localhost:8081 failed to respond; nested exception is org.apache.http.NoHttpResponseException: localhost:8081 failed to respond
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8081/users/1": localhost:8081 failed to respond; nested exception is org.apache.http.NoHttpResponseException: localhost:8081 failed to respond
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
        ...

The issue seems to be caused by a change in this method: au.com.dius.pact.consumer.BaseJdkMockServer#toPactRequest

It was changed from
val bodyContents = exchange.requestBody.bufferedReader(calculateCharset(headers)).readText()

to

val bodyContents = exchange.requestBody.readBytes()

It's not working for me because I have kotlin 1.2.7 and the readBytes() does not yet exist in that version. However, this is not obvious because the java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;) exception is caught by the Server (kinda silently - only logged with trace level) and the connection is closed.

Most helpful comment

Workaround: Override the 1.2 kotlin version that comes from the spring boot bom:

In build.gradle: ext['kotlin.version'] = '1.3.50'

All 2 comments

Workaround: Override the 1.2 kotlin version that comes from the spring boot bom:

In build.gradle: ext['kotlin.version'] = '1.3.50'

Workaround: Override the 1.2 kotlin version that comes from the spring boot bom:

In build.gradle: ext['kotlin.version'] = '1.3.50'

For the maven folks, ensure it's in 'test' scope if you don't use kotlin directly in your business code.

    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>1.3.60</version>
        <scope>test</scope>
    </dependency>
Was this page helpful?
0 / 5 - 0 ratings