Can't seem to use `UniAssertSubscriber` nor JUnit's `@BeforeEach` or `@AfterEach` with `@TestReactiveTransaction`
See original GitHub issueDescribe the bug
This is a spawn-off from #19102 - there’s a lengthy comment at the bottom which I’ll try to summarize here.
If I have an application using Panache reactive and I try to use the new @TestReactiveTransaction
annotation rather than what I’m doing now:
Panache.getSession().flatMap(session -> session.withTransaction(tx -> {
tx.markForRollback();
return some Uni;
}));
It seems I’m no longer able to use things like UniAssertSubscriber
or run any kinds of tests that use any kind of await
mechanism.
Some examples of things I can no longer do:
@Test
@TestReactiveTransaction
public void findByName() {
Fruit fruit = fruitRepository
.persist(new Fruit(null, "Grapefruit", "Summer fruit"))
.replaceWith(this.fruitRepository.findByName("Grapefruit"))
)
.await()
.atMost(Duration.ofSeconds(10));
assertThat(fruit)
.isNotNull()
.extracting(Fruit::getName, Fruit::getDescription)
.containsExactly("Grapefruit", "Summer fruit");
assertThat(fruit.getId())
.isNotNull()
.isGreaterThan(2L);
}
@Test
@TestReactiveTransaction
public void findByName() {
Fruit fruit = this.fruitRepository
.persist(new Fruit(null, "Grapefruit", "Summer fruit"))
.replaceWith(this.fruitRepository.findByName("Grapefruit"))
.subscribe().withSubscriber(UniAssertSubscriber.create())
.awaitSubscription(Duration.ofSeconds(5))
.awaitItem(Duration.ofSeconds(10))
.getItem();
assertThat(fruit)
.isNotNull()
.extracting(Fruit::getName, Fruit::getDescription)
.containsExactly("Grapefruit", "Summer fruit");
assertThat(fruit.getId())
.isNotNull()
.isGreaterThan(2L);
}
What seems to work is
@Test
@TestReactiveTransaction
public void findByName(UniAsserter asserter) {
asserter.assertThat(() -> this.fruitRepository
.persist(new Fruit(null, "Grapefruit", "Summer fruit"))
.replaceWith(this.fruitRepository.findByName("Grapefruit")),
fruit -> {
assertThat(fruit)
.isNotNull()
.extracting(Fruit::getName, Fruit::getDescription)
.containsExactly("Grapefruit", "Summer fruit");
assertThat(fruit.getId())
.isNotNull()
.isGreaterThan(2L);
}
);
}
But then this means I have to bring in a new quarkus-junit5-vertx
dependency and now use some assertion framework (UniAsserter
?) in all of my tests? This just doesn’t seem like a good trade-off to me where I have to completely re-write all my tests just because I want to take advantage of an annotation? The UniAsserter
thing doesn’t work in @BeforeEach
or @AfterEach
methods either.
What if I could tag my test class/methods with @Blocking
? That doesn’t seem to do anything now, but could it?
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
No response
Output of uname -a
or ver
No response
Output of java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
No response
Build tool (ie. output of mvnw --version
or gradlew --version
)
No response
Additional information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (10 by maintainers)
You know me - I write novels
Thanks for the detailed description. It will be a while before I look into this however, with PTO coming soon