Closed Sabartius closed 3 years ago
Just fiddled around with that and it seems that the QuarkusTest-Extension tries to clone au.com.dius.pact.provider.junit5.PactVerificationContext
at some point using XStream which happens in QuarkusTestExtension:544 - it seems this is to provide JUnit5 invocation context arguments to a different classloader according to the comment:
// the arguments were not loaded from TCCL so we need to deep clone them into the TCCL // because the test method runs from a class loaded from the TCCL
Unfortunately it seems that au.com.dius.pact.provider.junit5.PactVerificationContext
cannot be serialized/deserialized by XStream. I tried to run the test without @QuarkusTest
and simply tried to serialize/deserialize the PactVerificationContext
using XStreamDeepClone and ran into the exact same issue:
@BeforeEach
void before(PactVerificationContext context) {
context.setTarget(new AmpqTestTarget());
var deepClone = new XStreamDeepClone(getClass().getClassLoader());
var b = deepClone.clone(context); // Exception happens
}
We can't avoid deep cloning since the arguments need to converted to be loaded by the ThreadContext ClassLoader. What does probably need to be improved is the deep clone implementation itself. Currently we have the simplest possible solution that works for most cases, but it clearly needs improvement
@geoand can you tell if deep cloning can be avoided once JUnit5 resolves the issue https://github.com/junit-team/junit5/issues/201 ?
I see that #9886 has been resolved to fix the Supplier use case in a very specific way; however I can't see pointers to a general solution to solve the problem in this issue for example.
Yes, if JUnit fixes that issue (we have been monitoring it), then all nastiness of doing the deep cloone should go away
Is there some update on that issue? I just tested with Quarkus 1.11.1.Final and pact 4.1.15, the issue is the same.
Have any workarounds been identified for this issue, or is Pact unable to run with Quarkus for now?
I just faced the same issue here.
If you run with this PR: https://github.com/quarkusio/quarkus/pull/17306
And add the following to application.properties:
quarkus.class-loading.parent-first-artifacts=au.com.dius:pact-jvm-consumer,au.com.dius:pact-jvm-consumer-java8,au.com.dius:pact-jvm-junit5,au.com.dius:pact-jvm-core-matchers,au.com.dius:pact-jvm-core-model,au.com.dius:pact-jvm-core-pact-broker,au.com.dius:pact-jvm-core-support,au.com.dius:pact-jvm-provider,au.com.dius:pact-jvm-provider-junit5
Then Pact will work.
Ideally this would add these artifact to Quarkus as being parent-first so it would 'just work', however the only place that really makes sense is core, which does not really feel right. @geoand WDYT?
Sure, it's not ideal to have this configuration in the core module, but we already do it for mockito (which no reasonable person would use outside of a test), so I think it's fine.
Did this resolution work for anyone here? I'm still getting the exact same error, and I've updated to the Quarkus version where the PR is baselined.
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>2.0.0.Alpha3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
I've updated my Quarkus Maven Plugin to the same, and I've made the necessary additions to application.properties
.
@stuartwdouglas used for the fix the old pact artifact ids which were used until Apr, 2020.
For me it failed because I am using the latest ids which are:
`
<parentFirstArtifact>au.com.dius.pact.core:support</parentFirstArtifact>
<parentFirstArtifact>au.com.dius.pact.core:pactbroker</parentFirstArtifact>
<parentFirstArtifact>au.com.dius.pact:consumer</parentFirstArtifact>
<parentFirstArtifact>au.com.dius.pact.consumer:junit5</parentFirstArtifact>
<parentFirstArtifact>au.com.dius.pact:provider</parentFirstArtifact>
<parentFirstArtifact>au.com.dius.pact.provider:junit5</parentFirstArtifact>`
I was able to make it work by added those to core/runtime/pom.xml
.
@stuartwdouglas should I do a pull request with those appended to the list or should I replace the old artifact ids?
Go ahead and add the new coordinates to the list
@skattela I'm extremely grateful to your amazing eye!
Looks like my application.properties
component for the fix should be adjusted then as well.
I dont think that you need the entries in the application.properties
. For me it works without them.
The required changes are now merged and part of 2.0.0.CR3.
Here you can find an example of a pact contract test with a Quarkus consumer and a Quarkus provider.
@skattela I'm missing from your example how to use CDI managed beans from Quarkus in the Pact verification test.
In our case, we want to use a service to get the provider into a state, but the injected service is always null.
More specifically, in our @BeforeEach
JUnit callback the injected beans are not null, but then in the method annotated with @State
, the beans are null - I assume they are executed in a different context.
About my previous comment: I investigated this issue and found out, that with that setup we generate two different test class instances. I think this is normally also the case, but here Pact uses the instance, where Quarkus does not inject anything.
Here's the first instance creation (which will then be used by Pact)
https://github.com/quarkusio/quarkus/blob/2.6/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java#L687
A little below initTestState(extensionContext, state);
is called, and it creates the "proper" instance:
https://github.com/quarkusio/quarkus/blob/2.6/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java#L727
Maybe we can return the actualTestInstance
within interceptTestClassConstructor()
.
@geoand I think this is a question for you
EDIT: I opened this as its own issue, see #22611
Describe the bug FollowUp to #8978 @tgippi After Upgrading to Quarkus 1.5.0.Final Provider-Tests are still not possible, because the QuarkusTestExtension fails to xstream.deepCopy some Test-Context
Expected behavior Tests should run, like in Quarkus 1.2.x
Actual behavior
To Reproduce checkout
git@github.com:Sabartius/quarkus-pact-issue.git
run with
mvn -P1.5 clean test
Configuration
Screenshots
Environment (please complete the following information):
uname -a
orver
:java -version
: Java 11mvnw --version
orgradlew --version
): Maven 3.6.3Additional context