quarkusio / quarkus

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

Dev Services does not take into account properties defined in QuarkusTestResource #19296

Open Sgitario opened 3 years ago

Sgitario commented 3 years ago

Describe the bug

Having a test with:

@QuarkusTest
@QuarkusTestResource(SslStrimziKafkaTestResource.class)
public class SslAlertMonitorTest {
   // ...
}

Where SslStrimziKafkaTestResource is:

public class SslStrimziKafkaTestResource implements QuarkusTestResourceLifecycleManager {

    private final SslStrimziKafkaContainer kafka = new SslStrimziKafkaContainer();

    @Override
    public Map<String, String> start() {
        kafka.start();
        Map<String, String> properties = new HashMap<>();
        properties.put("kafka.bootstrap.servers", kafka.getBootstrapServers());
        properties.put("quarkus.kafka-streams.bootstrap-servers", kafka.getBootstrapServers());
        return properties;
    }

    @Override
    public void stop() {
        if (kafka != null) {
            kafka.close();
        }
    }
}

When running the test, I would have expected the Kafka Dev Services to not being started as I'm adding the property kafka.bootstrap.servers, but the dev services is created:

2021-08-09 11:29:28,528 INFO  [org.tes.DockerClientFactory] (build-26) Checking the system...
2021-08-09 11:29:28,528 INFO  [org.tes.DockerClientFactory] (build-26) ✔︎ Docker server version should be at least 1.6.0
2021-08-09 11:29:28,531 INFO  [org.tes.uti.ImageNameSubstitutor] (build-26) Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
2021-08-09 11:29:29,160 INFO  [org.tes.DockerClientFactory] (build-26) ✔︎ Docker environment should have more than 2GB free disk space
2021-08-09 11:29:29,385 INFO  [🐳 .5.5]] (build-26) Creating container for image: vectorized/redpanda:v21.5.5
2021-08-09 11:29:29,652 INFO  [🐳 .5.5]] (build-26) Starting container with ID: 15552de7722b6bf3c29aee76e57335af66070333e284085d52c1fef5be304c18
2021-08-09 11:29:30,078 INFO  [🐳 .5.5]] (build-26) Container vectorized/redpanda:v21.5.5 is starting: 15552de7722b6bf3c29aee76e57335af66070333e284085d52c1fef5be304c18
2021-08-09 11:29:31,987 INFO  [🐳 .5.5]] (build-26) Container vectorized/redpanda:v21.5.5 started in PT2.629393S

I don't think this is a Kafka Dev Services related thing, but a general issue for other dev services.

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

999-SNAPSHOT

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

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

No response

Additional information

No response

quarkus-bot[bot] commented 3 years ago

/cc @stuartwdouglas

stuartwdouglas commented 3 years ago

Unfortunately fixing this would be very complex, its an ordering issue.

QuarkusTestResource needs to be loaded in the Runtime ClassLoader, so it has access to the application classes, but DevServices are started in the deployment phase, so DevServices are already started by the time QuarkusTestResource is ready to be run.

In theory we could split up DevServices to run potentially run after QuarkusTestResource, but it is a fairly big and complex change.

For now you will need to manually disable DevServices.