Skip to content

Commit

Permalink
Fix DevModeMultipleReactiveSqlClientsIT on Aarch64 (#2041)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik authored and fedinskiy committed Sep 25, 2024
1 parent 71d2f7f commit 16fe4a2
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Response> getAll() {
return HardCoverBook.findAll(mssql)
public Uni<Response> 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<Response> findById(@PathParam("id") Long id) {
return HardCoverBook.findById(mssql, id).onItem().transform(
public Uni<Response> 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<Response> create(HardCoverBook hardCoverBook, UriInfo uriInfo) {
return hardCoverBook.save(mssql)
public Uni<Response> 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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Pool> {

@Inject
@Named("mssql")
MSSQLPool mssql;

@Inject
@ReactiveDataSource("mariadb")
Pool mariadb;

@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(Class<T> aClass, Type type, Annotation[] annotations) {
if (Pool.class == aClass) {
return (ParamConverter<T>) 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,12 +29,12 @@ private static Multi<HardCoverBook> fromSet(RowSet<Row> rows) {
return fromSet(rows, HardCoverBook::new);
}

public static Uni<List<HardCoverBook>> findAll(MSSQLPool client) {
public static Uni<List<HardCoverBook>> findAll(Pool client) {
return toList(client.query("SELECT * FROM " + TABLE_NAME).execute().onItem()
.transformToMulti(HardCoverBook::fromSet));
}

public Uni<Long> save(MSSQLPool client) {
public Uni<Long> save(Pool client) {
return client
.preparedQuery(
"INSERT INTO " + TABLE_NAME + " (" + TITLE + ", " + AUTHOR + ") VALUES ('" + title + "', '" + author
Expand All @@ -44,7 +44,7 @@ public Uni<Long> save(MSSQLPool client) {
.onItem().transform(id -> (Long) id.getDelegate().property(LAST_INSERTED_ID));
}

public static Uni<HardCoverBook> findById(MSSQLPool client, Long id) {
public static Uni<HardCoverBook> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 16fe4a2

Please sign in to comment.