You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Regarding below example. I have a transactional method that returns a reactive value. I am doing some conditional logic outside the transactional method; as a result, it never gets subscribed because upstream fails. But @transactional interceptors someshow subscribe to the result of transactionalResource() method. Without @transactional annotation result of transactionalResource() is never subscribed.
Is there a way I can make this behavior work as I intend to. I checked context propagation but I am afraid I didn't understand how it can help me with this scenario.
Note: Actually in my real application example "This should not invoke!!" invoked after the exception was logged. Maybe something with the test class. But still, no way to prevent it.
import io.quarkus.logging.Log;
import io.quarkus.test.junit.QuarkusTest;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.unchecked.Unchecked;
import org.junit.jupiter.api.Test;
import javax.transaction.Transactional;
@QuarkusTest
public class ReactiveTransactionTest {
@Transactional
public Uni<Void> transactionalResource(){
return Uni.createFrom().item("second")
.invoke(s -> Log.info("This should not invoke!!"))
.replaceWithVoid();
}
@Test
public void test(){
Uni<Void> second = transactionalResource();
Uni.createFrom().item("first")
.invoke(
Unchecked.consumer(s-> {
if(s.equals("first")) throw new RuntimeException("Exception");
})
)
.chain(() -> second)
.subscribe()
.with(s -> Log.info("success all")
,throwable -> Log.infov("Error occured: {0}", throwable));
}
}
Console output
2022-12-13 03:57:40,700 INFO [io.apa.use.ReactiveTransactionTest] (main) This should not invoke!!
2022-12-13 03:57:40,706 INFO [io.apa.use.ReactiveTransactionTest] (main) Error occured: java.lang.RuntimeException: Exception
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Regarding below example. I have a transactional method that returns a reactive value. I am doing some conditional logic outside the transactional method; as a result, it never gets subscribed because upstream fails. But @transactional interceptors someshow subscribe to the result of
transactionalResource()
method. Without @transactional annotation result oftransactionalResource()
is never subscribed.Is there a way I can make this behavior work as I intend to. I checked context propagation but I am afraid I didn't understand how it can help me with this scenario.
Note: Actually in my real application example
"This should not invoke!!"
invoked after the exception was logged. Maybe something with the test class. But still, no way to prevent it.Console output
Beta Was this translation helpful? Give feedback.
All reactions