Skip to content

Commit b35354f

Browse files
committed
use a random PostgreSQL Dev Service port
1 parent 035d5bf commit b35354f

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
quarkus:
2-
datasource:
3-
devservices:
4-
port: 5433
52
operator-sdk:
63
activate-leader-election-for-profiles:
74
- test

src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/Given.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.eclipse.microprofile.config.inject.ConfigProperty;
1010
import org.jspecify.annotations.NullMarked;
1111

12+
import java.net.URI;
13+
1214
@NullMarked
1315
@ApplicationScoped
1416
@RequiredArgsConstructor
@@ -21,12 +23,12 @@ public class Given {
2123
@ConfigProperty(name = "quarkus.datasource.devservices.password")
2224
String password;
2325

24-
@ConfigProperty(name = "quarkus.datasource.devservices.port")
25-
Integer port;
26+
@ConfigProperty(name = "quarkus.datasource.jdbc.url")
27+
String jdbcUrl;
2628

2729
DBConnectionDetails dbConnectionDetails() {
2830
return new DBConnectionDetails(
29-
port,
31+
parsePortFromJdbcUrl(jdbcUrl),
3032
username,
3133
password
3234
);
@@ -85,4 +87,12 @@ public record DBConnectionDetails(
8587
String password
8688
) {
8789
}
90+
91+
private int parsePortFromJdbcUrl(String url) {
92+
// Typical format: jdbc:postgresql://localhost:5432/db
93+
// We strip "jdbc:" so URI.create can handle the "postgresql://..." part
94+
return URI.create(
95+
url.replace("jdbc:", "")
96+
).getPort();
97+
}
8898
}

0 commit comments

Comments
 (0)