aboutsummaryrefslogtreecommitdiff
path: root/reactive/kotlinx-coroutines-reactor/test/FluxContextTest.kt
blob: 1ed3a164f6fe1af88a8187fb121fc33f927e12ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package kotlinx.coroutines.reactor

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.reactive.*
import org.junit.*
import org.junit.Test
import reactor.core.publisher.*
import kotlin.test.*

class FluxContextTest : TestBase() {
    private val dispatcher = newSingleThreadContext("FluxContextTest")

    @After
    fun tearDown() {
        dispatcher.close()
    }

    @Test
    fun testFluxCreateAsFlowThread() = runTest {
        expect(1)
        val mainThread = Thread.currentThread()
        val dispatcherThread = withContext(dispatcher) { Thread.currentThread() }
        assertTrue(dispatcherThread != mainThread)
        Flux.create<String> {
            assertEquals(dispatcherThread, Thread.currentThread())
            it.next("OK")
            it.complete()
        }
            .asFlow()
            .flowOn(dispatcher)
            .collect {
                expect(2)
                assertEquals("OK", it)
                assertEquals(mainThread, Thread.currentThread())
            }
        finish(3)
    }
}