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

Add scope to beans to allow tests to pass in environments with implic… #455

Merged
merged 1 commit into from Oct 11, 2019

Conversation

manovotn
Copy link
Contributor

…it bean archives.

I came across this while trying to run FT tests in Quarkus.

Functionally this doesn't change anything. It merely makes the relevant tests pass in a CDI environment that operates on implicit bean archive. In the current master, these classes are automatically picked as beans anyway, the PR only adds a bean defining annotation on them.

There might be more tests needing similar changes but so far I've only seen these.

@manovotn
Copy link
Contributor Author

This is similar to what Ken described in #454

@@ -22,11 +22,14 @@

import org.eclipse.microprofile.faulttolerance.Fallback;

import javax.enterprise.context.Dependent;

@Dependent
public class FallbackMethodSubclassBeanB {
Copy link
Member

Choose a reason for hiding this comment

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

Interestingly, this shouldn't actually need an annotation to cause the test to pass, even if it's not picked up as a bean.

FallbackMethodSubclassBeanA extends this class and validating that bean should be sufficient to cause an exception to be thrown at startup.

Not having the superclass annotated is consistent with other similar tests in the same package (FallbackMethodSubclassOverrideBeanB, FallbackMethodSuperclassPrivateBeanB, etc.)

I'm wondering if it would improve these tests to have the beans.xml specify that only annotated beans should be included.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FallbackMethodSubclassBeanA extends this class and validating that bean should be sufficient to cause an exception to be thrown at startup.

Then I perhaps misunderstood the test?
The subclass (FallbackMethodSubclassBeanA) seems OK because that bean contains the fallback method and inherits the method annotated with @Fallback.
Whereas FallbackMethodSubclassBeanB, when picked up as a bean as validated fails because it declares a @Fallback method (named fallback), but that method is not declared anywhere in the bean/class hierarchy.
What am I missing @Azquelt ? :)

I'm wondering if it would improve these tests to have the beans.xml specify that only annotated beans should be included.

We might do that as well. That's basically what my and Ken's PR are aimed towards - for the tests to work in an environment with implicit bean archives.

Copy link
Member

@Azquelt Azquelt Oct 11, 2019

Choose a reason for hiding this comment

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

You're not allowed to reference a fallback method from a subclass.

We decided on that to try to be consistent with the guidelines in the Common Annotations for the Java Platform spec (section 2.1). Basically, I should be able to look at the @Fallback annotation and know what it's going to do without having to look further around the class hierarchy.

The relevant part of the fault tolerance spec is in 8.1.2:

When fallbackMethod is used a FaultToleranceDefinitionException will be thrown if any of the following constraints are not met:

  • The named fallback method must be on the same class, a superclass or an implemented interface of the class which declares the annotated method
    [...]
  • The named fallback method must be accessible from the class which declares the annotated method

Note: this doesn't prevent you from referencing a public or protected fallback method which is in the same class and then overriding that method in a subclass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, thanks for explanation!
In that case, we should probably add @Vetoed to FallbackMethodSubclassBeanB so that it doesn't get picked up and validated accidentally because that leads to the same exception as the one the test is originally supposed to cover.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I agree, the test doesn't currently test what it's supposed to. Vetoing the class is probably clearer than excluding non-annotated classes in the beans.xml.

@manovotn
Copy link
Contributor Author

@Azquelt I have amended the PR, it now adds the scope to one test and vetoes the other bean.

Copy link
Member

@Azquelt Azquelt left a comment

Choose a reason for hiding this comment

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

Thanks :)

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.

None yet

4 participants