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

ArC - minor cleanup #32221

Merged
merged 6 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import io.quarkus.builder.item.MultiBuildItem;

/**
* A build item that can be used to unwrap CDI or other proxies
* A build item that can be used to unwrap CDI <s>or other proxies</s>.
*
* @deprecated Use {@code io.quarkus.arc.ClientProxy.unwrap(T)} instead.
*/
@Deprecated(since = "3.0.0", forRemoval = true)
public final class ProxyUnwrapperBuildItem extends MultiBuildItem {

private final Function<Object, Object> unwrapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.quarkus.arc.deployment;

import io.quarkus.arc.ClientProxy;
import io.quarkus.arc.runtime.ClientProxyUnwrapper;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ProxyUnwrapperBuildItem;

public class ProxyUnwrapProcessor {

@BuildStep
ProxyUnwrapperBuildItem wrapper() {
return new ProxyUnwrapperBuildItem(ClientProxy::unwrap);
// ClientProxy::unwrap cannot be used because we need to serialize the unwrapper through a recorder method
return new ProxyUnwrapperBuildItem(new ClientProxyUnwrapper());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

/**
* Marker build item to indicate that a build step initializes a CDI bean "manually" through a
* {@link io.quarkus.runtime.annotations.Recorder}
* {@link io.quarkus.runtime.annotations.Recorder}.
* <p>
* A build step does not necessarily need to create an instance of this build item, declaring a
* {@code BuildProducer<RecorderBeanInitializedBuildItem>} parameter is enough.
* <p>
* If a build step consumes a {@code List<RecorderBeanInitializedBuildItem>} parameter then it will be executed after all build
* steps that produce this build item.
* <p>
* This build item is deprecated because initialization of a bean via a recorder method is considered a bad practice. Extension
* authors are encouraged to use {@link SyntheticBeanBuildItem} instead. See https://github.com/quarkusio/quarkus/issues/24441
* for more information.
*
* @deprecated use synthetic beans for bean initialization instead
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* once they are completed if
* needed.
*/
public class InitializtionTaskProcessor {
public class InitializationTaskProcessor {

@BuildStep
@Consume(SyntheticBeansRuntimeInitBuildItem.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import io.quarkus.arc.InstanceHandle;
import io.quarkus.arc.ManagedContext;

public class BeanContainerImpl implements BeanContainer {
class BeanContainerImpl implements BeanContainer {

private static final Logger LOGGER = Logger.getLogger(BeanContainerImpl.class.getName());

private final ArcContainer container;

public BeanContainerImpl(ArcContainer container) {
BeanContainerImpl(ArcContainer container) {
this.container = container;
}

Expand Down Expand Up @@ -64,9 +64,9 @@ public ManagedContext requestContext() {
return container.requestContext();
}

static final class DefaultInstanceFactory<T> implements BeanContainer.Factory<T> {
private static final class DefaultInstanceFactory<T> implements BeanContainer.Factory<T> {

final Class<T> type;
private final Class<T> type;

DefaultInstanceFactory(Class<T> type) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import io.quarkus.arc.AbstractAnnotationLiteral;
import io.quarkus.arc.ArcInvocationContext;

public class InterceptorBindings {
/**
*
* @see ArcInvocationContext#getInterceptorBindings()
*/
public final class InterceptorBindings {

@SuppressWarnings("unchecked")
public static Set<Annotation> getInterceptorBindings(InvocationContext invocationContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class ArcContextProvider implements ThreadContextProvider {

protected static final ThreadContextController NOOP_CONTROLLER = new ThreadContextController() {
private static final ThreadContextController NOOP_CONTROLLER = new ThreadContextController() {
@Override
public void endContext() throws IllegalStateException {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.mongodb.client.internal.MongoClientImpl;

import io.quarkus.arc.Arc;
import io.quarkus.arc.runtime.ClientProxyUnwrapper;
import io.quarkus.arc.ClientProxy;
import io.quarkus.mongodb.health.MongoHealthCheck;
import io.quarkus.test.QuarkusUnitTest;

Expand All @@ -39,8 +39,6 @@ public class DefaultAndNamedMongoClientConfigTest extends MongoWithReplicasTestB
@Any
MongoHealthCheck health;

private final ClientProxyUnwrapper unwrapper = new ClientProxyUnwrapper();

@AfterEach
void cleanup() {
if (client != null) {
Expand Down Expand Up @@ -74,7 +72,7 @@ public void testNamedDataSourceInjection() {
}

private void assertProperConnection(MongoClient client, int expectedPort) {
assertThat(unwrapper.apply(client)).isInstanceOfSatisfying(MongoClientImpl.class, c -> {
assertThat(ClientProxy.unwrap(client)).isInstanceOfSatisfying(MongoClientImpl.class, c -> {
assertThat(c.getCluster().getSettings().getHosts()).singleElement().satisfies(sa -> {
assertThat(sa.getPort()).isEqualTo(expectedPort);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.mongodb.client.MongoClient;
import com.mongodb.client.internal.MongoClientImpl;

import io.quarkus.arc.runtime.ClientProxyUnwrapper;
import io.quarkus.arc.ClientProxy;
import io.quarkus.mongodb.impl.ReactiveMongoClientImpl;
import io.quarkus.mongodb.reactive.ReactiveMongoClient;
import io.quarkus.test.QuarkusUnitTest;
Expand All @@ -34,8 +34,6 @@ public class MongoClientConfigTest extends MongoWithReplicasTestBase {
@Inject
ReactiveMongoClient reactiveClient;

private final ClientProxyUnwrapper unwrapper = new ClientProxyUnwrapper();

@AfterEach
void cleanup() {
if (reactiveClient != null) {
Expand All @@ -48,7 +46,7 @@ void cleanup() {

@Test
public void testClientConfiguration() {
MongoClientImpl clientImpl = (MongoClientImpl) unwrapper.apply(client);
MongoClientImpl clientImpl = (MongoClientImpl) ClientProxy.unwrap(client);
assertThat(clientImpl.getSettings().getConnectionPoolSettings().getMaxSize()).isEqualTo(2);
assertThat(clientImpl.getSettings().getConnectionPoolSettings().getMinSize()).isEqualTo(1);
assertThat(clientImpl.getSettings().getConnectionPoolSettings().getMaxConnectionIdleTime(TimeUnit.SECONDS))
Expand All @@ -73,7 +71,7 @@ public void testClientConfiguration() {

@Test
public void testReactiveClientConfiuration() {
ReactiveMongoClientImpl reactiveMongoClientImpl = (ReactiveMongoClientImpl) unwrapper.apply(reactiveClient);
ReactiveMongoClientImpl reactiveMongoClientImpl = (ReactiveMongoClientImpl) ClientProxy.unwrap(reactiveClient);
com.mongodb.reactivestreams.client.internal.MongoClientImpl clientImpl = (com.mongodb.reactivestreams.client.internal.MongoClientImpl) reactiveMongoClientImpl
.unwrap();
assertThat(clientImpl.getSettings().getConnectionPoolSettings().getMaxSize()).isEqualTo(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import com.mongodb.reactivestreams.client.internal.MongoClientImpl;

import io.quarkus.arc.Arc;
import io.quarkus.arc.ClientProxy;
import io.quarkus.arc.InjectableBean;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.arc.runtime.ClientProxyUnwrapper;
import io.quarkus.mongodb.health.MongoHealthCheck;
import io.quarkus.mongodb.impl.ReactiveMongoClientImpl;
import io.quarkus.mongodb.reactive.ReactiveMongoClient;
Expand All @@ -47,8 +47,6 @@ public class NamedReactiveMongoClientConfigTest extends MongoWithReplicasTestBas
@Any
MongoHealthCheck health;

private final ClientProxyUnwrapper unwrapper = new ClientProxyUnwrapper();

@AfterEach
void cleanup() {
if (client != null) {
Expand Down Expand Up @@ -80,7 +78,7 @@ public void checkHealth() {
}

private void assertProperConnection(ReactiveMongoClient client, int expectedPort) {
assertThat(unwrapper.apply(client)).isInstanceOfSatisfying(ReactiveMongoClientImpl.class, rc -> {
assertThat(ClientProxy.unwrap(client)).isInstanceOfSatisfying(ReactiveMongoClientImpl.class, rc -> {
Field mongoClientField;
try {
mongoClientField = ReactiveMongoClientImpl.class.getDeclaredField("client");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.lang.reflect.Constructor;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;

import jakarta.ws.rs.WebApplicationException;

Expand All @@ -18,12 +17,11 @@
import org.jboss.resteasy.spi.metadata.ResourceClass;
import org.jboss.resteasy.spi.metadata.ResourceConstructor;

import io.quarkus.arc.runtime.ClientProxyUnwrapper;
import io.quarkus.arc.ClientProxy;

public class QuarkusInjectorFactory extends InjectorFactoryImpl {

private static final Logger log = Logger.getLogger("io.quarkus.resteasy.runtime");
static final Function<Object, Object> PROXY_UNWRAPPER = new ClientProxyUnwrapper();

@SuppressWarnings("rawtypes")
@Override
Expand Down Expand Up @@ -65,13 +63,13 @@ public UnwrappingPropertyInjector(PropertyInjector delegate) {

@Override
public CompletionStage<Void> inject(Object target, boolean unwrapAsync) {
return delegate.inject(PROXY_UNWRAPPER.apply(target), unwrapAsync);
return delegate.inject(ClientProxy.unwrap(target), unwrapAsync);
}

@Override
public CompletionStage<Void> inject(HttpRequest request, HttpResponse response, Object target, boolean unwrapAsync)
throws Failure, WebApplicationException, ApplicationException {
return delegate.inject(request, response, PROXY_UNWRAPPER.apply(target), unwrapAsync);
return delegate.inject(request, response, ClientProxy.unwrap(target), unwrapAsync);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.mockito.AdditionalAnswers;
import org.mockito.Mockito;

import io.quarkus.arc.runtime.ClientProxyUnwrapper;
import io.quarkus.arc.ClientProxy;
import io.quarkus.test.junit.callback.QuarkusTestAfterConstructCallback;
import io.quarkus.test.junit.mockito.InjectSpy;

Expand All @@ -28,7 +28,7 @@ public void afterConstruct(Object testInstance) {
}

private Object createSpyAndSetTestField(Object testInstance, Field field, Object beanInstance, boolean delegate) {
Object unwrapped = new ClientProxyUnwrapper().apply(beanInstance);
Object unwrapped = ClientProxy.unwrap(beanInstance);
Object spy = delegate ? Mockito.mock(unwrapped.getClass(), AdditionalAnswers.delegatesTo(unwrapped))
: Mockito.spy(unwrapped);
field.setAccessible(true);
Expand Down