forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#30651 from mkouba/issue-30636
ArC - use reflection fallback for PreDestroy callbacks if needed
- Loading branch information
Showing
6 changed files
with
87 additions
and
60 deletions.
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
21 changes: 0 additions & 21 deletions
21
.../src/test/java/io/quarkus/arc/test/interceptors/postConstruct/inherited/OriginalBean.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
...test/interceptors/postConstruct/inherited/PackagePrivatePostConstructInheritanceTest.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...rc/tests/src/test/java/io/quarkus/arc/test/lifecyclecallbacks/inherited/OriginalBean.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,30 @@ | ||
package io.quarkus.arc.test.lifecyclecallbacks.inherited; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class OriginalBean { | ||
|
||
static final AtomicBoolean POST_CONSTRUCT = new AtomicBoolean(); | ||
static final AtomicBoolean PRE_DESTROY = new AtomicBoolean(); | ||
|
||
// package private, not visible from AlternativeBean without reflection access | ||
@PostConstruct | ||
void postConstruct() { | ||
POST_CONSTRUCT.set(true); | ||
} | ||
|
||
@PreDestroy | ||
void preDestroy() { | ||
PRE_DESTROY.set(true); | ||
} | ||
|
||
public String ping() { | ||
return OriginalBean.class.getSimpleName(); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
.../quarkus/arc/test/lifecyclecallbacks/inherited/PackagePrivateCallbackInheritanceTest.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,42 @@ | ||
package io.quarkus.arc.test.lifecyclecallbacks.inherited; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import io.quarkus.arc.test.lifecyclecallbacks.inherited.subpackage.AlternativeBean; | ||
|
||
public class PackagePrivateCallbackInheritanceTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(AlternativeBean.class, OriginalBean.class); | ||
|
||
@Test | ||
public void testCallbacks() { | ||
ArcContainer container = Arc.container(); | ||
InstanceHandle<OriginalBean> origBeanInstance = container.instance(OriginalBean.class); | ||
InstanceHandle<AlternativeBean> alternativeBeanInstance = container.instance(AlternativeBean.class); | ||
|
||
assertTrue(origBeanInstance.isAvailable()); | ||
assertTrue(alternativeBeanInstance.isAvailable()); | ||
|
||
// AlternativeBean overrides the OriginalBean | ||
assertEquals(origBeanInstance.getBean(), alternativeBeanInstance.getBean()); | ||
assertEquals(AlternativeBean.class.getSimpleName(), alternativeBeanInstance.get().ping()); | ||
assertTrue(origBeanInstance.get().ping().equals(alternativeBeanInstance.get().ping())); | ||
|
||
// post construct should be invoked via during creation of AlternativeBean even though it's pack-private | ||
assertTrue(OriginalBean.POST_CONSTRUCT.get()); | ||
|
||
alternativeBeanInstance.destroy(); | ||
|
||
// pre destroy should be invoked even though it's package-private and AlternativeBean lives in a different package | ||
assertTrue(OriginalBean.PRE_DESTROY.get()); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...inherited/subpackage/AlternativeBean.java → ...inherited/subpackage/AlternativeBean.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