Added test for IPC -> UDP fallback

This commit is contained in:
nathan 2020-09-10 14:40:09 +02:00
parent 8885107052
commit 09c895e981

View File

@ -62,6 +62,64 @@ class DisconnectReconnectTest : BaseTest() {
}
waitForThreads()
System.err.println("Connection count (after reconnecting) is: " + reconnectCount.value)
Assert.assertEquals(4, reconnectCount.value)
}
@Test
fun reconnectWithFallbackClient() {
run {
val config = serverConfig()
config.enableIpc = false
val server: Server<Connection> = Server(config)
addEndPoint(server)
server.bind()
server.onConnect { connection ->
connection.logger.error("Disconnecting after 2 seconds.")
delay(2000)
connection.logger.error("Disconnecting....")
connection.close()
}
}
run {
val config = clientConfig()
config.enableIpc = true
config.enableIpcForLoopback = true
val client: Client<Connection> = Client(config)
addEndPoint(client)
client.onDisconnect { connection ->
connection.logger.error("Disconnected!")
val count = reconnectCount.getAndIncrement()
if (count == 3) {
connection.logger.error("Shutting down")
stopEndPoints()
}
else {
connection.logger.error("Reconnecting: $count")
try {
client.connect(LOOPBACK)
} catch (e: IOException) {
e.printStackTrace()
}
}
}
runBlocking {
client.connect(LOOPBACK)
}
}
waitForThreads()
System.err.println("Connection count (after reconnecting) is: " + reconnectCount.value)