-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KTOR-2914 Change exception type and clarify message (#3201)
* KTOR-2914 Change exception type and clarify message
- Loading branch information
Showing
2 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
ktor-network/jvm/test/io/ktor/network/selector/ActorSelectorManagerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.network.selector | ||
|
||
import io.mockk.* | ||
import kotlinx.coroutines.* | ||
import org.junit.* | ||
import org.junit.Test | ||
import java.io.* | ||
import kotlin.test.* | ||
|
||
class ActorSelectorManagerTest { | ||
val manager = ActorSelectorManager(Dispatchers.Default) | ||
|
||
@After | ||
fun tearDown() { | ||
manager.close() | ||
} | ||
|
||
@Test | ||
fun testSelectableIsClosed(): Unit = runBlocking { | ||
val selectable: Selectable = mockk() | ||
every { selectable.interestedOps } returns SelectInterest.READ.flag | ||
every { selectable.isClosed } returns true | ||
|
||
assertFailsWith<IOException> { | ||
manager.select(selectable, SelectInterest.READ) | ||
} | ||
} | ||
|
||
@Test | ||
fun testSelectOnWrongInterest(): Unit = runBlocking { | ||
val selectable: Selectable = mockk() | ||
every { selectable.interestedOps } returns SelectInterest.READ.flag | ||
every { selectable.isClosed } returns false | ||
|
||
assertFailsWith<IllegalStateException> { | ||
manager.select(selectable, SelectInterest.WRITE) | ||
} | ||
} | ||
} |