question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't seem to use `UniAssertSubscriber` nor JUnit's `@BeforeEach` or `@AfterEach` with `@TestReactiveTransaction`

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
edeandreacommented, Jul 30, 2021

You know me - I write novels

1reaction
geoandcommented, Jul 30, 2021

Thanks for the detailed description. It will be a while before I look into this however, with PTO coming soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to unit test a method returning Uni/Multi of Smallrye ...
I would really recommend using the way of testing from SmallRey. https://smallrye.io/smallrye-mutiny/1.7.0/guides/testing/. You still can get the object out ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found