liveBook · Manning

@RunOnVertxContext

As explained in Quarkus in Action

@RunOnVertxContext is an annotation that runs a test method on a Vert.x event-loop context.

Marks a test method for execution on a Vert.x event-loop thread, where reactive Hibernate operations can run. The main test thread is unsuitable for this code, and the annotation enables injection of a TransactionalUniAsserter for transactional Uni assertions. section 7.7.2

Reactive persistence test

Annotate the test and accept a TransactionalUniAsserter parameter: @Test @RunOnVertxContext public void testCreateReservation(TransactionalUniAsserter asserter). Use the asserter to persist a reservation, assert its generated identifier, count records, and retrieve the saved entity. section 7.7.2

Listing 7.43 Reactive invocations in the ReservationPersistenceTest
@Test
@RunOnVertxContext
public void testCreateReservation(TransactionalUniAsserter asserter) {
    Reservation reservation = new Reservation();
    reservation.startDay = LocalDate.now().plus(5, ChronoUnit.DAYS);
    reservation.endDay = LocalDate.now().plus(12, ChronoUnit.DAYS);
    reservation.carId = 384L;

    asserter.<Reservation>assertThat(() -> reservation.persist(),
        r -> {
            Assertions.assertNotNull(r.id);
            asserter.putData("reservation.id", r.id);
        });

    asserter.assertEquals(() -> Reservation.count(), 1L);
    asserter.assertThat(() -> Reservation.<Reservation>findById(
            asserter.getData("reservation.id")),
        persistedReservation -> {
            Assertions.assertNotNull(persistedReservation);
            Assertions.assertEquals(reservation.carId,
                persistedReservation.carId);
        });
}

Shows the complete reactive test pattern, including asynchronous assertions and data passed between assertion operations. section 7.7.2

How Quarkus in Action covers it

How deep it goes
Explains execution-thread requirements and demonstrates transactional Uni assertions, but defers broader asserter customization.
Examples
Demonstrates creating, counting, retrieving, and asserting a reservation asynchronously.
What it assumes
Assumes reactive persistence and Uni familiarity while supplying the event-loop and transactional assertion setup.
What you can do after
Apply it via Quarkus Hibernate Reactive testing to execute transactional asynchronous persistence tests.
How it connects
Connects Vert.x event loops with Hibernate Reactive, Uni, and TransactionalUniAsserter.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.