aboutsummaryrefslogtreecommitdiffstats
path: root/kotlinx-coroutines-core/common/test/channels/ArrayChannelTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'kotlinx-coroutines-core/common/test/channels/ArrayChannelTest.kt')
-rw-r--r--kotlinx-coroutines-core/common/test/channels/ArrayChannelTest.kt34
1 files changed, 17 insertions, 17 deletions
diff --git a/kotlinx-coroutines-core/common/test/channels/ArrayChannelTest.kt b/kotlinx-coroutines-core/common/test/channels/ArrayChannelTest.kt
index a57b519f..632fd292 100644
--- a/kotlinx-coroutines-core/common/test/channels/ArrayChannelTest.kt
+++ b/kotlinx-coroutines-core/common/test/channels/ArrayChannelTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines.channels
@@ -38,17 +38,17 @@ class ArrayChannelTest : TestBase() {
}
@Test
- fun testClosedBufferedReceiveOrNull() = runTest {
+ fun testClosedBufferedReceiveCatching() = runTest {
val q = Channel<Int>(1)
check(q.isEmpty && !q.isClosedForSend && !q.isClosedForReceive)
expect(1)
launch {
expect(5)
check(!q.isEmpty && q.isClosedForSend && !q.isClosedForReceive)
- assertEquals(42, q.receiveOrNull())
+ assertEquals(42, q.receiveCatching().getOrNull())
expect(6)
check(!q.isEmpty && q.isClosedForSend && q.isClosedForReceive)
- assertNull(q.receiveOrNull())
+ assertNull(q.receiveCatching().getOrNull())
expect(7)
}
expect(2)
@@ -86,31 +86,31 @@ class ArrayChannelTest : TestBase() {
}
@Test
- fun testOfferAndPoll() = runTest {
+ fun testTryOp() = runTest {
val q = Channel<Int>(1)
- assertTrue(q.offer(1))
+ assertTrue(q.trySend(1).isSuccess)
expect(1)
launch {
expect(3)
- assertEquals(1, q.poll())
+ assertEquals(1, q.tryReceive().getOrNull())
expect(4)
- assertNull(q.poll())
+ assertNull(q.tryReceive().getOrNull())
expect(5)
assertEquals(2, q.receive()) // suspends
expect(9)
- assertEquals(3, q.poll())
+ assertEquals(3, q.tryReceive().getOrNull())
expect(10)
- assertNull(q.poll())
+ assertNull(q.tryReceive().getOrNull())
expect(11)
}
expect(2)
yield()
expect(6)
- assertTrue(q.offer(2))
+ assertTrue(q.trySend(2).isSuccess)
expect(7)
- assertTrue(q.offer(3))
+ assertTrue(q.trySend(3).isSuccess)
expect(8)
- assertFalse(q.offer(4))
+ assertFalse(q.trySend(4).isSuccess)
yield()
finish(12)
}
@@ -134,7 +134,7 @@ class ArrayChannelTest : TestBase() {
q.cancel()
check(q.isClosedForSend)
check(q.isClosedForReceive)
- assertFailsWith<CancellationException> { q.receiveOrNull() }
+ assertFailsWith<CancellationException> { q.receiveCatching().getOrThrow() }
finish(12)
}
@@ -142,7 +142,7 @@ class ArrayChannelTest : TestBase() {
fun testCancelWithCause() = runTest({ it is TestCancellationException }) {
val channel = Channel<Int>(5)
channel.cancel(TestCancellationException())
- channel.receiveOrNull()
+ channel.receive()
}
@Test
@@ -157,10 +157,10 @@ class ArrayChannelTest : TestBase() {
val capacity = 42
val channel = Channel<Int>(capacity)
repeat(4) {
- channel.offer(-1)
+ channel.trySend(-1)
}
repeat(4) {
- channel.receiveOrNull()
+ channel.receiveCatching().getOrNull()
}
checkBufferChannel(channel, capacity)
}