From f0a68aea475a8c7ebcf124f0872e3d3f698362a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Vav=C5=99=C3=ADk?= Date: Fri, 24 Mar 2023 15:28:04 +0100 Subject: [PATCH] Enable Hibernate Reactive tests for PostgreSQL, MariaDB and MySQL --- pom.xml | 9 +++------ .../reactive/boostrap/web/BookController.java | 16 ++++++++++++---- .../src/main/resources/application.properties | 2 +- .../ts/hibernate/reactive/database/Author.java | 4 +++- .../AbstractDatabaseHibernateReactiveIT.java | 4 ++++ .../MsSQLDatabaseHibernateReactiveIT.java | 4 ++++ .../ts/hibernate/reactive/OracleDatabaseIT.java | 4 ++++ .../src/test/resources/oracle_import.sql | 4 ++-- .../src/test/resources/postgres_import.sql | 4 ++-- 9 files changed, 35 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 0f43ad9e4..c37a4f2f8 100644 --- a/pom.xml +++ b/pom.xml @@ -552,8 +552,7 @@ sql-db/panache-flyway sql-db/reactive-rest-data-panache sql-db/vertx-sql - - + sql-db/hibernate-reactive sql-db/reactive-vanilla sql-db/hibernate-fulltext-search sql-db/narayana-transactions @@ -585,8 +584,7 @@ env-info service-binding/postgresql-crunchy-classic - - + service-binding/postgresql-crunchy-reactive @@ -601,8 +599,7 @@ env-info spring/spring-data spring/spring-web - - + spring/spring-web-reactive spring/spring-properties spring/spring-cloud-config cache/spring diff --git a/spring/spring-web-reactive/src/main/java/io/quarkus/ts/spring/web/reactive/boostrap/web/BookController.java b/spring/spring-web-reactive/src/main/java/io/quarkus/ts/spring/web/reactive/boostrap/web/BookController.java index 1de6ea586..fc0adcc82 100644 --- a/spring/spring-web-reactive/src/main/java/io/quarkus/ts/spring/web/reactive/boostrap/web/BookController.java +++ b/spring/spring-web-reactive/src/main/java/io/quarkus/ts/spring/web/reactive/boostrap/web/BookController.java @@ -23,12 +23,13 @@ import org.springframework.web.bind.annotation.RestController; import io.quarkus.hibernate.reactive.panache.Panache; +import io.quarkus.hibernate.reactive.panache.common.WithSession; +import io.quarkus.hibernate.reactive.panache.common.WithTransaction; import io.quarkus.hibernate.reactive.panache.common.runtime.ReactiveTransactional; import io.quarkus.ts.spring.web.reactive.boostrap.persistence.model.Book; import io.quarkus.ts.spring.web.reactive.boostrap.persistence.repo.BookRepository; import io.quarkus.ts.spring.web.reactive.boostrap.web.exception.BookIdMismatchException; import io.quarkus.ts.spring.web.reactive.boostrap.web.exception.BookNotFoundException; -import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; @RestController @@ -42,6 +43,7 @@ public class BookController { @Autowired BookRepository bookRepository; + @WithSession @GetMapping public Uni> findAll() { return bookRepository.listAll().onItem() @@ -49,12 +51,17 @@ public Uni> findAll() { .ifNoItem().after(Duration.ofSeconds(FAIL_AFTER_SECONDS)).failWith(BookNotFoundException::new); } + @WithSession @GetMapping("/title/{bookTitle}") - public Multi findByTitle(@PathVariable String bookTitle) { + public Uni> findByTitle(@PathVariable String bookTitle) { return bookRepository.findByTitle(bookTitle) - .ifNoItem().after(Duration.ofSeconds(FAIL_AFTER_SECONDS)).failWith(BookNotFoundException::new); + .collect() + .asList() + .ifNoItem() + .after(Duration.ofSeconds(FAIL_AFTER_SECONDS)).failWith(BookNotFoundException::new); } + @WithSession @GetMapping("/{id}") public Uni findOne(@PathVariable long id) { return bookRepository.findById(id) @@ -62,6 +69,7 @@ public Uni findOne(@PathVariable long id) { .ifNoItem().after(Duration.ofSeconds(FAIL_AFTER_SECONDS)).failWith(BookNotFoundException::new); } + @WithSession @PostMapping public Uni create(@RequestBody Book book) { return Panache.withTransaction(() -> bookRepository.persist(book)) @@ -69,7 +77,7 @@ public Uni create(@RequestBody Book book) { } @DeleteMapping("/{id}") - @ReactiveTransactional + @WithTransaction public Uni delete(@PathVariable long id) { return bookRepository.deleteById(id) .map(deleted -> deleted diff --git a/spring/spring-web-reactive/src/main/resources/application.properties b/spring/spring-web-reactive/src/main/resources/application.properties index 84e4b93be..e15d0025c 100644 --- a/spring/spring-web-reactive/src/main/resources/application.properties +++ b/spring/spring-web-reactive/src/main/resources/application.properties @@ -4,7 +4,7 @@ quarkus.datasource.db-kind=mariadb #quarkus.datasource.reactive.url=vertx-reactive:mysql://localhost/quarkus_test #quarkus.datasource.username=admin #quarkus.datasource.password=admin -quarkus.hibernate-orm.dialect=org.hibernate.dialect.MariaDB102Dialect +quarkus.hibernate-orm.dialect=org.hibernate.dialect.MariaDBDialect quarkus.hibernate-orm.database.generation=drop-and-create quarkus.log.console.format=%d{HH:mm:ss.SSS} [%t] %-5p %c{36} - %m%n diff --git a/sql-db/hibernate-reactive/src/main/java/io/quarkus/ts/hibernate/reactive/database/Author.java b/sql-db/hibernate-reactive/src/main/java/io/quarkus/ts/hibernate/reactive/database/Author.java index 69fbaf5fb..ce23d06e4 100644 --- a/sql-db/hibernate-reactive/src/main/java/io/quarkus/ts/hibernate/reactive/database/Author.java +++ b/sql-db/hibernate-reactive/src/main/java/io/quarkus/ts/hibernate/reactive/database/Author.java @@ -10,6 +10,7 @@ import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; @@ -32,7 +33,8 @@ public class Author { @Size(max = MAX_NAME_LENGTH) private String name; - @OneToMany(mappedBy = "author", cascade = PERSIST, fetch = FetchType.EAGER) + @JoinColumn(name = "author") + @OneToMany(cascade = PERSIST, fetch = FetchType.EAGER) private List books = new ArrayList<>(); public Author(String name) { diff --git a/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/AbstractDatabaseHibernateReactiveIT.java b/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/AbstractDatabaseHibernateReactiveIT.java index bf3310805..9e3288cc8 100644 --- a/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/AbstractDatabaseHibernateReactiveIT.java +++ b/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/AbstractDatabaseHibernateReactiveIT.java @@ -16,6 +16,7 @@ import org.junit.jupiter.api.TestMethodOrder; import io.quarkus.test.bootstrap.RestService; +import io.quarkus.test.scenarios.annotations.DisabledOnNative; import io.restassured.http.ContentType; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; @@ -155,6 +156,7 @@ public void searchWithJoin() { assertTrue(result.contains("Thinking fast and slow")); } + @DisabledOnNative(reason = "https://github.com/quarkusio/quarkus/issues/32114") @Test public void searchWithLimit() { String result = getApp().given() @@ -242,6 +244,7 @@ public void useTransaction() { .body("$", hasItem("Ubik")); } + @DisabledOnNative(reason = "https://github.com/quarkusio/quarkus/issues/32114") @Test public void convertValue() { Response response = getApp().given().get("/library/isbn/2"); @@ -260,6 +263,7 @@ public void convertZeroValue() { assertEquals("0", response.body().asString()); } + @DisabledOnNative(reason = "https://github.com/quarkusio/quarkus/issues/32114") @Test public void setConvertedValue() { Response change = getApp().given().put("/library/isbn/1/5170261586"); diff --git a/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/MsSQLDatabaseHibernateReactiveIT.java b/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/MsSQLDatabaseHibernateReactiveIT.java index ebef9f0de..a4321e21d 100644 --- a/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/MsSQLDatabaseHibernateReactiveIT.java +++ b/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/MsSQLDatabaseHibernateReactiveIT.java @@ -1,11 +1,15 @@ package io.quarkus.ts.hibernate.reactive; +import org.junit.jupiter.api.Disabled; + import io.quarkus.test.bootstrap.RestService; import io.quarkus.test.bootstrap.SqlServerService; import io.quarkus.test.scenarios.QuarkusScenario; import io.quarkus.test.services.Container; import io.quarkus.test.services.QuarkusApplication; +// TODO: enable with next Hibernate Reactive bump in Quarkus main +@Disabled("https://github.com/quarkusio/quarkus/issues/32102#issuecomment-1482501348") @QuarkusScenario public class MsSQLDatabaseHibernateReactiveIT extends AbstractDatabaseHibernateReactiveIT { diff --git a/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/OracleDatabaseIT.java b/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/OracleDatabaseIT.java index eebf2300f..46b168dc1 100644 --- a/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/OracleDatabaseIT.java +++ b/sql-db/hibernate-reactive/src/test/java/io/quarkus/ts/hibernate/reactive/OracleDatabaseIT.java @@ -1,11 +1,15 @@ package io.quarkus.ts.hibernate.reactive; +import org.junit.jupiter.api.Disabled; + import io.quarkus.test.bootstrap.OracleService; import io.quarkus.test.bootstrap.RestService; import io.quarkus.test.scenarios.QuarkusScenario; import io.quarkus.test.services.Container; import io.quarkus.test.services.QuarkusApplication; +// TODO: enable with next Hibernate Reactive bump in Quarkus main +@Disabled("https://github.com/quarkusio/quarkus/issues/32102#issuecomment-1482501348") @QuarkusScenario public class OracleDatabaseIT extends AbstractDatabaseHibernateReactiveIT { diff --git a/sql-db/hibernate-reactive/src/test/resources/oracle_import.sql b/sql-db/hibernate-reactive/src/test/resources/oracle_import.sql index fa7356a6b..fcb55ac2e 100644 --- a/sql-db/hibernate-reactive/src/test/resources/oracle_import.sql +++ b/sql-db/hibernate-reactive/src/test/resources/oracle_import.sql @@ -1,10 +1,10 @@ -DROP TABLE authors; +DROP TABLE authors CASCADE CONSTRAINTS; CREATE TABLE AUTHORS(ID NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, NAME VARCHAR(100) NOT NULL); INSERT INTO authors(id,name) VALUES (1, 'Homer'); INSERT INTO authors(id,name) VALUES (2, 'Vern'); INSERT INTO authors(id,name) VALUES (3, 'Dlugi'); INSERT INTO authors(id,name) VALUES (4, 'Kahneman'); -DROP TABLE books; +DROP TABLE books CASCADE CONSTRAINTS; CREATE TABLE books(id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, author INT references authors(id) , title VARCHAR(500) NOT NULL, isbn VARCHAR(50)); INSERT INTO books(author, title) VALUES (3, 'Slovník'); INSERT INTO books(author, title, isbn) VALUES (4, 'Thinking fast and slow', '978-0374275631'); diff --git a/sql-db/hibernate-reactive/src/test/resources/postgres_import.sql b/sql-db/hibernate-reactive/src/test/resources/postgres_import.sql index 5ec95c6c5..a1170c7c7 100644 --- a/sql-db/hibernate-reactive/src/test/resources/postgres_import.sql +++ b/sql-db/hibernate-reactive/src/test/resources/postgres_import.sql @@ -1,10 +1,10 @@ -DROP TABLE IF EXISTS authors; +DROP TABLE IF EXISTS authors CASCADE; CREATE TABLE authors(id SERIAL PRIMARY KEY, name TEXT NOT NULL); INSERT INTO authors(id,name) VALUES (1, 'Homer'); INSERT INTO authors(id,name) VALUES (2, 'Vern'); INSERT INTO authors(id,name) VALUES (3, 'Dlugi'); INSERT INTO authors(id,name) VALUES (4, 'Kahneman'); -DROP TABLE IF EXISTS books; +DROP TABLE IF EXISTS books CASCADE; CREATE TABLE books(id SERIAL PRIMARY KEY, author int references authors(id) , title TEXT NOT NULL, isbn TEXT NULL); INSERT INTO books(author, title) VALUES (3, 'Slovník'); INSERT INTO books(author, title, isbn) VALUES (4, 'Thinking fast and slow', '978-0374275631');