Skip to content

Commit

Permalink
ArC: log warning about removed beans for BeanContainer operations
Browse files Browse the repository at this point in the history
- this warning got accidentally removed in
#28112 (quarkus 2.14)
  • Loading branch information
mkouba committed Sep 1, 2023
1 parent 4c0340a commit c1e6248
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.quarkus.arc.impl.ArcContainerImpl;
import io.quarkus.test.QuarkusUnitTest;

public class ApiLookupProblemDetectedTest {
public class ArcContainerLookupProblemDetectedTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
Expand All @@ -31,10 +31,10 @@ public class ApiLookupProblemDetectedTest {
Formatter fmt = new PatternFormatter("%m");
String message = fmt.format(warning);
assertTrue(message.contains(
"Stack frame: io.quarkus.arc.test.unused.ApiLookupProblemDetectedTest.testWarning"),
"Stack frame: io.quarkus.arc.test.unused.ArcContainerLookupProblemDetectedTest.testWarning"),
message);
assertTrue(message.contains(
"Required type: class io.quarkus.arc.test.unused.ApiLookupProblemDetectedTest$Alpha"),
"Required type: class io.quarkus.arc.test.unused.ArcContainerLookupProblemDetectedTest$Alpha"),
message);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.quarkus.arc.test.unused;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.logging.Formatter;
import java.util.logging.LogRecord;

import jakarta.enterprise.context.ApplicationScoped;

import org.jboss.logmanager.formatters.PatternFormatter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.arc.Arc;
import io.quarkus.arc.impl.ArcContainerImpl;
import io.quarkus.test.QuarkusUnitTest;

public class ArcContainerSupplierLookupProblemDetectedTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot(root -> root
.addClasses(Alpha.class))
.setLogRecordPredicate(log -> ArcContainerImpl.class.getPackage().getName().equals(log.getLoggerName()))
.assertLogRecords(records -> {
LogRecord warning = records.stream()
.filter(l -> l.getMessage().contains("programmatic lookup problem detected")).findAny().orElse(null);
assertNotNull(warning);
Formatter fmt = new PatternFormatter("%m");
String message = fmt.format(warning);
assertTrue(message.contains(
"Stack frame: io.quarkus.arc.test.unused.ArcContainerSupplierLookupProblemDetectedTest.testWarning"),
message);
assertTrue(message.contains(
"Required type: class io.quarkus.arc.test.unused.ArcContainerSupplierLookupProblemDetectedTest$Alpha"),
message);
});

@Test
public void testWarning() {
// Note that the warning is only displayed once, subsequent calls use a cached result
assertNull(Arc.container().beanInstanceSupplier(Alpha.class));
}

// unused bean, will be removed
@ApplicationScoped
static class Alpha {

public String ping() {
return "ok";
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.quarkus.arc.impl.ArcContainerImpl;
import io.quarkus.test.QuarkusUnitTest;

public class ArcLookupProblemDetectedTest {
public class CDIProviderLookupProblemDetectedTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
Expand All @@ -32,10 +32,10 @@ public class ArcLookupProblemDetectedTest {
Formatter fmt = new PatternFormatter("%m");
String message = fmt.format(warning);
assertTrue(message.contains(
"Stack frame: io.quarkus.arc.test.unused.ArcLookupProblemDetectedTest"),
"Stack frame: io.quarkus.arc.test.unused.CDIProviderLookupProblemDetectedTest"),
message);
assertTrue(message.contains(
"Required type: class io.quarkus.arc.test.unused.ArcLookupProblemDetectedTest$Alpha"),
"Required type: class io.quarkus.arc.test.unused.CDIProviderLookupProblemDetectedTest$Alpha"),
message);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ private <T> Supplier<InstanceHandle<T>> createInstanceSupplier(boolean resolveAm
if (qualifiers == null || qualifiers.length == 0) {
qualifiers = new Annotation[] { Default.Literal.INSTANCE };
}
Set<InjectableBean<?>> resolvedBeans = resolved.getValue(new Resolvable(type, qualifiers));
Resolvable resolvable = new Resolvable(type, qualifiers);
Set<InjectableBean<?>> resolvedBeans = resolved.getValue(resolvable);
if (resolvedBeans.isEmpty()) {
scanRemovedBeans(resolvable);
}
Set<InjectableBean<?>> filteredBean = resolvedBeans;
if (resolvedBeans.size() > 1) {
if (resolveAmbiguities) {
Expand Down

0 comments on commit c1e6248

Please sign in to comment.