mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-13 08:31:31 +00:00
31 lines
666 B
Kotlin
31 lines
666 B
Kotlin
package concurrent
|
|
|
|
import kotlin.concurrent.*
|
|
import kotlin.test.*
|
|
|
|
import org.junit.Test as test
|
|
|
|
import java.util.concurrent.*
|
|
import java.util.concurrent.TimeUnit.*
|
|
|
|
class ThreadTest {
|
|
test fun scheduledTask() {
|
|
|
|
val pool = Executors.newFixedThreadPool(1)
|
|
val countDown = CountDownLatch(1)
|
|
pool {
|
|
countDown.countDown()
|
|
}
|
|
assertTrue(countDown.await(2, SECONDS), "Count down is executed")
|
|
}
|
|
|
|
test fun callableInvoke() {
|
|
|
|
val pool = Executors.newFixedThreadPool(1)
|
|
val future = pool<String> {
|
|
"Hello"
|
|
}
|
|
assertEquals("Hello", future.get(2, SECONDS))
|
|
}
|
|
|
|
} |