it should "should be able to use custom execution contexts" in {
|
var originalThreadId: Long = 0
|
var observeOnThreadId1: Long = 0
|
var observeOnThreadId2: Long = 0
|
val ctx1 = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(5))
|
val ctx2 = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(5))
|
|
Await.result(
|
observable()
|
.map((i: Int) => {
|
originalThreadId = Thread.currentThread().getId
|
i
|
})
|
.observeOn(ctx1)
|
.map((i: Int) => {
|
observeOnThreadId1 = Thread.currentThread().getId
|
i
|
})
|
.observeOn(ctx2)
|
.map((i: Int) => {
|
observeOnThreadId2 = Thread.currentThread().getId
|
i
|
})
|
.toFuture(),
|
Duration(10, TimeUnit.SECONDS)
|
)
|
ctx1.shutdown()
|
ctx2.shutdown()
|
|
originalThreadId should not be observeOnThreadId1
|
observeOnThreadId1 should not be observeOnThreadId2
|
}
|