2023-05-28 18:41:46 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2023 dorkbox, llc
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-04-29 10:25:25 +02:00
|
|
|
package dorkboxTest.network
|
|
|
|
|
2021-07-07 16:19:00 +02:00
|
|
|
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
|
2021-07-07 16:19:00 +02:00
|
|
|
fun RmiPing() {
|
2023-06-25 17:25:29 +02:00
|
|
|
// session/stream count errors
|
2021-07-07 16:19:00 +02:00
|
|
|
val clientSuccess = atomic(false)
|
|
|
|
|
|
|
|
run {
|
|
|
|
val configuration = serverConfig()
|
|
|
|
|
|
|
|
val server: Server<Connection> = Server(configuration)
|
|
|
|
addEndPoint(server)
|
2023-06-26 19:28:55 +02:00
|
|
|
server.bind(2000)
|
2021-07-07 16:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
run {
|
|
|
|
val config = clientConfig()
|
|
|
|
|
|
|
|
val client: Client<Connection> = Client(config)
|
|
|
|
addEndPoint(client)
|
|
|
|
|
|
|
|
client.onConnect {
|
2021-07-08 14:33:24 +02:00
|
|
|
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()
|
|
|
|
if (count == 99) {
|
2021-07-08 14:33:24 +02:00
|
|
|
clientSuccess.value = true
|
2021-07-07 16:19:00 +02:00
|
|
|
|
2021-07-08 14:33:24 +02:00
|
|
|
logger.error("out-bound: $outbound")
|
|
|
|
logger.error("in-bound: $inbound")
|
|
|
|
logger.error("round-trip: $roundtrip")
|
2021-07-07 16:19:00 +02:00
|
|
|
|
2021-07-08 14:33:24 +02:00
|
|
|
stopEndPoints()
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 16:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 19:28:55 +02:00
|
|
|
client.connect(LOCALHOST, 2000)
|
2021-07-07 16:19:00 +02:00
|
|
|
}
|
|
|
|
|
2023-06-16 14:15:27 +02:00
|
|
|
waitForThreads()
|
2021-07-07 16:19:00 +02:00
|
|
|
|
|
|
|
Assert.assertTrue(clientSuccess.value)
|
|
|
|
}
|
2021-04-29 10:25:25 +02:00
|
|
|
}
|