quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

UnsupportedOperationException while running a QuarkusUnitTest with DevServices #19325

Closed gastaldi closed 3 years ago

gastaldi commented 3 years ago

Describe the bug

Having a test like the following:

package io.quarkus.registry.app.services;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import io.quarkus.test.QuarkusUnitTest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;

public class RegistryDescriptorMavenResourceTest {

    @RegisterExtension
    static final QuarkusUnitTest config = new QuarkusUnitTest()
            .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
                    .addAsResource(new StringAsset("quarkus.registry.groupId=foo"), "application.properties"));

    @Test
    void should_use_custom_group_id() {
        given()
                .get("/maven/foo/quarkus-registry-descriptor/1.0-SNAPSHOT/quarkus-registry-descriptor-1.0-SNAPSHOT.json")
                .then()
                .statusCode(200)
                .header(HttpHeaders.CONTENT_TYPE, containsString(MediaType.APPLICATION_JSON))
                .body("descriptor.artifact", is("foo:quarkus-registry-descriptor::json:1.0-SNAPSHOT"),
                        "platforms.artifact", is("foo:quarkus-platforms::json:1.0-SNAPSHOT"));

    }
}

The following error is thrown when trying to run the test:

Caused by: java.lang.UnsupportedOperationException
    at io.quarkus.test.junit.RunningAppConfigResolver$1.unwrap(RunningAppConfigResolver.java:57)
    at io.quarkus.runtime.configuration.ConfigUtils.isPropertyPresent(ConfigUtils.java:208)
    at io.quarkus.datasource.deployment.spi.DevServicesDatasourceConfigurationHandlerBuildItem$2.test(DevServicesDatasourceConfigurationHandlerBuildItem.java:68)
    at io.quarkus.datasource.deployment.spi.DevServicesDatasourceConfigurationHandlerBuildItem$2.test(DevServicesDatasourceConfigurationHandlerBuildItem.java:64)
    at io.quarkus.datasource.deployment.devservices.DevServicesDatasourceProcessor.startDevDb(DevServicesDatasourceProcessor.java:234)
    at io.quarkus.datasource.deployment.devservices.DevServicesDatasourceProcessor.launchDatabases(DevServicesDatasourceProcessor.java:114)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:820)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
    at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2442)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1476)
    at java.base/java.lang.Thread.run(Thread.java:829)
    at org.jboss.threads.JBossThread.run(JBossThread.java:501)

Expected behavior

The test would run

Actual behavior

Test fails with UnsupportedOperationException

How to Reproduce?

Run the test above with a project containing:

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-hibernate-orm-panache</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-jdbc-postgresql</artifactId>
    </dependency>

Output of uname -a or ver

Fedora 34

Output of java -version

11

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.1.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Maven 3.8.1

Additional information

No response

quarkus-bot[bot] commented 3 years ago

/cc @stuartwdouglas

stuartwdouglas commented 3 years ago

I tried this and it worked, do you have a reproducer?

gastaldi commented 3 years ago

Heh, this test was my reproducer, I had it failing in https://github.com/quarkusio/registry.quarkus.io

gastaldi commented 3 years ago

I ran the test from inside Intellij IDEA, if that helps

stuartwdouglas commented 3 years ago

You can't mix QuarkusTest and QuarkusUnitTest. I swear we used to have error detection for this but I can't seem to find it.

gastaldi commented 3 years ago

You can't mix QuarkusTest and QuarkusUnitTest. I swear we used to have error detection for this but I can't seem to find it.

Mix how? The test doesn't have any @QuarkusTest afaik

stuartwdouglas commented 3 years ago

The module does though, QuarkusTest starts quarkus once and leaves it running, QuarkusUnitTest starts/stops each time.