diff --git a/build.gradle.kts b/build.gradle.kts index fd2f3d8..d6ab9cf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ val xodusVersion by extra("2.0.1") allprojects { group = "space.kscience" - version = "0.3.0-dev-3" + version = "0.3.0-dev-4" repositories{ maven("https://maven.pkg.jetbrains.space/spc/p/sci/dev") } diff --git a/controls-core/src/jvmMain/kotlin/space/kscience/controls/ports/ChannelPort.kt b/controls-core/src/jvmMain/kotlin/space/kscience/controls/ports/ChannelPort.kt index ec50d47..f450607 100644 --- a/controls-core/src/jvmMain/kotlin/space/kscience/controls/ports/ChannelPort.kt +++ b/controls-core/src/jvmMain/kotlin/space/kscience/controls/ports/ChannelPort.kt @@ -51,7 +51,7 @@ public class ChannelPort( } if (num < 0) cancel("The input channel is exhausted") } catch (ex: Exception) { - if(ex is AsynchronousCloseException){ + if (ex is AsynchronousCloseException) { logger.info { "Channel $channel closed" } } else { logger.error(ex) { "Channel read error, retrying in 1 second" } @@ -108,7 +108,7 @@ public object UdpPort : PortFactory { /** * Connect a datagram channel to a remote host/port. If [localPort] is provided, it is used to bind local port for receiving messages. */ - public fun open( + public fun openChannel( context: Context, remoteHost: String, remotePort: Int, @@ -130,6 +130,6 @@ public object UdpPort : PortFactory { val remotePort by meta.number { error("Remote port is not specified") } val localHost: String? by meta.string() val localPort: Int? by meta.int() - return open(context, remoteHost, remotePort.toInt(), localPort, localHost ?: "localhost") + return openChannel(context, remoteHost, remotePort.toInt(), localPort, localHost ?: "localhost") } } \ No newline at end of file diff --git a/controls-core/src/jvmTest/kotlin/space/kscience/controls/ports/PortIOTest.kt b/controls-core/src/jvmTest/kotlin/space/kscience/controls/ports/PortIOTest.kt index 3f92500..daa6173 100644 --- a/controls-core/src/jvmTest/kotlin/space/kscience/controls/ports/PortIOTest.kt +++ b/controls-core/src/jvmTest/kotlin/space/kscience/controls/ports/PortIOTest.kt @@ -1,6 +1,10 @@ package space.kscience.controls.ports -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.take +import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test @@ -25,19 +29,19 @@ internal class PortIOTest { @Test fun testUdpCommunication() = runTest { - val receiver = UdpPort.open(Global, "localhost", 8811, localPort = 8812) - val sender = UdpPort.open(Global, "localhost", 8812, localPort = 8811) + val receiver = UdpPort.openChannel(Global, "localhost", 8811, localPort = 8812) + val sender = UdpPort.openChannel(Global, "localhost", 8812, localPort = 8811) + delay(30) repeat(10) { sender.send("Line number $it\n") } val res = receiver .receiving() - .onEach { println("ARRAY: ${it.decodeToString()}") } .withStringDelimiter("\n") - .onEach { println("LINE: $it") } - .take(10).toList() + .take(10) + .toList() assertEquals("Line number 3", res[3].trim()) receiver.close()