Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of rest client default scope #2940

Merged
merged 1 commit into from
Jul 4, 2019

Conversation

machi1990
Copy link
Member

Fixes #2798

/cc @geoand

@geoand
Copy link
Contributor

geoand commented Jun 23, 2019

Thanks @machi1990!

I will take a look most likely tomorrow. Perhaps @michalszynkiewicz would also like to review it

@geoand
Copy link
Contributor

geoand commented Jun 23, 2019

One comment, I think we should keep this to a single commit.

@machi1990
Copy link
Member Author

Thanks @machi1990!

I will take a look most likely tomorrow. Perhaps @michalszynkiewicz would also like to review it

Okay thanks @geoand . I still have a failing TCK, I thought opening a PR would help with figuring out why.

@geoand
Copy link
Contributor

geoand commented Jun 23, 2019

FWIW, here is an example of how I was debugging tests when I ran things locally:

 mvn clean  verify -f tcks/pom.xml -Dtest=InvokeWithJsonBProviderTest --projects 'io.quarkus:quarkus-tck-microprofile-rest-client'

@machi1990 machi1990 force-pushed the 2798 branch 2 times, most recently from 5c9e9fe to b7f99fb Compare June 23, 2019 16:08
@emmanuelbernard emmanuelbernard requested a review from geoand June 24, 2019 12:57
@geoand
Copy link
Contributor

geoand commented Jun 24, 2019

@machi1990 do you need any help with this one?

@machi1990
Copy link
Member Author

@machi1990 do you need any help with this one?

Hey @geoand, thanks. Sure. I am yet to figure out why the test are failing for Linux Build and passing for the other platforms.

Also, I got one TCK for default scope passing and not the other. But the integration test I added for the cases are passing. Any ideas?

@geoand
Copy link
Contributor

geoand commented Jun 24, 2019

I'll have to take a closer look later on today or tomorrow morning. If you find any fixes in the meantime, feel free to push :)

@geoand
Copy link
Contributor

geoand commented Jun 25, 2019

@machi1990 seems like you are making progress, 👍 . However I am guessing that there is still some corner case not addressed since CDIInvokeSimpleGetOperationTest and CDIInvokeAsyncSimpleGetOperationTest are failing with what looks like a CDI error that the PR indends to fix :)

@machi1990
Copy link
Member Author

CDIInvokeSimpleGetOperationTest

hey @geoand , thanks for checking my progress. Yes, I was able to take a look yesternight: had a day away from comp (was in conference).

So here is what I am observing locally, only running the failing test (which I believe to be just CDIInvokeSimpleGetOperationTest) passes:

mvn verify -f tcks/pom.xml --projects 'io.quarkus:quarkus-tck-microprofile-rest-client' -Dtest=HasSingletonScopeTest

If I only run the two tests which were excluded before this PR, they work just fine as well:

mvn verify -f tcks/pom.xml --projects 'io.quarkus:quarkus-tck-microprofile-rest-client' -Dtest=CDIInvokeAsyncSimpleGetOperationTest,CDIInvokeSimpleGetOperationTest

However, If I run the same tests by adding HasSingletonScopeTest test which seems to set the scope to Singleton through /mp-rest/scope leads to failure on the first test.

mvn verify -f tcks/pom.xml --projects 'io.quarkus:quarkus-tck-microprofile-rest-client' -Dtest=CDIInvokeSimpleGetOperationTest,HasSingletonScopeTest

Thoughts?

@geoand
Copy link
Contributor

geoand commented Jun 25, 2019

That's interesting for sure! I don't know enough about the tests to know what is going on, but what I would do is debug the tests (as described here) and try to figure out exactly what is happening.

@@ -127,6 +112,27 @@ public boolean skipValidation(InjectionTargetInfo target, ValidationRule rule) {
}
}

private Collection<ClassInfo> collectTargetClass() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified because to be able to create a default noArgConstructor for AppScope and RequestScope once. Otherwise, TCK tests in HasRequestScopeTest and HasAppScopeTest were failing with a <cinit> error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need validation from @mkouba on this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't hurt to describe what's actually changed and why? ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why
While working on this PR, I noticed the following error:

Caused by: java.lang.RuntimeException: Failed to start quarkus
	at io.quarkus.runner.ApplicationImpl1.<clinit>(ApplicationImpl1.zig:205)
	... 112 more
Caused by: java.lang.ClassFormatError: Duplicate method name "<init>" with signature "()V" in class file org/eclipse/microprofile/rest/client/tck/cditests/HasAppScopeTest$MyAppScopedApi
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
	at io.quarkus.runner.RuntimeClassLoader.findClass(RuntimeClassLoader.java:217)
	at io.quarkus.runner.RuntimeClassLoader.loadClass(RuntimeClassLoader.java:163)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.eclipse.microprofile.rest.client.tck.cditests.HasAppScopeTest_MyAppScopedApi_4a90cb1eedbe1d7e3f457833a0ee883318179f2e_Synthetic_Bean.<init>(HasAppScopeTest_MyAppScopedApi_4a90cb1eedbe1d7e3f457833a0ee883318179f2e_Synthetic_Bean.zig:120)
	at io.quarkus.arc.setup.Default_ComponentsProvider.getComponents(Default_ComponentsProvider.zig:222)
	at io.quarkus.arc.ArcContainerImpl.<init>(ArcContainerImpl.java:84)
	at io.quarkus.arc.Arc.initialize(Arc.java:18)
	at io.quarkus.arc.runtime.ArcDeploymentTemplate.getContainer(ArcDeploymentTemplate.java:33)
	at io.quarkus.deployment.steps.ArcAnnotationProcessor$build7.deploy_0(ArcAnnotationProcessor$build7.zig:53)
	at io.quarkus.deployment.steps.ArcAnnotationProcessor$build7.deploy(ArcAnnotationProcessor$build7.zig:141)
	at io.quarkus.runner.ApplicationImpl1.<clinit>(ApplicationImpl1.zig:191)
	... 112 more

When running rest-client tck tests notably when running and HasAppScopeTest or HasRequestScopeTest. My understanding is, we tried to generate a no arg constructor twice and looking at the modified code, an HashSet is used while ClassInfo does not declare an hashCode method leading to MyAppScopedApi.class being recorded twice.

What changed
Record a normal scoped bean class once based on its DotName which has a hashCode. The DotName is provided by ClassInfo.name().

Is that the way to go about it? Open to changing this to something different. @mkouba @geoand

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me, @mkouba WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@machi1990 otherwise the PR looks good! So pls revert the changes in NoArgsConstructorProcessor and just ignore the interfaces there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkouba @geoand thanks for your analysis.

Modifier.isInterface(annotationInstance.target().asClass().flags())

I'll revert this part and use this instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkouba did all the meaningful analysis 😆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkouba @geoand thanks for your analysis.

Modifier.isInterface(annotationInstance.target().asClass().flags())

I'll revert this part and use this instead.

This had been addressed. @mkouba @geoand

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let @mkouba review since he was the one that found the problem

<class name="org.eclipse.microprofile.rest.client.tck.cditests.HasRequestScopeTest">


<!-- excluded because of race scope configuration on SimpleGetApi interface -->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkouba I added a comment about here. If you run the tests one by one, they all pass. If you run them together, they fail randomly: one pass and not the other, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really weird and we should probably try to find the real cause first. I'll try to run the tests locally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think that the problem is that ConfigProvider.getConfig() caches the ConfigProviderResolver in a static field. We do work around this limitation in QuarkusConfigProducer by using ConfigProviderResolver.instance().getConfig() instead. I'll try to update the code and run the tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it didn't help most probably because the rest client beans are registered in STATIC_INIT and ConfigProviderResolver is re-set during RUNTIME_INIT...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mkouba, thanks for the investigation. How do you advise we proceed regarding this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #3089 - pls add this link to the relevant comment in the tck-suite.xml.

Then I think we can merge this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@mkouba mkouba merged commit 8d841dc into quarkusio:master Jul 4, 2019
@machi1990 machi1990 deleted the 2798 branch July 4, 2019 12:45
@gsmet gsmet added this to the 0.19.0 milestone Jul 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scope of MP REST Client is singleton by default
4 participants