Hi team! I have a problem THIS IS MY TEST CLASS :...
# pact-jvm
d
Hi team! I have a problem THIS IS MY TEST CLASS :
Copy code
@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "P01823-TS-Trade-Store", pactVersion = PactSpecVersion.V4, providerType = ProviderType.SYNCH_MESSAGE)
class GetTradesByFilterProductTypeFXFWDTest {

    ManagedChannel channel;
    @BeforeEach
    void setUp(MockServer mockServer) {
        System.setProperty("pact_do_not_track", "true");

    }

    ////////////////// 1. GetTradesByFilter product types
    @Pact(consumer = "P01819-ipa-mi")
    public V4Pact tradesByFilterProductTypeFXFWD(PactBuilder builder) {
        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();
    }


    @Test
    @PactTestFor(pactMethod = "tradesByFilterProductTypeFXFWD")
    @MockServerConfig(implementation = MockServerImplementation.Plugin, registryEntry = "protobuf/transport/grpc")
    void testTradesByFilterProductTypeFXFWD(MockServer mockServer, V4Interaction.SynchronousMessages interaction) throws InvalidProtocolBufferException, InterruptedException {
        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);

            assertThat(responseTrade).as("getTradeByFilter is null").isNotNull();
        } finally {
            if (!success) {
                channel.awaitTermination(10, TimeUnit.SECONDS);
                channel.shutdown();
            }
        }
    }
    @Pact(consumer = "P01819-ipa-mi")
    public V4Pact tradesByFilterProductTypeFXFWDONE(PactBuilder builder) {
        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();
    }


    @Test
    @PactTestFor(pactMethod = "tradesByFilterProductTypeFXFWDONE")
    @MockServerConfig(implementation = MockServerImplementation.Plugin, registryEntry = "protobuf/transport/grpc")
    void testTradesByFilterProductTypeFXFWDONE(MockServer mockServer, V4Interaction.SynchronousMessages interaction) throws InvalidProtocolBufferException, InterruptedException {
        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);

            assertThat(responseTrade).as("getTradeByFilter is null").isNotNull();
        } finally {
            if (!success) {
                channel.awaitTermination(10, TimeUnit.SECONDS);
                channel.shutdown();
            }
        }
    }
}
After running all class I have an error:
2025-02-18 17:34:46,081 ERROR [main] [:] io.pact.plugins.jvm.core.DefaultPluginManager: Failed to initialise the plugin
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:351) at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:332) at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:174) at io.pact.plugin.PactPluginGrpc$PactPluginBlockingStub.initPlugin(PactPluginGrpc.java:641) at io.pact.plugins.jvm.core.DefaultPluginManager.initPlugin$lambda$37(PluginManager.kt:913) at io.pact.plugins.jvm.core.DefaultPactPlugin.withGrpcStub(PluginManager.kt:267) at io.pact.plugins.jvm.core.DefaultPluginManager.initPlugin(PluginManager.kt:913) at io.pact.plugins.jvm.core.DefaultPluginManager.tryInitPlugin(PluginManager.kt:892) at io.pact.plugins.jvm.core.DefaultPluginManager.initialisePlugin(PluginManager.kt:866) at io.pact.plugins.jvm.core.DefaultPluginManager.loadPlugin(PluginManager.kt:419) at au.com.dius.pact.consumer.dsl.PactBuilder.usingPlugin(PactBuilder.kt:113) at au.com.dius.pact.consumer.dsl.PactBuilder.usingPlugin$default(PactBuilder.kt:110) at au.com.dius.pact.consumer.dsl.PactBuilder.usingPlugin(PactBuilder.kt) at com.ing.ipami.pact.product_type.GetTradesByFilterProductTypeFXFWDTest.tradesByFilterProductTypeFXFWDONE(GetTradesByFilterProductTypeFXFWDTest.java:101) Caused by: io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: getsockopt: /[00000001]52748 Caused by: java.net.ConnectException: Connection refused: getsockopt Process finished with exit code 0 protobuf plugin V 0.5.4 is installed on my laptop Do you have any ideas why after running tested class PACT framework generated only one tested method inside contract/.json file? Thanks
m
hmm are there any other logs? Are there logs for the gRPC/Protobuf plugin? (I believe they should be in a path like this:
~/.pact/plugins/<plugin-version>/*.log
P.S. it’s just Pact (not an acronym) 😉
d
hi @Matt (pactflow.io / pact-js / pact-go) I have empty lig file after running this tests. 0KB log file only this error in console that I provided higher... But in another runs where I put incorrect field from proto files and trying to play with mock server from tests I have this thanks a lot!
m
yeah those errors look much more helpful - did that manage to unblock you?
d
i found an error... expectsToReceive("a get trade by filter request") - message inside method expectsToReceive the same in both tested method that's why PACT override contract in the result