Added unit test for manually starting/stopping the aeron media driver outside of the network
This commit is contained in:
parent
3c4cfe805f
commit
3b9eb00de9
|
@ -2,6 +2,7 @@ package dorkboxTest.network
|
||||||
|
|
||||||
import dorkbox.network.Client
|
import dorkbox.network.Client
|
||||||
import dorkbox.network.Server
|
import dorkbox.network.Server
|
||||||
|
import dorkbox.network.aeron.AeronConfig
|
||||||
import dorkbox.network.connection.Connection
|
import dorkbox.network.connection.Connection
|
||||||
import kotlinx.atomicfu.atomic
|
import kotlinx.atomicfu.atomic
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
@ -68,6 +69,66 @@ class DisconnectReconnectTest : BaseTest() {
|
||||||
Assert.assertEquals(4, reconnectCount.value)
|
Assert.assertEquals(4, reconnectCount.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun manualMediaDriverAndReconnectClient() {
|
||||||
|
val serverConfiguration = serverConfig()
|
||||||
|
val mediaDriver = runBlocking {
|
||||||
|
AeronConfig.startDriver(serverConfiguration)
|
||||||
|
}
|
||||||
|
|
||||||
|
run {
|
||||||
|
val server: Server<Connection> = Server(serverConfiguration)
|
||||||
|
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()
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
AeronConfig.stopDriver(mediaDriver)
|
||||||
|
|
||||||
|
System.err.println("Connection count (after reconnecting) is: " + reconnectCount.value)
|
||||||
|
Assert.assertEquals(4, reconnectCount.value)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun reconnectWithFallbackClient() {
|
fun reconnectWithFallbackClient() {
|
||||||
run {
|
run {
|
||||||
|
@ -127,7 +188,7 @@ class DisconnectReconnectTest : BaseTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun disconenctedMediaDriver() {
|
fun disconnectedMediaDriver() {
|
||||||
val server: Server<Connection>
|
val server: Server<Connection>
|
||||||
run {
|
run {
|
||||||
val config = serverConfig()
|
val config = serverConfig()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user