jschenfeld
08/11/2026, 2:07 PM@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "example-provider", pactVersion = PactSpecVersion.V4)
class ExampleClientPactTest {
private final OkHttpClient client = new OkHttpClient();
@Pact(consumer = "example-consumer")
public V4Pact createOrderPact(PactDslWithProvider builder) {
return builder
.given("provider accepts an order")
.uponReceiving("a request to create an order")
.path("/orders")
.method("POST")
.headers(Map.of("Content-Type", "application/json"))
.body(new PactDslJsonBody()
.stringType("customerId", "cust-123")
.decimalType("amount", 100.00))
.willRespondWith()
.status(200)
.headers(Map.of("Content-Type", "application/json"))
.body(new PactDslJsonBody()
.stringType("orderId", "order-456")
.stringValue("status", "CREATED"))
.toPact(V4Pact.class);
}
@Test
@PactTestFor(pactMethod = "createOrderPact")
void should_create_order(MockServer mockServer) throws IOException {
Request request = new Request.Builder()
.url(mockServer.getUrl() + "/orders")
.post(RequestBody.create(
"{\"customerId\":\"cust-123\",\"amount\":100.00}",
MediaType.get("application/json")))
.build();
try (Response response = client.newCall(request).execute()) {
assertThat(response.code()).isEqualTo(200);
}
}
}
Fails with:
java.io.IOException: unexpected end of stream on <http://localhost>:PORT/...
Caused by: java.io.EOFException: \n not found: limit=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict
at okhttp3.internal.http1.HeadersReader.readLine
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders
and Pact reports the interaction as not received (client never got a full response). Looks like a race where the client connects before the mock server is ready to respond. Anyone seen this / know a fix or workaround?rholshausen
08/12/2026, 12:40 AMrholshausen
08/12/2026, 12:42 AMrholshausen
08/12/2026, 12:42 AM