Skip to content

Commit

Permalink
Fix test ClassLoader issue
Browse files Browse the repository at this point in the history
This prevents the base runtime CL from
loading deployment classes.

Fixes quarkusio#16810
Fixes quarkusio#16804
  • Loading branch information
stuartwdouglas committed Apr 28, 2021
1 parent 6c26085 commit 4a53153
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 22 deletions.
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
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
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

0 comments on commit 4a53153

Please sign in to comment.