Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 0 additions & 84 deletions integration-tests/jpa-postgresql-withxml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
<name>Quarkus - Integration Tests - JPA - PostgreSQL with XML</name>
<description>Module that contains JPA related tests running with the PostgreSQL database</description>

<properties>
<postgres.url>jdbc:postgresql://localhost:5431/hibernate_orm_test</postgres.url>
</properties>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -161,86 +157,6 @@
</plugins>
</build>
</profile>

<profile>
<id>docker-postgresql</id>
<activation>
<property>
<name>start-containers</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>${postgres.image}</name>
<alias>postgresql</alias>
<run>
<env>
<POSTGRES_USER>hibernate_orm_test</POSTGRES_USER>
<POSTGRES_PASSWORD>hibernate_orm_test</POSTGRES_PASSWORD>
<POSTGRES_DB>hibernate_orm_test</POSTGRES_DB>
</env>
<ports>
<port>5431:5432</port>
</ports>
<wait>
<!-- For some reason, Postgres will tell us it's ready *twice*,
and that's the truth the second time only.
See https://github.com/fabric8io/docker-maven-plugin/issues/628
See also how the condition is configured in testcontainers:
https://github.com/testcontainers/testcontainers-java/blob/c64aab9fd5e3a452ee0faf793560327eb4da9841/modules/postgresql/src/main/java/org/testcontainers/containers/PostgreSQLContainer.java#L52-L55 -->
<time>20000</time>
<log>(?s)ready to accept connections.*ready to accept connections</log>
</wait>
</run>
</image>
</images>
<!--Stops all postgres images currently running, not just those we just started.
Useful to stop processes still running from a previously failed integration test run -->
<allContainers>true</allContainers>
</configuration>
<executions>
<execution>
<id>docker-start</id>
<phase>compile</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker-stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>docker-prune</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${docker-prune.location}</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
quarkus.datasource.username=hibernate_orm_test
quarkus.datasource.password=hibernate_orm_test
quarkus.datasource.jdbc.url=${postgres.url}
quarkus.datasource.jdbc.max-size=8

quarkus.hibernate-orm.packages=io.quarkus.it.jpa.postgresql.defaultpu
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/jpa-postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

By default, the tests of this module are disabled.

To run the tests in a standard JVM with PostgreSQL started as a Docker container, you can run the following command:
To run the tests in a standard JVM with PostgreSQL started as a Dev Service, you can run the following command:

```
mvn clean install -Dtest-containers -Dstart-containers
Expand All @@ -16,12 +16,12 @@ Additionally, you can generate a native image and run the tests for this native
mvn clean install -Dtest-containers -Dstart-containers -Dnative
```

If you don't want to run PostgreSQL as a Docker container, you can start your own PostgreSQL server. It needs to listen on the default port and have a database called `hibernate_orm_test` accessible to the user `hibernate_orm_test` with the password `hibernate_orm_test`.
If you don't want to run PostgreSQL as a Dev Service, you can start your own PostgreSQL server. It needs to listen on the default port and have a database called `hibernate_orm_test` accessible to the user `hibernate_orm_test` with the password `hibernate_orm_test`.

You can then run the tests as follows (either with `-Dnative` or not):

```
mvn clean install -Dtest-containers
mvn clean install -Dtest-containers -Dpostgres.url=jdbc:postgresql://...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this in your other PRs... but I think it's incorrect? postgres.url is no longer mentioned in the configuration of this integration test, so I don't think setting it will do anything.

In order for this to be true, I think you'd need to keep the line quarkus.datasource.jdbc.url=${postgres.url} in application.properties. And set the default value of postgres.url to an empty string in pom.xml, so that by default the configuration will look like quarkus.datasource.jdbc.url= (no value), which means dev services will kick in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That, or we remove this part of the README and expect people to always use dev services to run these tests. Which is perfectly fine IMO, but others might disagree -- @gsmet maybe?

```

If you have specific requirements, you can define a specific connection URL with `-Dpostgres.url=jdbc:postgresql://...`.
If you have specific requirements, you can also define a specific connection URL with `-Dpostgres.url=jdbc:postgresql://...`.
106 changes: 22 additions & 84 deletions integration-tests/jpa-postgresql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
<name>Quarkus - Integration Tests - JPA - PostgreSQL</name>
<description>Module that contains JPA related tests running with the PostgreSQL database</description>

<properties>
<postgres.url>jdbc:postgresql://localhost:5431/hibernate_orm_test</postgres.url>
</properties>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -46,6 +42,28 @@
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.junit.platform</groupId>-->
<!-- <artifactId>junit-platform-suite</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
Comment on lines +45 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed? Or maybe we need a comment to explain why it's here and commented out?

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<!-- Until we have testcontainers 2, which has https://github.com/testcontainers/testcontainers-java/issues/970, add back JUnit 4 so testcontainers doesn't break everything :( -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit4.version}</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
Expand Down Expand Up @@ -171,86 +189,6 @@
</plugins>
</build>
</profile>

<profile>
<id>docker-postgresql</id>
<activation>
<property>
<name>start-containers</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>${postgres.image}</name>
<alias>postgresql</alias>
<run>
<env>
<POSTGRES_USER>hibernate_orm_test</POSTGRES_USER>
<POSTGRES_PASSWORD>hibernate_orm_test</POSTGRES_PASSWORD>
<POSTGRES_DB>hibernate_orm_test</POSTGRES_DB>
</env>
<ports>
<port>5431:5432</port>
</ports>
<wait>
<!-- For some reason, Postgres will tell us it's ready *twice*,
and that's the truth the second time only.
See https://github.com/fabric8io/docker-maven-plugin/issues/628
See also how the condition is configured in testcontainers:
https://github.com/testcontainers/testcontainers-java/blob/c64aab9fd5e3a452ee0faf793560327eb4da9841/modules/postgresql/src/main/java/org/testcontainers/containers/PostgreSQLContainer.java#L52-L55 -->
<time>20000</time>
<log>(?s)ready to accept connections.*ready to accept connections</log>
</wait>
</run>
</image>
</images>
<!--Stops all postgres images currently running, not just those we just started.
Useful to stop processes still running from a previously failed integration test run -->
<allContainers>true</allContainers>
</configuration>
<executions>
<execution>
<id>docker-start</id>
<phase>compile</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker-stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>docker-prune</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${docker-prune.location}</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
quarkus.datasource.username=hibernate_orm_test
quarkus.datasource.password=hibernate_orm_test
quarkus.datasource.jdbc.url=${postgres.url}
quarkus.datasource.jdbc.max-size=8

quarkus.hibernate-orm.packages=io.quarkus.it.jpa.postgresql.defaultpu
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.quarkus.it.jpa.postgresql;

import static org.hamcrest.Matchers.is;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.restassured.RestAssured;

/* Exercises OverrideJdbcUrlBuildTimeConfigSource, which cannot coexist with dev services. */
@TestProfile(ConfigOverrideTest.Profile.class)
@QuarkusTest
public class ConfigOverrideTest {

@Test
public void base() {
RestAssured.when().get("/jpa/testfunctionality/base").then().body(is("OK"));
}

public static class Profile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
// Disable dev services so we know we're connecting to the right database
return Map.of("quarkus.devservices.enabled", "false");
}

@Override
public String getConfigProfile() {
return "someotherprofile";
}

@Override
public List<TestResourceEntry> testResources() {
return Collections.singletonList(new TestResourceEntry(PostgresTestResourceLifecycleManager.class));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigSource;

import io.quarkus.runtime.configuration.ConfigUtils;
import io.smallrye.config.Priorities;
import io.smallrye.config.common.MapBackedConfigSource;

Expand All @@ -23,6 +24,12 @@ public String getValue(final String propertyName) {
return super.getValue(propertyName);
}

boolean someotherprofile = ConfigUtils.isProfileActive("someotherprofile");
// This config source should only kick in when the custom profile is active, or dev services get disabled for all tests
if (!someotherprofile) {
return super.getValue(propertyName);
}

boolean isBuildTime = false;
for (ConfigSource configSource : ConfigProvider.getConfig().getConfigSources()) {
if (configSource.getName().equals("PropertiesConfigSource[source=Build system]")) {
Expand All @@ -31,10 +38,13 @@ public String getValue(final String propertyName) {
}
}

// Originally, the JDBC Extension queried the JDBC URL value at build time to either start or skip the DevService. In cases where the URL was an expansion, this would fail if the expansion is not available at build time. In the original issue, the JDBC URL was set as an expansion in Vault, only available at runtime.
// To simulate the original issue, the source sets quarkus.datasource.jdbc.url at build time, and sets it to an 'impossible' expansion.
if (isBuildTime) {
return "${postgres.url}";
return "${arbitrary.unavailable.value}";
}

// To keep things working, we can then either return nothing at runtime so that we default to the normal application config, or return valid config at runtime.
return super.getValue(propertyName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.quarkus.it.jpa.postgresql;

import java.util.Map;

import org.testcontainers.containers.PostgreSQLContainer;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

public class PostgresTestResourceLifecycleManager implements QuarkusTestResourceLifecycleManager {

private static PostgreSQLContainer<?> postgres;

@SuppressWarnings("resource")
@Override
public Map<String, String> start() {
postgres = new PostgreSQLContainer<>("postgres:14") // the exact value doesn't really matter here
.withDatabaseName("testdb")
.withUsername("test")
.withPassword("test");

postgres.start();

return Map.of("quarkus.datasource.jdbc.url", postgres.getJdbcUrl(), "quarkus.datasource.username", "test",
"quarkus.datasource.password", "test");
}

@Override
public void stop() {

if (postgres != null) {
postgres.stop();
}
}

}
Loading
Loading