From 8caef6611c7a5e4cd269a18803da5295cf8bf090 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 2 Sep 2020 03:18:10 +0200 Subject: [PATCH] Cleaned up unit tests --- test/dorkboxTest/network/AeronClient.kt | 20 +++------ test/dorkboxTest/network/AeronServer.kt | 4 +- test/dorkboxTest/network/BaseTest.kt | 4 +- .../network/DisconnectReconnectTest.kt | 2 +- test/dorkboxTest/network/ListenerTest.kt | 2 +- .../dorkboxTest/network/MultipleServerTest.kt | 2 +- test/dorkboxTest/network/PingPongTest.kt | 2 +- .../network/SerializationValidationTest.kt | 4 +- .../rmi/RmiDelayedInvocationSpamTest.kt | 45 ++++++++++++------- .../network/rmi/RmiDelayedInvocationTest.kt | 20 ++++----- test/dorkboxTest/network/rmi/RmiNestedTest.kt | 21 ++------- test/dorkboxTest/network/rmi/RmiSimpleTest.kt | 31 +++++++------ .../network/rmi/multiJVM/TestClient.kt | 3 +- .../network/rmi/multiJVM/TestServer.kt | 2 +- 14 files changed, 75 insertions(+), 87 deletions(-) diff --git a/test/dorkboxTest/network/AeronClient.kt b/test/dorkboxTest/network/AeronClient.kt index bf7b93eb..b6cdac52 100644 --- a/test/dorkboxTest/network/AeronClient.kt +++ b/test/dorkboxTest/network/AeronClient.kt @@ -94,15 +94,6 @@ object AeronClient { @Throws(Exception::class) @JvmStatic fun main(args: Array) { -// val ntpClient = NtpClient() -// ntpClient.requestTime("time.mit.edu", 10_000) -// -// println("ROUNDTRIP: ${ntpClient.roundTripTime}") -// println("NTP : ${convertLongToTime(System.currentTimeMillis())}") -// println("NTP : ${convertLongToTime(ntpClient.ntpTime)}") -// -// if (true) return - val configuration = Configuration() configuration.subscriptionPort = 2000 configuration.publicationPort = 2001 @@ -136,7 +127,6 @@ object AeronClient { runBlocking { client.connect("127.0.0.1") // UDP connection via loopback -// client.connect() // IPC connection } @@ -146,11 +136,11 @@ object AeronClient { // send - unreliable // send - priority (0-255 -- 255 is MAX priority) when sending, max is always sent immediately, then lower priority is sent if there is no backpressure from the MediaDriver. // send - IPC/local - runBlocking { - while (!client.isShutdown()) { - client.send("ECHO " + java.lang.Long.toUnsignedString(client.crypto.secureRandom.nextLong(), 16)) - } - } +// runBlocking { +// while (!client.isShutdown()) { +// client.send("ECHO " + java.lang.Long.toUnsignedString(client.crypto.secureRandom.nextLong(), 16)) +// } +// } // connection needs to know diff --git a/test/dorkboxTest/network/AeronServer.kt b/test/dorkboxTest/network/AeronServer.kt index c99b5bfb..38b6234d 100644 --- a/test/dorkboxTest/network/AeronServer.kt +++ b/test/dorkboxTest/network/AeronServer.kt @@ -96,12 +96,12 @@ object AeronServer { } server.onError { throwable -> - println("has error") + println("from test: has error") throwable.printStackTrace() } server.onError { connection, throwable -> - println("has error") + println("from test: has connection error") throwable.printStackTrace() } diff --git a/test/dorkboxTest/network/BaseTest.kt b/test/dorkboxTest/network/BaseTest.kt index 452fed4d..3095aa12 100644 --- a/test/dorkboxTest/network/BaseTest.kt +++ b/test/dorkboxTest/network/BaseTest.kt @@ -83,8 +83,8 @@ abstract class BaseTest { // rootLogger.setLevel(Level.OFF); -// rootLogger.level = Level.INFO; - rootLogger.level = Level.TRACE; + rootLogger.level = Level.INFO; +// rootLogger.level = Level.TRACE; // rootLogger.level = Level.DEBUG // rootLogger.level = Level.ALL; diff --git a/test/dorkboxTest/network/DisconnectReconnectTest.kt b/test/dorkboxTest/network/DisconnectReconnectTest.kt index 1aa157e0..4b56265a 100644 --- a/test/dorkboxTest/network/DisconnectReconnectTest.kt +++ b/test/dorkboxTest/network/DisconnectReconnectTest.kt @@ -20,7 +20,7 @@ class DisconnectReconnectTest : BaseTest() { val server: Server = Server(configuration) addEndPoint(server) - server.bind(false) + server.bind() server.onConnect { connection -> connection.logger.error("Disconnecting after 2 seconds.") diff --git a/test/dorkboxTest/network/ListenerTest.kt b/test/dorkboxTest/network/ListenerTest.kt index bb01727a..e05f7b5b 100644 --- a/test/dorkboxTest/network/ListenerTest.kt +++ b/test/dorkboxTest/network/ListenerTest.kt @@ -112,7 +112,7 @@ class ListenerTest : BaseTest() { serverDisconnect.value = true } - server.bind(false) + server.bind() diff --git a/test/dorkboxTest/network/MultipleServerTest.kt b/test/dorkboxTest/network/MultipleServerTest.kt index f4dfa304..9e19ccd2 100644 --- a/test/dorkboxTest/network/MultipleServerTest.kt +++ b/test/dorkboxTest/network/MultipleServerTest.kt @@ -83,7 +83,7 @@ class MultipleServerTest : BaseTest() { } } - server.bind(false) + server.bind() serverAeronDir = File(configuration.aeronLogDirectory.toString() + count) } diff --git a/test/dorkboxTest/network/PingPongTest.kt b/test/dorkboxTest/network/PingPongTest.kt index 4716016d..e4d88cd5 100644 --- a/test/dorkboxTest/network/PingPongTest.kt +++ b/test/dorkboxTest/network/PingPongTest.kt @@ -64,7 +64,7 @@ class PingPongTest : BaseTest() { val server: Server = Server(configuration) addEndPoint(server) - server.bind(false) + server.bind() server.onError { _, throwable -> fail = "Error during processing. $throwable" diff --git a/test/dorkboxTest/network/SerializationValidationTest.kt b/test/dorkboxTest/network/SerializationValidationTest.kt index e56227f3..031b6743 100644 --- a/test/dorkboxTest/network/SerializationValidationTest.kt +++ b/test/dorkboxTest/network/SerializationValidationTest.kt @@ -36,7 +36,7 @@ class SerializationValidationTest : BaseTest() { server.onMessage { connection, message -> stopEndPoints() } - server.bind(false) + server.bind() } @@ -74,7 +74,7 @@ class SerializationValidationTest : BaseTest() { server.onMessage { connection, message -> stopEndPoints() } - server.bind(false) + server.bind() } diff --git a/test/dorkboxTest/network/rmi/RmiDelayedInvocationSpamTest.kt b/test/dorkboxTest/network/rmi/RmiDelayedInvocationSpamTest.kt index e9191406..96b0d52f 100644 --- a/test/dorkboxTest/network/rmi/RmiDelayedInvocationSpamTest.kt +++ b/test/dorkboxTest/network/rmi/RmiDelayedInvocationSpamTest.kt @@ -21,12 +21,10 @@ import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkbox.network.rmi.RemoteObject import dorkbox.network.serialization.Serialization -import dorkbox.util.exceptions.SecurityException import dorkboxTest.network.BaseTest import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Test -import java.io.IOException import java.util.concurrent.atomic.AtomicLong class RmiDelayedInvocationSpamTest : BaseTest() { @@ -34,22 +32,42 @@ class RmiDelayedInvocationSpamTest : BaseTest() { private val RMI_ID = 12251 + var async = true + @Test - @Throws(SecurityException::class, IOException::class) fun rmiNetwork() { runBlocking { + async = false + rmi { configuration -> + configuration.enableIpcForLoopback = false + } + } + } + + @Test + fun rmiNetworkAync() { + runBlocking { + async = true + rmi { configuration -> + configuration.enableIpcForLoopback = false + } + } + } + + @Test + fun rmiIpc() { + runBlocking { + async = false rmi() } } @Test - @Throws(SecurityException::class, IOException::class) - fun rmiLocal() { -// rmi(object : Config() { -// fun apply(configuration: Configuration) { -// configuration.localChannelName = EndPoint.LOCAL_CHANNEL -// } -// }) + fun rmiIpcAsync() { + runBlocking { + async = true + rmi() + } } fun register(serialization: Serialization) { @@ -63,10 +81,8 @@ class RmiDelayedInvocationSpamTest : BaseTest() { suspend fun rmi(config: (Configuration) -> Unit = {}) { val server: Server - val async = false - val mod = if (async) 10_000L else 200L - val totalRuns = if (async) 1_000_000 else 700 + val totalRuns = if (async) 1_000_000 else 1_000 run { val configuration = serverConfig() @@ -77,7 +93,7 @@ class RmiDelayedInvocationSpamTest : BaseTest() { addEndPoint(server) server.saveGlobalObject(TestObjectImpl(counter), RMI_ID) - server.bind(false) + server.bind() } @@ -116,7 +132,6 @@ class RmiDelayedInvocationSpamTest : BaseTest() { // have to do this first, so it will wait for the client responses! // if we close the client first, the connection will be closed, and the responses will never arrive to the server - server.close() stopEndPoints() } diff --git a/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt b/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt index e8c3c0a3..aad2aa3c 100644 --- a/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt +++ b/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt @@ -20,11 +20,9 @@ import dorkbox.network.Configuration import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkbox.network.serialization.Serialization -import dorkbox.util.exceptions.SecurityException import dorkboxTest.network.BaseTest import kotlinx.coroutines.runBlocking import org.junit.Test -import java.io.IOException import java.util.concurrent.atomic.AtomicInteger class RmiDelayedInvocationTest : BaseTest() { @@ -32,21 +30,19 @@ class RmiDelayedInvocationTest : BaseTest() { private val OBJ_ID = 123 @Test - @Throws(SecurityException::class, IOException::class) fun rmiNetwork() { runBlocking { - rmi() + rmi() { configuration -> + configuration.enableIpcForLoopback = false + } } } @Test - @Throws(SecurityException::class, IOException::class) - fun rmiLocal() { -// rmi(object : Config() { -// fun apply(configuration: Configuration) { -// configuration.localChannelName = EndPoint.LOCAL_CHANNEL -// } -// }) + fun rmiIpc() { + runBlocking { + rmi() + } } fun register(serialization: Serialization) { @@ -67,7 +63,7 @@ class RmiDelayedInvocationTest : BaseTest() { addEndPoint(server) server.saveGlobalObject(TestObjectImpl(iterateLock), OBJ_ID) - server.bind(false) + server.bind() } run { diff --git a/test/dorkboxTest/network/rmi/RmiNestedTest.kt b/test/dorkboxTest/network/rmi/RmiNestedTest.kt index 2797348a..5dde38c9 100644 --- a/test/dorkboxTest/network/rmi/RmiNestedTest.kt +++ b/test/dorkboxTest/network/rmi/RmiNestedTest.kt @@ -18,12 +18,10 @@ package dorkboxTest.network.rmi import dorkbox.network.Client import dorkbox.network.Server import dorkbox.network.connection.Connection -import dorkbox.util.exceptions.SecurityException import dorkboxTest.network.BaseTest import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Test -import java.io.IOException import java.util.concurrent.atomic.AtomicInteger @@ -35,19 +33,6 @@ class RmiNestedTest : BaseTest() { private val idCounter = AtomicInteger() } - @Test - @Throws(SecurityException::class, IOException::class) - fun rmiIPC() { -// TODO("DO IPC STUFF!") - // rmi(new Config() { - // @Override - // public - // void apply(final Configuration configuration) { - // configuration.localChannelName = EndPoint.LOCAL_CHANNEL; - // } - // }); - } - /** * In this test the server has two objects in an object space. * @@ -93,7 +78,7 @@ class RmiNestedTest : BaseTest() { } } - server.bind(false) + server.bind() } @@ -163,7 +148,7 @@ class RmiNestedTest : BaseTest() { } } - server.bind(false) + server.bind() } @@ -232,7 +217,7 @@ class RmiNestedTest : BaseTest() { } } - server.bind(false) + server.bind() } diff --git a/test/dorkboxTest/network/rmi/RmiSimpleTest.kt b/test/dorkboxTest/network/rmi/RmiSimpleTest.kt index 5fef4000..5d5b52bb 100644 --- a/test/dorkboxTest/network/rmi/RmiSimpleTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSimpleTest.kt @@ -50,23 +50,27 @@ class RmiSimpleTest : BaseTest() { @Test fun rmiNetworkGlobal() { - rmiGlobal() + rmiGlobal() { configuration -> + configuration.enableIpcForLoopback = false + } } @Test fun rmiNetworkConnection() { + rmi { configuration -> + configuration.enableIpcForLoopback = false + } + } + + @Test + fun rmiIpcNetworkGlobal() { + rmiGlobal() + } + + @Test + fun rmiIPcNetworkConnection() { rmi() } -// -// @Test -// @Throws(SecurityException::class, IOException::class, InterruptedException::class) -// fun rmiIPC() { -// rmi { configuration -> -// if (configuration is ServerConfiguration) { -// configuration.listenIpAddress = LOOPBACK -// } -// } -// } fun rmi(config: (Configuration) -> Unit = {}) { run { @@ -79,8 +83,7 @@ class RmiSimpleTest : BaseTest() { val server = Server(configuration) addEndPoint(server) - - server.bind(false) + server.bind() server.onMessage { connection, m -> System.err.println("Received finish signal for test for: Client -> Server") @@ -146,7 +149,7 @@ class RmiSimpleTest : BaseTest() { val server = Server(configuration) addEndPoint(server) - server.bind(false) + server.bind() server.onMessage { connection, m -> System.err.println("Received finish signal for test for: Client -> Server") diff --git a/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt b/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt index 7f2fbd0c..324122e1 100644 --- a/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt +++ b/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt @@ -105,8 +105,7 @@ object TestClient { runBlocking { client.connect(BaseTest.LOOPBACK) + client.waitForClose() } - - client.waitForShutdown() } } diff --git a/test/dorkboxTest/network/rmi/multiJVM/TestServer.kt b/test/dorkboxTest/network/rmi/multiJVM/TestServer.kt index 1c20be81..9e08d518 100644 --- a/test/dorkboxTest/network/rmi/multiJVM/TestServer.kt +++ b/test/dorkboxTest/network/rmi/multiJVM/TestServer.kt @@ -80,6 +80,6 @@ object TestServer { // } } - server.bind(false) + server.bind() } }