https://pact.io logo
#pact-jvm
Title
# pact-jvm
s

Shaun Mendham

05/26/2022, 8:07 AM
Hi all, This looks to be an already discussed topic, but struggling to find a conclusive answer to a question we have. Effectively we have a microservice which interacts both via HTTP and Kafka with other microservices, we are looking to PACT test both of these interaction types. Is it currently not possible to define multiple provider types against the same provider name? (E.g. we would need to define a two providers
service-name
and
service-name-kafka
) What I am seeing currently with a single provider name across two test classes, is that all contracts for the provider are run against both types of which the opposite type contracts fail.
👍 1
It looks by this: https://pact.canny.io/feature-requests/p/support-multiple-protocols-of-pact-for-the-same-application That the feature is planned, is this the best place to track the progress? In the meantime is the recommended solution to have multiple providers defined, one for each contract type?
y

Yousaf Nabi (pactflow.io)

05/26/2022, 11:36 AM
Hi, I believe your use case is solved in v4 pact-specification https://github.com/pact-foundation/pact-specification/tree/version-4 This is from the latest OSS changelog https://pactflow.io/blog/changelog-oss-may-2022/
Pact specification V4 is here! We worked hard on listening to the community, after the release of v3, 5 years ago. We consolidation many of the requests people made about things that haven’t worked quite properly. One of the biggest changes is consolidation the file format to allow for HTTP and message interactions with a single file.
📹 See an AMA from 2021 where Ron Holshausen took us through “

What's in store for Pact specification v4.0

?”
📙 Read the V4 spec RFC for a full list of changes: https://github.com/pact-foundation/pact-specification/issues/71
🚀 Implementations in Rust core and JVM has been completed
🌍 All our Pact specifications are open-source and you can see them all here
s

Shaun Mendham

05/30/2022, 8:48 AM
How does this work on the provider side, our scenario is such that we have multiple consumers asserting different interaction types against a single provider. e.g. we have: • Provider with both REST endpoints and a Kafka producer. • Consumer A which consumes the REST endpoints. • Consumer B which consumes the Kafka messages. I’m struggling to find anything in the documentation as to how a Provider PACT test file or files should look for this case. I have created an demo project here: https://github.com/shaunmendham/pact-demo/tree/main Where when running the provider PACT tests, each test file satisfies one of the pacts but not the other. Is there a way to filter which pacts are applied to which test file based on interaction type? Or should this be handled in another way? Thanks in advance.
We have since experimented with a custom
InteractionFilter
to filter by interaction type. Still with one test file per interaction type, but filtering to only those supported by the test file. Does this sounds like a reasonable approach?
y

Yousaf Nabi (pactflow.io)

05/30/2022, 6:06 PM
Hey man, thanks SO much for the example repo, that is absolutely invaluable. just tagging @uglyog , so when he has time he can cast his eyes over, as he is the man!
s

Shaun Mendham

05/30/2022, 10:03 PM
Perfect, thank you. I’ve just added my implementation of the interaction filter to that project, see here 🙂
r

rholshausen

06/01/2022, 12:40 AM
I would create two different consumer names (and keep the same provider), one for each transport. Then you can have two different pact files to test the different interactions.
s

Shaun Mendham

06/01/2022, 7:51 AM
@rholshausen, I’ve clarified something in the demo repo that may not initially have been clear. In our actual scenario the two consumers are from different projects and so would already have a different consumer name and generate an individual contract against the provider. Additionally I would hope to keep the same consumer name for multiple interaction types if this was the case to keep the dependencies between services clear, for example not having two nodes for a single service in the pact flow network graph.
r

rholshausen

06/01/2022, 8:02 AM
With V4 Pact files, you can have both a HTTP and message queue interaction in the same file.
But you have different consumers. I think adding the
@Consumer
annotation to each provider test and it will only run the verification for that consumer
s

Shaun Mendham

06/01/2022, 8:08 AM
Our issue is on the provider side where if a single or multiple consumers have different interaction types across the contracts (within a single or across multiple). We needed a way to specify which contracts should be verified against which test file Message or rest… I’ve just tried adding
@Consumer
Which looks like it’s working 👍 I guess this issue would come back if we ever had a single consumer asserting multiple interaction types against the same provider. Where we would then need something like the filter. Or alternatively multiple provider names.
In this more general case, is the above interaction filter a reasonable solution?
Thank you for your time looking at this one 🙂
@Consumer
works for the demo use case, however with the annotation only accepting a single consumer name. This would mean needing to duplicate the provider test files, or add additional boilerplate per consumer, rather than adding a new consumer string which might have been an acceptable overhead 🤔 Our real scenario is something like: • Provider A (Kafka and REST) • Consumer B consumes Kafka of Provider A • Consumer C consumes REST of Provider A • Consumer D consumes REST of Provider A • Consumer E consumes REST of Provider A • …
2 Views