separate BreakConnectionException and more correct processing for ClosedException.
This commit is contained in:
1 parent
4f6bc3c77e
commit
0d3a8ae95c
7 files changed
+84
-16
No files matched your search
@@ -7,7 +7,10 @@ import net.sergeych.crypto2.SigningKey
|
||||
import net.sergeych.crypto2.initCrypto
|
||||
import net.sergeych.kiloparsec.*
|
||||
import net.sergeych.mp_logger.Log
|
||||
import kotlin.test.*
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.fail
|
||||
|
||||
private var dcnt = 0
|
||||
fun createTestDevice(): Pair<Transport.Device, Transport.Device> {
|
||||
@@ -154,6 +157,8 @@ class TransportTest {
|
||||
d2.close()
|
||||
}
|
||||
|
||||
class TestException(text: String) : Exception(text)
|
||||
|
||||
@Test
|
||||
fun testClient() = runTest {
|
||||
initCrypto()
|
||||
@@ -173,6 +178,10 @@ class TransportTest {
|
||||
val serverId = SigningKey.pair()
|
||||
val clientId = SigningKey.pair()
|
||||
|
||||
val cmdException by command<Unit, Unit>()
|
||||
val cmdRemoteExceptionTest by command<Unit, String>()
|
||||
val cmdBreak by command<Unit, Unit>()
|
||||
|
||||
val serverInterface = KiloInterface<String>().apply {
|
||||
on(cmdPing) {
|
||||
"pong! [$it]"
|
||||
@@ -189,15 +198,26 @@ class TransportTest {
|
||||
on(cmdChainCallServer2) {
|
||||
remote.call(cmdChainCallClient2, "$it-s2")
|
||||
}
|
||||
registerError { IllegalStateException() }
|
||||
registerError { IllegalArgumentException(it) }
|
||||
on(cmdException) { throw TestException("te1") }
|
||||
on(cmdRemoteExceptionTest) {
|
||||
try {
|
||||
remote.call(cmdException)
|
||||
"error!"
|
||||
} catch (e: TestException) {
|
||||
"ok: ${e.message}"
|
||||
}
|
||||
}
|
||||
on(cmdBreak) { throw LocalInterface.BreakConnectionException() }
|
||||
registerError { TestException(it) }
|
||||
}
|
||||
val kiloServerConnection = KiloServerConnection(serverInterface, d1, "server session", serverId.secretKey
|
||||
val kiloServerConnection = KiloServerConnection(
|
||||
serverInterface, d1, "server session", serverId.secretKey
|
||||
)
|
||||
launch { kiloServerConnection.run() }
|
||||
|
||||
var cnt = 0
|
||||
val client = KiloClient {
|
||||
addErrors(serverInterface)
|
||||
session { "client session!" }
|
||||
secretIdKey = clientId.secretKey
|
||||
local {
|
||||
@@ -208,11 +228,13 @@ class TransportTest {
|
||||
"client pong: $it"
|
||||
}
|
||||
on(cmdChainCallClient1) {
|
||||
remote.call(cmdChainCallServer2,"$it-c1")
|
||||
remote.call(cmdChainCallServer2, "$it-c1")
|
||||
}
|
||||
on(cmdChainCallClient2) { "$it-c2" }
|
||||
on(cmdException) { throw TestException("te-local") }
|
||||
}
|
||||
connect {
|
||||
println("Called connect: $cnt")
|
||||
if (cnt++ > 0) {
|
||||
cancel()
|
||||
fail("connect called once again")
|
||||
@@ -226,6 +248,18 @@ class TransportTest {
|
||||
assertEquals("server push: bar", kiloServerConnection.call(cmdPush, "bar"))
|
||||
|
||||
assertEquals("**-s1-c1-s2-c2", client.call(cmdChainCallServer1, "**"))
|
||||
|
||||
assertThrows<TestException> { client.call(cmdException) }
|
||||
assertEquals("ok: te-local", client.call(cmdRemoteExceptionTest))
|
||||
|
||||
assertThrows<RemoteInterface.ClosedException> {
|
||||
client.call(cmdBreak)
|
||||
}
|
||||
|
||||
// Note that current transport test is too simple,
|
||||
// therefore, we can't test reconnecting, also we need server and client instances
|
||||
// not connections, so that's all
|
||||
|
||||
d1.close()
|
||||
d2.close()
|
||||
client.close()
|
||||
|
||||
Reference in new issue
Block a user