forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Arc to deal with final methods of beans that needs to be proxied
This is done in the same manner that is already present for interceptors and is very useful for Kotlin code where methods are final by default Fixes: quarkusio#10290
- Loading branch information
Showing
7 changed files
with
214 additions
and
44 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
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
106 changes: 106 additions & 0 deletions
106
...ployment/src/test/java/io/quarkus/arc/test/unproxyable/RequestScopedFinalMethodsTest.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,106 @@ | ||
package io.quarkus.arc.test.unproxyable; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.context.RequestScoped; | ||
import javax.enterprise.event.Event; | ||
import javax.enterprise.event.Observes; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
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.ManagedContext; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class RequestScopedFinalMethodsTest { | ||
|
||
@RegisterExtension | ||
public static QuarkusUnitTest container = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(RequestScopedBean.class)); | ||
|
||
@Test | ||
public void testRequestScopedBeanWorksProperly() { | ||
ArcContainer container = Arc.container(); | ||
ManagedContext requestContext = container.requestContext(); | ||
requestContext.activate(); | ||
|
||
InstanceHandle<RequestScopedBean> handle = container.instance(RequestScopedBean.class); | ||
Assertions.assertTrue(handle.isAvailable()); | ||
|
||
RequestScopedBean bean = handle.get(); | ||
Assertions.assertNull(bean.getProp()); | ||
bean.setProp(100); | ||
Assertions.assertEquals(100, bean.getProp()); | ||
|
||
requestContext.terminate(); | ||
requestContext.activate(); | ||
|
||
handle = container.instance(RequestScopedBean.class); | ||
bean = handle.get(); | ||
Assertions.assertTrue(handle.isAvailable()); | ||
Assertions.assertNull(bean.getProp()); | ||
} | ||
|
||
@RequestScoped | ||
static class RequestScopedBean { | ||
private Integer prop = null; | ||
|
||
public final Integer getProp() { | ||
return prop; | ||
} | ||
|
||
public final void setProp(Integer prop) { | ||
this.prop = prop; | ||
} | ||
} | ||
|
||
@Dependent | ||
static class StringProducer { | ||
|
||
@Inject | ||
Event<String> event; | ||
|
||
void fire(String value) { | ||
event.fire(value); | ||
} | ||
|
||
} | ||
|
||
@Singleton | ||
static class StringObserver { | ||
|
||
private List<Integer> events; | ||
|
||
@Inject | ||
RequestScopedBean requestScopedBean; | ||
|
||
@PostConstruct | ||
void init() { | ||
events = new CopyOnWriteArrayList<>(); | ||
} | ||
|
||
void observeSync(@Observes Integer value) { | ||
Integer oldValue = requestScopedBean.getProp(); | ||
Integer newValue = oldValue == null ? value : value + oldValue; | ||
requestScopedBean.setProp(newValue); | ||
events.add(newValue); | ||
} | ||
|
||
List<Integer> getEvents() { | ||
return events; | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.