-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
ArC - enable implementing all types of interception with single method #15633
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...rc/test/java/io/quarkus/arc/test/interceptors/mixed/BusinessLifecycleInterceptorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.quarkus.arc.test.interceptors.mixed; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.annotation.Priority; | ||
import javax.enterprise.context.Dependent; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
public class BusinessLifecycleInterceptorTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(MyTransactional.class, SimpleBean.class, | ||
SimpleInterceptor.class); | ||
|
||
public static final AtomicInteger INTERCEPTORS_CALLED = new AtomicInteger(); | ||
|
||
@Test | ||
public void testInterception() { | ||
InstanceHandle<SimpleBean> instance = Arc.container().instance(SimpleBean.class); | ||
SimpleBean simpleBean = instance.get(); | ||
assertEquals(1, INTERCEPTORS_CALLED.get()); | ||
assertEquals(2, simpleBean.ping()); | ||
assertEquals(2, INTERCEPTORS_CALLED.get()); | ||
} | ||
|
||
@Dependent | ||
@MyTransactional | ||
static class SimpleBean { | ||
|
||
int ping() { | ||
return 0; | ||
} | ||
|
||
} | ||
|
||
@Priority(1) | ||
@MyTransactional | ||
@Interceptor | ||
public static class SimpleInterceptor { | ||
|
||
@PostConstruct | ||
@PreDestroy | ||
@AroundInvoke | ||
Object intercept(InvocationContext ctx) throws Exception { | ||
return INTERCEPTORS_CALLED.incrementAndGet(); | ||
} | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...jects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/mixed/MyTransactional.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkus.arc.test.interceptors.mixed; | ||
|
||
import static java.lang.annotation.ElementType.CONSTRUCTOR; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.interceptor.InterceptorBinding; | ||
|
||
@Target({ TYPE, CONSTRUCTOR }) | ||
@Retention(RUNTIME) | ||
@InterceptorBinding | ||
public @interface MyTransactional { | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also allow
ArcInvocationContext
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point but I don't think it would work right now... let me check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this would actually require some more work, because we also generate the interceptor beans that implement
javax.enterprise.inject.spi.Interceptor.intercept(InterceptionType, T, InvocationContext)
etc. We can create a feature request though. Currently, you would need to cast theInvocationContext
inside the interceptor method. @manovotn WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, it just occurred to me when I saw the code :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #15660