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

Dev services: MSSQL reactive client does not support JDBC url format #25487

Merged
merged 3 commits into from
May 24, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ public static DevServicesDatasourceConfigurationHandlerBuildItem jdbc(String dbK
@Override
public Map<String, String> apply(String dsName,
DevServicesDatasourceProvider.RunningDevServicesDatasource runningDevDb) {
String jdbcUrl = runningDevDb.getJdbcUrl();
if (dsName == null) {
return Collections.singletonMap("quarkus.datasource.jdbc.url", runningDevDb.getUrl());
return Collections.singletonMap("quarkus.datasource.jdbc.url", jdbcUrl);
} else {
// we use quoted and unquoted versions because depending on whether a user configured other JDBC properties
// one of the URLs may be ignored
// see https://github.com/quarkusio/quarkus/issues/21387
return Map.of(
datasourceURLPropName(dsName), runningDevDb.getUrl(),
datasourceURLPropName("\"" + dsName + "\""), runningDevDb.getUrl());
datasourceURLPropName(dsName), jdbcUrl,
datasourceURLPropName("\"" + dsName + "\""), jdbcUrl);
}
}

Expand All @@ -90,12 +91,16 @@ public static DevServicesDatasourceConfigurationHandlerBuildItem reactive(String
@Override
public Map<String, String> apply(String dsName,
DevServicesDatasourceProvider.RunningDevServicesDatasource runningDevDb) {
String reactiveUrl = runningDevDb.getReactiveUrl();
if (dsName == null) {
return Collections.singletonMap("quarkus.datasource.reactive.url",
runningDevDb.getUrl().replaceFirst("jdbc:", "vertx-reactive:"));
return Collections.singletonMap("quarkus.datasource.reactive.url", reactiveUrl);
} else {
return Collections.singletonMap("quarkus.datasource.\"" + dsName + "\".reactive.url",
runningDevDb.getUrl().replaceFirst("jdbc:", "vertx-reactive:"));
// we use quoted and unquoted versions because depending on whether a user configured other JDBC properties
// one of the URLs may be ignored
// see https://github.com/quarkusio/quarkus/issues/21387
return Map.of(
datasourceReactiveURLPropName(dsName, false), reactiveUrl,
datasourceReactiveURLPropName(dsName, true), reactiveUrl);
}
}
}, new Predicate<String>() {
Expand All @@ -104,10 +109,24 @@ public boolean test(String dsName) {
if (dsName == null) {
return ConfigUtils.isPropertyPresent("quarkus.datasource.reactive.url");
} else {
return ConfigUtils.isPropertyPresent("quarkus.datasource.\"" + dsName + "\".reactive.url") ||
ConfigUtils.isPropertyPresent("quarkus.datasource." + dsName + ".reactive.url");
return ConfigUtils.isPropertyPresent(datasourceReactiveURLPropName(dsName, false)) ||
ConfigUtils.isPropertyPresent(datasourceReactiveURLPropName(dsName, true));
}
}
});
}

private static String datasourceReactiveURLPropName(String dsName, boolean quotedName) {
StringBuilder key = new StringBuilder("quarkus.datasource");
key.append('.');
if (quotedName) {
key.append('"');
}
key.append(dsName);
if (quotedName) {
key.append('"');
}
key.append(".reactive.url");
return key.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ default boolean isDockerRequired() {
class RunningDevServicesDatasource {

private final String id;
private final String url;
private final String jdbcUrl;
private final String reactiveUrl;
private final String username;
private final String password;
private final Closeable closeTask;

public RunningDevServicesDatasource(String id, String url, String username, String password, Closeable closeTask) {
public RunningDevServicesDatasource(String id, String jdbcUrl, String reactiveUrl, String username, String password,
Closeable closeTask) {
this.id = id;
this.url = url;
this.jdbcUrl = jdbcUrl;
this.reactiveUrl = reactiveUrl;
this.username = username;
this.password = password;
this.closeTask = closeTask;
Expand All @@ -41,8 +44,12 @@ public String getId() {
return id;
}

public String getUrl() {
return url;
public String getJdbcUrl() {
return jdbcUrl;
}

public String getReactiveUrl() {
return reactiveUrl;
}

public Closeable getCloseTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt

return new RunningDevServicesDatasource(container.getContainerId(),
container.getEffectiveJdbcUrl(),
container.getReactiveUrl(),
container.getUsername(),
container.getPassword(),
new ContainerShutdownCloseable(container, "IBM Db2"));
Expand Down Expand Up @@ -97,5 +98,9 @@ public String getEffectiveJdbcUrl() {
return super.getJdbcUrl();
}
}

public String getReactiveUrl() {
return getEffectiveJdbcUrl().replaceFirst("jdbc:", "vertx-reactive:");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
+ additionalArgs.toString(),
null,
null,
null,
new Closeable() {
@Override
public void close() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
+ ";DB_CLOSE_DELAY=-1" + additionalArgs.toString();
return new RunningDevServicesDatasource(null,
connectionUrl,
null,
"sa",
"sa",
new Closeable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt

return new RunningDevServicesDatasource(container.getContainerId(),
container.getEffectiveJdbcUrl(),
container.getReactiveUrl(),
container.getUsername(),
container.getPassword(),
new ContainerShutdownCloseable(container, "MariaDB"));
Expand Down Expand Up @@ -101,5 +102,9 @@ public String getEffectiveJdbcUrl() {
return super.getJdbcUrl();
}
}

public String getReactiveUrl() {
return getEffectiveJdbcUrl().replaceFirst("jdbc:", "vertx-reactive:");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt

return new RunningDevServicesDatasource(container.getContainerId(),
container.getEffectiveJdbcUrl(),
container.getReactiveUrl(),
container.getUsername(),
container.getPassword(),
new ContainerShutdownCloseable(container, "Microsoft SQL Server"));
Expand Down Expand Up @@ -94,5 +95,15 @@ public String getEffectiveJdbcUrl() {
return super.getJdbcUrl();
}
}

public String getReactiveUrl() {
StringBuilder url = new StringBuilder("vertx-reactive:sqlserver://");
if (useSharedNetwork) {
url.append(hostName).append(":").append(MS_SQL_SERVER_PORT);
} else {
url.append(this.getHost()).append(":").append(this.getMappedPort(MS_SQL_SERVER_PORT));
}
return url.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt

return new RunningDevServicesDatasource(container.getContainerId(),
container.getEffectiveJdbcUrl(),
container.getReactiveUrl(),
container.getUsername(),
container.getPassword(),
new ContainerShutdownCloseable(container, "MySQL"));
Expand Down Expand Up @@ -104,5 +105,9 @@ public String getEffectiveJdbcUrl() {
return super.getJdbcUrl();
}
}

public String getReactiveUrl() {
return getEffectiveJdbcUrl().replaceFirst("jdbc:", "vertx-reactive:");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt

return new RunningDevServicesDatasource(container.getContainerId(),
container.getEffectiveJdbcUrl(),
container.getReactiveUrl(),
container.getUsername(),
container.getPassword(),
new ContainerShutdownCloseable(container, "Oracle"));
Expand Down Expand Up @@ -110,5 +111,9 @@ public String getEffectiveJdbcUrl() {
return super.getJdbcUrl();
}
}

public String getReactiveUrl() {
return getEffectiveJdbcUrl().replaceFirst("jdbc:", "vertx-reactive:");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt

return new RunningDevServicesDatasource(container.getContainerId(),
container.getEffectiveJdbcUrl(),
container.getReactiveUrl(),
container.getUsername(),
container.getPassword(),
new ContainerShutdownCloseable(container, "PostgreSQL"));
Expand Down Expand Up @@ -107,5 +108,9 @@ public String getEffectiveJdbcUrl() {
return super.getJdbcUrl();
}
}

public String getReactiveUrl() {
return getEffectiveJdbcUrl().replaceFirst("jdbc:", "vertx-reactive:");
}
}
}
5 changes: 5 additions & 0 deletions extensions/reactive-mssql-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<artifactId>quarkus-smallrye-health-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.quarkus.reactive.mssql.client;

import static org.assertj.core.api.Assertions.assertThat;

import java.time.Duration;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import javax.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.vertx.mutiny.mssqlclient.MSSQLPool;

public class DevServicesMsSQLDatasourceTestCase {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addAsResource("container-license-acceptance.txt"))
// Expect no warnings from reactive
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue()
&& record.getMessage().toLowerCase(Locale.ENGLISH).contains("reactive"))
.assertLogRecords(records -> assertThat(records)
// This is just to get meaningful error messages, as LogRecord doesn't have a toString()
.extracting(LogRecord::getMessage)
.isEmpty());

@Inject
MSSQLPool pool;

@Test
public void testDatasource() throws Exception {
pool.withConnection(conn -> conn.query("SELECT 1").execute().replaceWithVoid())
.await().atMost(Duration.ofMinutes(2));
}
}
5 changes: 5 additions & 0 deletions extensions/reactive-mysql-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
<artifactId>quarkus-smallrye-health-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.reactive.mysql.client;

import static org.assertj.core.api.Assertions.assertThat;

import java.time.Duration;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import javax.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.vertx.mutiny.mysqlclient.MySQLPool;

public class DevServicesMySQLDatasourceTestCase {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withEmptyApplication()
// Expect no warnings from reactive
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue()
&& record.getMessage().toLowerCase(Locale.ENGLISH).contains("reactive"))
.assertLogRecords(records -> assertThat(records)
// This is just to get meaningful error messages, as LogRecord doesn't have a toString()
.extracting(LogRecord::getMessage)
.isEmpty());

@Inject
MySQLPool pool;

@Test
public void testDatasource() throws Exception {
pool.withConnection(conn -> conn.query("SELECT 1").execute().replaceWithVoid())
.await().atMost(Duration.ofMinutes(2));
}
}
5 changes: 5 additions & 0 deletions extensions/reactive-oracle-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<artifactId>quarkus-smallrye-health-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.reactive.oracle.client;

import static org.assertj.core.api.Assertions.assertThat;

import java.time.Duration;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import javax.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.vertx.mutiny.oracleclient.OraclePool;

public class DevServicesOracleDatasourceTestCase {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withEmptyApplication()
// Expect no warnings from reactive
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue()
&& record.getMessage().toLowerCase(Locale.ENGLISH).contains("reactive"))
.assertLogRecords(records -> assertThat(records)
// This is just to get meaningful error messages, as LogRecord doesn't have a toString()
.extracting(LogRecord::getMessage)
.isEmpty());

@Inject
OraclePool pool;

@Test
public void testDatasource() throws Exception {
pool.withConnection(conn -> conn.query("SELECT 1 FROM DUAL").execute().replaceWithVoid())
.await().atMost(Duration.ofMinutes(2));
}
}
Loading