From 69681f626a3327e163466fcd892b721fcc1b5556 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 28 Sep 2020 19:37:40 +0200 Subject: [PATCH] Added extra IPC/UDP test --- .../dorkboxTest/network/MultipleServerTest.kt | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/test/dorkboxTest/network/MultipleServerTest.kt b/test/dorkboxTest/network/MultipleServerTest.kt index a3d00279..9083e489 100644 --- a/test/dorkboxTest/network/MultipleServerTest.kt +++ b/test/dorkboxTest/network/MultipleServerTest.kt @@ -53,8 +53,87 @@ class MultipleServerTest : BaseTest() { @Test @Throws(SecurityException::class, IOException::class) - fun multipleServers() { + fun multipleUDP() { val portOffset = 2 + received.set(0) + + var serverAeronDir: File? = null + val didReceive = mutableListOf() + + for (count in 0 until total) { + didReceive.add(AtomicBoolean()) + val offset = count * portOffset + + val configuration = serverConfig() + configuration.subscriptionPort += offset + configuration.publicationPort += offset + configuration.aeronDirectory = serverAeronDir + configuration.enableIpc = false + + val server: Server = Server(configuration) + addEndPoint(server) + + server.onMessage{ connection, message -> + if (message != "client_$count") { + Assert.fail() + } + + didReceive[count].set(true) + if (received.incrementAndGet() == total) { + connection.logger.error("Done, stopping endpoints") + stopEndPoints() + } + } + + server.bind() + + serverAeronDir = File(configuration.aeronDirectory.toString() + count) + } + + var clientAeronDir: File? = null + val didSend = mutableListOf() + + for (count in 0 until total) { + didSend.add(AtomicBoolean()) + val offset = count * portOffset + + val configuration = clientConfig() + configuration.subscriptionPort += offset + configuration.publicationPort += offset + configuration.aeronDirectory = clientAeronDir + configuration.enableIpc = false + + + val client: Client = Client(configuration) + addEndPoint(client) + + clientAeronDir = File(configuration.aeronDirectory.toString() + count) + + client.onConnect { connection -> + didSend[count].set(true) + connection.send("client_$count") + } + + runBlocking { + client.connect(LOOPBACK) + } + } + + waitForThreads() + + didSend.forEach { + assertTrue(it.get()) + } + didReceive.forEach { + assertTrue(it.get()) + } + } + + @Test + @Throws(SecurityException::class, IOException::class) + fun multipleIPC() { + val portOffset = 2 + received.set(0) var serverAeronDir: File? = null val didReceive = mutableListOf()