https://kotlinlang.org logo
#spring
Title
g

gotoOla

03/10/2021, 12:27 PM
Does anybody have any tips on how to run coroutines with spring and reactor context? Right now I've gotten my service level code to work with `
Copy code
val reactorContext = coroutineContext[ReactorContext.Key]!!.context.asCoroutineContext()
but if I try to write a unit-test for this I fail with a nullpointerException since I guess the coroutineContext[ReactorContext.Key] is populated from the context given by spring/the controller layer? ?
I access the coroutineContext like this because I am accessing Context-variables in suspend-functions
s

Saharath Kleips

03/10/2021, 5:51 PM
If it’s just for a unit test, you can add a mock context yourself:
Copy code
runBlocking(context = myMockContext) { ... }
👍 1
15 Views