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

UnsupportedOperationException while running a QuarkusUnitTest with DevServices #19325

Closed
gastaldi opened this issue Aug 10, 2021 · 7 comments · Fixed by #19329
Closed

UnsupportedOperationException while running a QuarkusUnitTest with DevServices #19325

gastaldi opened this issue Aug 10, 2021 · 7 comments · Fixed by #19329
Labels
area/devservices kind/bug Something isn't working
Milestone

Comments

@gastaldi
Copy link
Contributor

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

@gastaldi gastaldi added the kind/bug Something isn't working label Aug 10, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Aug 10, 2021

/cc @stuartwdouglas

@stuartwdouglas
Copy link
Member

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

@gastaldi
Copy link
Contributor Author

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

@gastaldi
Copy link
Contributor Author

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

@stuartwdouglas
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Member

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

stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue Aug 10, 2021
I am sure we used to have this but it seems to have gotten lost
somewhere.

Fixes quarkusio#19325
@quarkus-bot quarkus-bot bot added this to the 2.2 - main milestone Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/devservices kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants