Network/test/dorkboxTest/network/PingTest.kt

61 lines
1.6 KiB
Kotlin
Raw Normal View History

2021-04-29 10:25:25 +02:00
package dorkboxTest.network
import ch.qos.logback.classic.Level
import dorkbox.network.Client
import dorkbox.network.Server
import dorkbox.network.connection.Connection
import kotlinx.atomicfu.atomic
import org.junit.Assert
2021-04-29 10:25:25 +02:00
import org.junit.Test
class PingTest : BaseTest() {
2022-06-11 23:54:23 +02:00
val counter = atomic(0)
2021-04-29 10:25:25 +02:00
@Test
fun RmiPing() {
setLogLevel(Level.TRACE)
val clientSuccess = atomic(false)
run {
val configuration = serverConfig()
val server: Server<Connection> = Server(configuration)
addEndPoint(server)
server.bind()
}
run {
val config = clientConfig()
val client: Client<Connection> = Client(config)
addEndPoint(client)
client.onConnect {
repeat(100) {
ping {
2022-04-04 23:21:44 +02:00
// a ping object is returned, once the round-trip is complete
2022-06-11 23:54:23 +02:00
val count = counter.getAndIncrement()
println(count)
2022-06-11 23:54:23 +02:00
if (count == 99) {
clientSuccess.value = true
logger.error("out-bound: $outbound")
logger.error("in-bound: $inbound")
logger.error("round-trip: $roundtrip")
stopEndPoints()
}
}
}
}
client.connect(LOCALHOST)
}
2022-06-11 23:54:23 +02:00
waitForThreads(500)
Assert.assertTrue(clientSuccess.value)
}
2021-04-29 10:25:25 +02:00
}