Skip to content

Commit

Permalink
Merge pull request #1126 from michalvavrik/feature/enable-hibernate-r…
Browse files Browse the repository at this point in the history
…eactive-modules

Enable Hibernate Reactive tests for PostgreSQL, MariaDB and MySQL
  • Loading branch information
michalvavrik authored Mar 25, 2023
2 parents 3451d3d + f0a68ae commit 8f0e559
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 16 deletions.
9 changes: 3 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,7 @@
<module>sql-db/panache-flyway</module>
<module>sql-db/reactive-rest-data-panache</module>
<module>sql-db/vertx-sql</module>
<!-- TODO: enable when https://github.com/quarkusio/quarkus/pull/31217 us reverted -->
<!-- <module>sql-db/hibernate-reactive</module> -->
<module>sql-db/hibernate-reactive</module>
<module>sql-db/reactive-vanilla</module>
<module>sql-db/hibernate-fulltext-search</module>
<module>sql-db/narayana-transactions</module>
Expand Down Expand Up @@ -585,8 +584,7 @@
<modules>
<module>env-info</module>
<module>service-binding/postgresql-crunchy-classic</module>
<!-- TODO: enable when https://github.com/quarkusio/quarkus/pull/31217 us reverted -->
<!-- <module>service-binding/postgresql-crunchy-reactive</module> -->
<module>service-binding/postgresql-crunchy-reactive</module>
</modules>
</profile>
<profile>
Expand All @@ -601,8 +599,7 @@
<module>env-info</module>
<module>spring/spring-data</module>
<module>spring/spring-web</module>
<!-- TODO: enable when https://github.com/quarkusio/quarkus/pull/31217 us reverted -->
<!-- <module>spring/spring-web-reactive</module> -->
<module>spring/spring-web-reactive</module>
<module>spring/spring-properties</module>
<module>spring/spring-cloud-config</module>
<module>cache/spring</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,34 +43,41 @@ public class BookController {
@Autowired
BookRepository bookRepository;

@WithSession
@GetMapping
public Uni<List<Book>> findAll() {
return bookRepository.listAll().onItem()
.ifNull().continueWith(Collections.emptyList())
.ifNoItem().after(Duration.ofSeconds(FAIL_AFTER_SECONDS)).failWith(BookNotFoundException::new);
}

@WithSession
@GetMapping("/title/{bookTitle}")
public Multi<Book> findByTitle(@PathVariable String bookTitle) {
public Uni<List<Book>> 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<Book> findOne(@PathVariable long id) {
return bookRepository.findById(id)
.onItem().ifNull().failWith(BookNotFoundException::new)
.ifNoItem().after(Duration.ofSeconds(FAIL_AFTER_SECONDS)).failWith(BookNotFoundException::new);
}

@WithSession
@PostMapping
public Uni<Response> create(@RequestBody Book book) {
return Panache.withTransaction(() -> bookRepository.persist(book))
.replaceWith(Response.ok((book)).status(CREATED)::build);
}

@DeleteMapping("/{id}")
@ReactiveTransactional
@WithTransaction
public Uni<Response> delete(@PathVariable long id) {
return bookRepository.deleteById(id)
.map(deleted -> deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Book> books = new ArrayList<>();

public Author(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

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

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

0 comments on commit 8f0e559

Please sign in to comment.