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

Fix test ClassLoader issue #16829

Merged
merged 1 commit into from
May 4, 2021
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 @@ -2,6 +2,9 @@

import static org.hamcrest.core.Is.is;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
Expand All @@ -14,6 +17,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.deployment.util.FileUtil;
import io.quarkus.runtime.StartupEvent;
import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;
Expand All @@ -24,11 +28,21 @@
public class AdditionalLocationsTest {
@RegisterExtension
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(DevBean.class)
.addAsResource(new StringAsset("quarkus.config.locations=additional.properties\n"),
"application.properties")
.addAsResource(new StringAsset("additional.property=1234\n"), "additional.properties"));
.setArchiveProducer(() -> {
try {
String props = new String(FileUtil.readFileContents(
AdditionalLocationsTest.class.getClassLoader().getResourceAsStream("application.properties")),
StandardCharsets.UTF_8);

return ShrinkWrap.create(JavaArchive.class)
.addClasses(DevBean.class)
.addAsResource(new StringAsset(props + "\nquarkus.config.locations=additional.properties\n"),
"application.properties")
.addAsResource(new StringAsset("additional.property=1234\n"), "additional.properties");
} catch (IOException e) {
throw new RuntimeException(e);
}
});

@BeforeAll
static void beforeAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DSAPublicKey getPublicKey() {
}

public void setPublicKey(DSAPublicKey publicKey) {
log.infof("setPublicKey, key=%s", publicKey);
log.debugf("setPublicKey, key=%s", publicKey);
this.publicKey = publicKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class GrpcReflectionTest {
.addPackage(HealthGrpc.class.getPackage())
.addPackage(MutinyReflectableServiceGrpc.class.getPackage())
.addClass(MyReflectionService.class))
.setFlatClassPath(true)
.withConfigurationResource("reflection-config.properties");

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ public synchronized QuarkusClassLoader getBaseRuntimeClassLoader() {
for (Path root : quarkusBootstrap.getApplicationRoot()) {
builder.addElement(ClassPathElement.fromPath(root));
}
} else {
for (Path root : quarkusBootstrap.getApplicationRoot()) {
builder.addBannedElement(ClassPathElement.fromPath(root));
}
}

//additional user class path elements first
Expand All @@ -228,6 +232,7 @@ public synchronized QuarkusClassLoader getBaseRuntimeClassLoader() {
} else {
for (Path root : i.getArchivePath()) {
hotReloadPaths.add(root);
builder.addBannedElement(ClassPathElement.fromPath(root));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@
public class MicroProfileHealthEnabledTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer(
() -> ShrinkWrap.create(JavaArchive.class)
.addPackage(HealthGrpc.class.getPackage())
.addClass(FakeService.class))
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setFlatClassPath(true)
.setArchiveProducer(
() -> ShrinkWrap.create(JavaArchive.class)
.addPackage(HealthGrpc.class.getPackage())
.addClass(FakeService.class))
.withConfigurationResource("health-config.properties");

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ quarkus.log.category.\"org.apache.kafka\".level=WARN
quarkus.log.category.\"org.apache.zookeeper\".level=WARN

# enable health check
quarkus.kafka.health.enabled=true

# TODO: this should not be needed, but Avro does not seem to use the correct CL
# This will also cause dev mode issues
quarkus.test.flat-class-path=true
quarkus.kafka.health.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ quarkus.log.category.\"org.apache.kafka\".level=WARN
quarkus.log.category.\"org.apache.zookeeper\".level=WARN

# enable health check
quarkus.kafka.health.enabled=true

# TODO: this should not be needed, but Avro does not seem to use the correct CL
# This will also cause dev mode issues
quarkus.test.flat-class-path=true
quarkus.kafka.health.enabled=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

#picocli attempts to load resource bundles from its own CL rather than the TCCL
quarkus.test.flat-class-path=true
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
import org.jboss.arquillian.test.spi.TestClass;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.container.ClassContainer;
Expand Down Expand Up @@ -29,7 +30,7 @@ public void process(Archive<?> applicationArchive, TestClass testClass) {
if (ClassContainer.class.isInstance(applicationArchive) && testClass.getJavaClass().getSuperclass() != null) {
ClassContainer<?> classContainer = ClassContainer.class.cast(applicationArchive);
Class<?> clazz = testClass.getJavaClass().getSuperclass();
while (clazz != Object.class && clazz != null) {
while (clazz != Object.class && clazz != null && clazz != Arquillian.class) {
classContainer.addClass(clazz);
clazz = clazz.getSuperclass();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
import org.jboss.arquillian.test.spi.TestClass;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.container.ClassContainer;
Expand Down Expand Up @@ -29,7 +30,7 @@ public void process(Archive<?> applicationArchive, TestClass testClass) {
if (ClassContainer.class.isInstance(applicationArchive) && testClass.getJavaClass().getSuperclass() != null) {
ClassContainer<?> classContainer = ClassContainer.class.cast(applicationArchive);
Class<?> clazz = testClass.getJavaClass().getSuperclass();
while (clazz != Object.class && clazz != null) {
while (clazz != Object.class && clazz != null && clazz != Arquillian.class) {
classContainer.addClass(clazz);
clazz = clazz.getSuperclass();
}
Expand Down
2 changes: 1 addition & 1 deletion tcks/resteasy-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<properties>

<!-- to avoid sudden surprises, checkout is pinned to a specific commit -->
<resteasy-reactive-testsuite.repo.ref>6bc5d1bacccaf45a7db968b57a262b8e84e4621b</resteasy-reactive-testsuite.repo.ref>
<resteasy-reactive-testsuite.repo.ref>82698545ef2f09b6b826d650502238cebf9f6171</resteasy-reactive-testsuite.repo.ref>

<exec.skip>${skipTests}</exec.skip>
<resteasy-reactive-testsuite.clone.skip>${exec.skip}</resteasy-reactive-testsuite.clone.skip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public void execute(BuildContext context) {
.setApplicationRoot(appLocation)
.setProjectRoot(appLocation)
.setIsolateDeployment(false)
.setFlatClassPath(true)
.setMode(QuarkusBootstrap.Mode.TEST);
for (Path i : libraries) {
bootstrapBuilder.addAdditionalApplicationArchive(new AdditionalDependency(i, false, true));
Expand Down