My java class
@Pact(consumer = "P01819-ipa-mi")
public V4Pact tradesByFilterProductTypeFXFWD(PactBuilder builder) throws InterruptedException {
return builder
.usingPlugin("protobuf")
.expectsToReceive("a get trade by filter request", "core/interaction/synchronous-message")
.with(Map.of(
"pact:proto", filePath("proto/tsServiceV2.proto"),
"pact:content-type", "application/grpc",
"pact:proto-service", "TradeStoreService/GetTradesByFilter",
"pact:protobuf-config", Map.of(
"additionalIncludes",
List.of(filePath("proto/tsService.proto"))),
// Details on the request message
"request", Map.of(
"productTypes",
Map.of("value",
"matching(equalTo, 'FXFWD')")),
// Details on the response
"response",
Map.of("trade_key",
Map.of("product_type", "matching(equalTo, 'FXFWD')")))
).toPact();
}
My Test
@Test
@PactTestFor(pactMethod = "tradesByFilterProductTypeFXFWD")
@MockServerConfig(implementation = MockServerImplementation.Plugin, registryEntry = "protobuf/transport/grpc")
void testTradesByFilterProductTypeFXFWD(MockServer mockServer, V4Interaction.SynchronousMessages interaction) throws InvalidProtocolBufferException {
boolean success = false;
ManagedChannel channel = ManagedChannelBuilder.forTarget("127.0.0.1:" + mockServer.getPort())
.usePlaintext()
.build();
try {
TradeStoreServiceGrpc.TradeStoreServiceBlockingStub stub = TradeStoreServiceGrpc.newBlockingStub(channel);
ts.api.TsServiceV2.TradeFilter tradeFilter = ts.api.TsServiceV2.TradeFilter.parseFrom(interaction.getRequest().getContents().getValue());
Iterator<TsService.Trade> responseTrade = stub.getTradesByFilter(tradeFilter);
Thread.sleep(10000);
assertThat(responseTrade).as("getTradeByFilter is null").isNotNull();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
if (!success) {
channel.shutdown();
}
}
}
An error2025-02-17 10:52:31,966 ERROR [main] [:] io.pact.plugins.jvm.core.DefaultPluginManager: Failed to initialise the plugin
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
at com.ing.ipami.pact.product_type.GetTradesByFilterProductTypeFXFWDTest.tradesByFilterProductTypeFXFWDONE(GetTradesByFilterProductTypeFXFWDTest.java:99)
Caused by: io.grpcty.shaded.ioty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: getsockopt: /[0:0:0:0:0:0:0:1]:64265
And in the result I have .json file with generated only ONE test method
I can't understand what a problem... Protobuf plugin is installed protoc version protobuf version
- Mock server correctly started and i get a request and response
- .usingPlugin("protobuf") trying to debug this part...nothing helps