Search code examples
javaquarkusquarkus-testing

Is there a way to create a Quarkus Test Resource of the application itself?


I am attempting to create a java application that will communicate with other instances of the application hosted by peers via HTTP requests. As such, I want to be able to generate test cases that simulate different nodes communicating with one another. Is there a way of creating a QuarkusTestResourceLifecycleManager or similar that will spin up an instance of my Quarkus application (ideally where I can specify the port)? Then I am able to create predictable test scenarios where various peers are engaging with one another.

I have scoured all Quarkus documentation in great detail and have not been able to find what I am looking for.

I have attempted something similar to the below:

public class TestResource implements QuarkusTestResourceLifecycleManager {

    @Override
    public Map<String, String> start() {
        
        Quarkus.run("-Dquarkus.http.port=8082");

        return Map.of(
                ConfigProperties.QUARKUS_PORT,
                "8082"
        );
    }

    @Override
    public void stop() {
        Quarkus.asyncExit();
    }
}

Unfortunately, this has not had the desired result but I hope it highlights what I am attempting to achieve.


Solution

  • @QuarkusTest just spin up a single instance of your application so the only way to have multiple instances of your application is to emulate them using Wiremock as describe in official doc and stub all you need for you test.