From 16fe4a2295e9c52681a34be34bc2e6b52e2e0ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Vav=C5=99=C3=ADk?= <43821672+michalvavrik@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:13:39 +0200 Subject: [PATCH] Fix DevModeMultipleReactiveSqlClientsIT on Aarch64 (#2041) --- .../db/clients/HardCoverBookResource.java | 22 +++------ .../db/clients/ReactiveClientConverter.java | 49 +++++++++++++++++++ .../db/clients/model/HardCoverBook.java | 8 +-- .../src/main/resources/application.properties | 1 + .../main/resources/mariadb-init-script.sql | 5 ++ .../DevModeMultipleReactiveSqlClientsIT.java | 15 +++--- ...activeMssqlDevServiceUserExperienceIT.java | 1 + ...activeMysqlDevServiceUserExperienceIT.java | 1 + ...ePostgresqlDevServiceUserExperienceIT.java | 1 + 9 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/ReactiveClientConverter.java create mode 100644 sql-db/reactive-vanilla/src/main/resources/mariadb-init-script.sql diff --git a/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/HardCoverBookResource.java b/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/HardCoverBookResource.java index 6d2c60fee..a92d89e60 100644 --- a/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/HardCoverBookResource.java +++ b/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/HardCoverBookResource.java @@ -2,8 +2,6 @@ import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; -import jakarta.inject.Inject; -import jakarta.inject.Named; import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; @@ -15,33 +13,29 @@ import io.quarkus.ts.reactive.db.clients.model.Book; import io.quarkus.ts.reactive.db.clients.model.HardCoverBook; import io.smallrye.mutiny.Uni; -import io.vertx.mutiny.mssqlclient.MSSQLPool; +import io.vertx.mutiny.sqlclient.Pool; -@Path("/book/mssql") +@Path("/book/{reactive-client}") public class HardCoverBookResource extends CommonResource { - @Inject - @Named("mssql") - MSSQLPool mssql; - @GET @Produces(APPLICATION_JSON) - public Uni getAll() { - return HardCoverBook.findAll(mssql) + public Uni getAll(@PathParam("reactive-client") Pool pool) { + return HardCoverBook.findAll(pool) .onItem().transform(books -> Response.ok(Book.toJsonStringify(books)).build()); } @GET @Path("/{id}") @Produces(APPLICATION_JSON) - public Uni findById(@PathParam("id") Long id) { - return HardCoverBook.findById(mssql, id).onItem().transform( + public Uni findById(@PathParam("id") Long id, @PathParam("reactive-client") Pool pool) { + return HardCoverBook.findById(pool, id).onItem().transform( hardCoverBook -> Response.ok(hardCoverBook.toJsonStringify()).build()); } @POST - public Uni create(HardCoverBook hardCoverBook, UriInfo uriInfo) { - return hardCoverBook.save(mssql) + public Uni create(HardCoverBook hardCoverBook, UriInfo uriInfo, @PathParam("reactive-client") Pool pool) { + return hardCoverBook.save(pool) .onItem().transform(id -> fromId(id, uriInfo)) .onItem().transform(uri -> Response.created(uri).build()); } diff --git a/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/ReactiveClientConverter.java b/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/ReactiveClientConverter.java new file mode 100644 index 000000000..1276d36e9 --- /dev/null +++ b/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/ReactiveClientConverter.java @@ -0,0 +1,49 @@ +package io.quarkus.ts.reactive.db.clients; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.ws.rs.ext.ParamConverter; +import jakarta.ws.rs.ext.ParamConverterProvider; +import jakarta.ws.rs.ext.Provider; + +import io.quarkus.reactive.datasource.ReactiveDataSource; +import io.vertx.mutiny.mssqlclient.MSSQLPool; +import io.vertx.mutiny.sqlclient.Pool; + +@Provider +public class ReactiveClientConverter implements ParamConverterProvider, ParamConverter { + + @Inject + @Named("mssql") + MSSQLPool mssql; + + @Inject + @ReactiveDataSource("mariadb") + Pool mariadb; + + @SuppressWarnings("unchecked") + @Override + public ParamConverter getConverter(Class aClass, Type type, Annotation[] annotations) { + if (Pool.class == aClass) { + return (ParamConverter) this; + } + return null; + } + + @Override + public Pool fromString(String reactiveClient) { + return switch (reactiveClient) { + case "mariadb" -> mariadb; + case "mssql" -> mssql; + default -> throw new IllegalStateException("Unexpected reactive client: " + reactiveClient); + }; + } + + @Override + public String toString(Pool pool) { + throw new UnsupportedOperationException("We only convert path param to a Pool"); + } +} diff --git a/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/model/HardCoverBook.java b/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/model/HardCoverBook.java index 50b6e8103..02abf957d 100644 --- a/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/model/HardCoverBook.java +++ b/sql-db/reactive-vanilla/src/main/java/io/quarkus/ts/reactive/db/clients/model/HardCoverBook.java @@ -4,7 +4,7 @@ import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; -import io.vertx.mutiny.mssqlclient.MSSQLPool; +import io.vertx.mutiny.sqlclient.Pool; import io.vertx.mutiny.sqlclient.Row; import io.vertx.mutiny.sqlclient.RowSet; import io.vertx.sqlclient.PropertyKind; @@ -29,12 +29,12 @@ private static Multi fromSet(RowSet rows) { return fromSet(rows, HardCoverBook::new); } - public static Uni> findAll(MSSQLPool client) { + public static Uni> findAll(Pool client) { return toList(client.query("SELECT * FROM " + TABLE_NAME).execute().onItem() .transformToMulti(HardCoverBook::fromSet)); } - public Uni save(MSSQLPool client) { + public Uni save(Pool client) { return client .preparedQuery( "INSERT INTO " + TABLE_NAME + " (" + TITLE + ", " + AUTHOR + ") VALUES ('" + title + "', '" + author @@ -44,7 +44,7 @@ public Uni save(MSSQLPool client) { .onItem().transform(id -> (Long) id.getDelegate().property(LAST_INSERTED_ID)); } - public static Uni findById(MSSQLPool client, Long id) { + public static Uni findById(Pool client, Long id) { return client.preparedQuery("SELECT id, title, author FROM " + TABLE_NAME + " WHERE id = " + id).execute() .onItem().transform(RowSet::iterator) .onItem().transform(iterator -> iterator.hasNext() ? new HardCoverBook(iterator.next()) : null); diff --git a/sql-db/reactive-vanilla/src/main/resources/application.properties b/sql-db/reactive-vanilla/src/main/resources/application.properties index b23cc4265..383650003 100644 --- a/sql-db/reactive-vanilla/src/main/resources/application.properties +++ b/sql-db/reactive-vanilla/src/main/resources/application.properties @@ -1,3 +1,4 @@ quarkus.datasource.db-kind=postgresql quarkus.datasource.mysql.db-kind=mysql +quarkus.datasource.mariadb.db-kind=mariadb quarkus.datasource.mssql.db-kind=mssql diff --git a/sql-db/reactive-vanilla/src/main/resources/mariadb-init-script.sql b/sql-db/reactive-vanilla/src/main/resources/mariadb-init-script.sql new file mode 100644 index 000000000..0d63fb039 --- /dev/null +++ b/sql-db/reactive-vanilla/src/main/resources/mariadb-init-script.sql @@ -0,0 +1,5 @@ +DROP TABLE IF EXISTS hardCoverBook; +CREATE TABLE hardCoverBook (id SERIAL PRIMARY KEY, title TEXT NOT NULL, author TEXT NOT NULL); +INSERT INTO hardCoverBook (title, author) VALUES ('Foundation', 'Isaac Asimov'); +INSERT INTO hardCoverBook (title, author) VALUES ('2001: A Space Odyssey', 'Arthur C. Clarke'); +INSERT INTO hardCoverBook (title, author) VALUES ('Stranger in a Strange Land', 'Robert A. Heinlein'); diff --git a/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeMultipleReactiveSqlClientsIT.java b/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeMultipleReactiveSqlClientsIT.java index 208ab5714..c4cb08f1c 100644 --- a/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeMultipleReactiveSqlClientsIT.java +++ b/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeMultipleReactiveSqlClientsIT.java @@ -31,8 +31,9 @@ public class DevModeMultipleReactiveSqlClientsIT { @DevModeQuarkusApplication static RestService app = new RestService() .withProperty("quarkus.datasource.devservices.init-script-path", "postgresql-init-script.sql") + .withProperty("quarkus.datasource.mariadb.devservices.init-script-path", "mariadb-init-script.sql") .withProperty("quarkus.datasource.mysql.devservices.init-script-path", "mysql-init-script.sql") - .withProperty("quarkus.datasource.mssql.devservices.init-script-path", "mssql-init-script.sql"); + .withProperty("quarkus.datasource.mssql.devservices.enabled", "false"); @Test public void verifyReactivePostgresqlRetrieveEntities() { @@ -81,26 +82,26 @@ public void verifyReactiveMysqlCreateEntity() { } @Test - public void verifyReactiveMssqlRetrieveEntities() { + public void verifyReactiveMariaDbRetrieveEntities() { given() - .when().get("/book/mssql") + .when().get("/book/mariadb") .then() .statusCode(HttpStatus.SC_OK) .body("$.size()", greaterThan(2)); } @Test - public void verifyReactiveMssqlRetrieveById() { + public void verifyReactiveMariaDbRetrieveById() { given() - .when().get("/book/mssql/1") + .when().get("/book/mariadb/1") .then() .statusCode(HttpStatus.SC_OK); } @Test - public void verifyReactiveMssqlCreateEntity() { + public void verifyReactiveMariaDbCreateEntity() { HardCoverBook hardCoverBook = new HardCoverBook("Sin noticias de Gurb", "Eduardo Mendoza"); - createRecord("/book/mssql", hardCoverBook); + createRecord("/book/mariadb", hardCoverBook); } private static void createRecord(String path, Book book) { diff --git a/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactiveMssqlDevServiceUserExperienceIT.java b/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactiveMssqlDevServiceUserExperienceIT.java index ca008d59c..490679644 100644 --- a/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactiveMssqlDevServiceUserExperienceIT.java +++ b/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactiveMssqlDevServiceUserExperienceIT.java @@ -28,6 +28,7 @@ public class DevModeReactiveMssqlDevServiceUserExperienceIT { static RestService app = new RestService() .withProperty("quarkus.datasource.mssql.devservices.image-name", "${mssql.image}") .withProperty("quarkus.datasource.mysql.devservices.enabled", "false") + .withProperty("quarkus.datasource.mariadb.devservices.enabled", "false") .withProperty("quarkus.datasource.devservices.enabled", "false") .onPreStart(s -> DockerUtils.removeImage(MSSQL_NAME, MSSQL_VERSION)); diff --git a/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactiveMysqlDevServiceUserExperienceIT.java b/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactiveMysqlDevServiceUserExperienceIT.java index e80c15b85..30e97ec95 100644 --- a/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactiveMysqlDevServiceUserExperienceIT.java +++ b/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactiveMysqlDevServiceUserExperienceIT.java @@ -24,6 +24,7 @@ public class DevModeReactiveMysqlDevServiceUserExperienceIT { @DevModeQuarkusApplication static RestService app = new RestService() .withProperty("quarkus.datasource.mysql.devservices.image-name", "${mysql.upstream.80.image}") + .withProperty("quarkus.datasource.mariadb.devservices.enabled", "false") .withProperty("quarkus.datasource.mssql.devservices.enabled", "false") .withProperty("quarkus.datasource.devservices.enabled", "false") .onPreStart(s -> DockerUtils.removeImage(MYSQL_NAME, MYSQL_VERSION)); diff --git a/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactivePostgresqlDevServiceUserExperienceIT.java b/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactivePostgresqlDevServiceUserExperienceIT.java index 8bfa46ec6..66c8178cc 100644 --- a/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactivePostgresqlDevServiceUserExperienceIT.java +++ b/sql-db/reactive-vanilla/src/test/java/io/quarkus/ts/reactive/db/clients/DevModeReactivePostgresqlDevServiceUserExperienceIT.java @@ -28,6 +28,7 @@ public class DevModeReactivePostgresqlDevServiceUserExperienceIT { static RestService app = new RestService() .withProperty("quarkus.datasource.devservices.image-name", "${postgresql.latest.image}-bullseye") .withProperty("quarkus.datasource.mysql.devservices.enabled", "false") + .withProperty("quarkus.datasource.mariadb.devservices.enabled", "false") .withProperty("quarkus.datasource.mssql.devservices.enabled", "false") .onPreStart(s -> DockerUtils.removeImage(POSTGRES_NAME, POSTGRESQL_VERSION));