diff --git a/test/dorkboxTest/network/AeronClient.kt b/test/dorkboxTest/network/AeronClient.kt index ce6e7650..e0d06571 100644 --- a/test/dorkboxTest/network/AeronClient.kt +++ b/test/dorkboxTest/network/AeronClient.kt @@ -128,10 +128,7 @@ object AeronClient { println(message) } - runBlocking { - client.connect("127.0.0.1") // UDP connection via loopback - } - + client.connect("127.0.0.1") // UDP connection via loopback // different ones needed diff --git a/test/dorkboxTest/network/BaseTest.kt b/test/dorkboxTest/network/BaseTest.kt index 28c0d01d..22436030 100644 --- a/test/dorkboxTest/network/BaseTest.kt +++ b/test/dorkboxTest/network/BaseTest.kt @@ -70,14 +70,23 @@ abstract class BaseTest { private var autoFailThread: Thread? = null companion object { + fun setLog() { + setLogLevel(Level.TRACE) + } + const val LOOPBACK = "loopback" fun clientConfig(block: Configuration.() -> Unit = {}): Configuration { + val configuration = Configuration() configuration.settingsStore = MemoryStore.type() // don't want to persist anything on disk! configuration.subscriptionPort = 2000 configuration.publicationPort = 2001 + configuration.enableIpc = false + block(configuration) + + setLog() return configuration } @@ -88,16 +97,51 @@ abstract class BaseTest { configuration.subscriptionPort = 2000 configuration.publicationPort = 2001 + configuration.enableIpc = false configuration.maxClientCount = 5 configuration.maxConnectionsPerIpAddress = 5 block(configuration) + setLog() return configuration } + fun setLogLevel(level: Level) { + // assume SLF4J is bound to logback in the current environment + val rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME) as Logger + rootLogger.level = level + + val context = rootLogger.loggerContext + val jc = JoranConfigurator() + context.reset() // override default configuration + + jc.context = context + + + context.getLogger(Server::class.simpleName).level = level + context.getLogger(Client::class.simpleName).level = level + + // we only want error messages + val kryoLogger = LoggerFactory.getLogger("com.esotericsoftware") as Logger + kryoLogger.level = Level.ERROR + + val encoder = PatternLayoutEncoder() + encoder.context = context + encoder.pattern = "%date{HH:mm:ss.SSS} %-5level [%logger{35}] %msg%n" + encoder.start() + val consoleAppender = ConsoleAppender() + consoleAppender.context = context + consoleAppender.encoder = encoder + consoleAppender.start() + rootLogger.addAppender(consoleAppender) +// +// context.getLogger(Server::class.simpleName).trace("TESTING") +// context.getLogger(Client::class.simpleName).trace("TESTING") + } + // wait minimum of 2 minutes before we automatically fail the unit test. - const val AUTO_FAIL_TIMEOUT: Long = 120 + var AUTO_FAIL_TIMEOUT: Long = 120 init { if (OS.javaVersion >= 9) { @@ -133,39 +177,8 @@ abstract class BaseTest { init { println("---- " + this.javaClass.simpleName) - -// setLogLevel(Level.INFO) - setLogLevel(Level.TRACE) -// setLogLevel(Level.DEBUG) } - fun setLogLevel(level: Level) { - // assume SLF4J is bound to logback in the current environment - val rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME) as Logger - val context = rootLogger.loggerContext - val jc = JoranConfigurator() - jc.context = context - context.reset() // override default configuration - - rootLogger.level = level - - // we only want error messages - val kryoLogger = LoggerFactory.getLogger("com.esotericsoftware") as Logger - kryoLogger.level = Level.ERROR - - - val encoder = PatternLayoutEncoder() - encoder.context = context - encoder.pattern = "%date{HH:mm:ss.SSS} %-5level [%logger{35}] %msg%n" - encoder.start() - val consoleAppender = ConsoleAppender() - consoleAppender.context = context - consoleAppender.encoder = encoder - consoleAppender.start() - rootLogger.addAppender(consoleAppender) - } - - fun addEndPoint(endPointConnection: EndPoint<*>) { endPointConnections.add(endPointConnection) synchronized(lock) { latch = CountDownLatch(endPointConnections.size + 1) } @@ -253,11 +266,5 @@ abstract class BaseTest { autoFailThread!!.interrupt() autoFailThread = null } - - // Give sockets a chance to close before starting the next test. - try { - Thread.sleep(1000) - } catch (ignored: InterruptedException) { - } } } diff --git a/test/dorkboxTest/network/ConnectionFilterTest.kt b/test/dorkboxTest/network/ConnectionFilterTest.kt index 36270a1c..391f9a71 100644 --- a/test/dorkboxTest/network/ConnectionFilterTest.kt +++ b/test/dorkboxTest/network/ConnectionFilterTest.kt @@ -186,6 +186,7 @@ class ConnectionFilterTest : BaseTest() { } client.onDisconnect { + println("**************************** CLOSE") stopEndPoints() } @@ -233,6 +234,7 @@ class ConnectionFilterTest : BaseTest() { try { client.connect(LOOPBACK) } catch (e: Exception) { + e.printStackTrace() stopEndPoints() throw e } @@ -241,6 +243,58 @@ class ConnectionFilterTest : BaseTest() { waitForThreads() } + @Test + fun rejectServerIpc() { + val serverConnectSuccess = atomic(false) + val clientConnectSuccess = atomic(false) + + run { + val configuration = serverConfig() { + enableIpc = true + } + + val server: Server = Server(configuration) + addEndPoint(server) + server.bind() + server.filter(IpSubnetFilterRule("1.1.1.1", 32)) // this address will NEVER actually connect. we just use it for testing + + server.onConnect { connection -> + serverConnectSuccess.lazySet(true) + connection.close() + } + } + + run { + val config = clientConfig() { + enableIpc = true + } + + val client: Client = Client(config) + addEndPoint(client) + + client.onConnect { + clientConnectSuccess.value = true + } + + client.onDisconnect { + stopEndPoints() + } + + try { + client.connect(LOOPBACK) + } catch (e: Exception) { + e.printStackTrace() + stopEndPoints() + throw e + } + } + + waitForThreads() + + Assert.assertTrue(serverConnectSuccess.value) + Assert.assertTrue(clientConnectSuccess.value) + } + @Test(expected = ClientException::class) fun rejectClient() { run { diff --git a/test/dorkboxTest/network/DisconnectReconnectTest.kt b/test/dorkboxTest/network/DisconnectReconnectTest.kt index 82ea7dd9..a98cf20e 100644 --- a/test/dorkboxTest/network/DisconnectReconnectTest.kt +++ b/test/dorkboxTest/network/DisconnectReconnectTest.kt @@ -57,13 +57,85 @@ class DisconnectReconnectTest : BaseTest() { } } - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } - waitForThreads() + waitForThreads(0) + + System.err.println("Connection count (after reconnecting) is: " + reconnectCount.value) + Assert.assertEquals(4, reconnectCount.value) + } + + interface CloseIface { + suspend fun close() + } + + class CloseImpl : CloseIface { + override suspend fun close() { + // the connection specific one is called instead + } + + suspend fun close(connection: Connection) { + connection.close() + } + } + + + @Test + fun reconnectRmiClient() { + val CLOSE_ID = 33 + + run { + val config = serverConfig() + config.serialization.registerRmi(CloseIface::class.java) + + val server: Server = Server(config) + addEndPoint(server) + server.bind() + + + server.onConnect { connection -> + connection.logger.error("Disconnecting after 2 seconds.") + delay(2000) + + connection.logger.error("Disconnecting via RMI ....") + val closerObject = connection.getGlobalObject(CLOSE_ID) + closerObject.close() + } + } + + run { + val config = clientConfig() + config.serialization.registerRmi(CloseIface::class.java, CloseImpl::class.java) + + val client: Client = Client(config) + addEndPoint(client) + client.saveGlobalObject(CloseImpl(), CLOSE_ID) + + 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() + } + } + } + + client.connect(LOOPBACK) + } + + + waitForThreads(0) System.err.println("Connection count (after reconnecting) is: " + reconnectCount.value) Assert.assertEquals(4, reconnectCount.value) @@ -116,17 +188,12 @@ class DisconnectReconnectTest : BaseTest() { } } - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } waitForThreads() - - runBlocking { - aeronDriver.close() - } + aeronDriver.close() System.err.println("Connection count (after reconnecting) is: " + reconnectCount.value) Assert.assertEquals(4, reconnectCount.value) @@ -134,6 +201,7 @@ class DisconnectReconnectTest : BaseTest() { @Test fun reconnectWithFallbackClient() { + // this tests IPC with fallback to UDP (because the server has IPC disabled, and the client has it enabled) run { val config = serverConfig() config.enableIpc = false @@ -154,7 +222,6 @@ class DisconnectReconnectTest : BaseTest() { run { val config = clientConfig() config.enableIpc = true - config.enableIpcForLoopback = true val client: Client = Client(config) addEndPoint(client) @@ -178,9 +245,7 @@ class DisconnectReconnectTest : BaseTest() { } } - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } @@ -224,9 +289,7 @@ class DisconnectReconnectTest : BaseTest() { stopEndPoints() } - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } server.close() diff --git a/test/dorkboxTest/network/ListenerTest.kt b/test/dorkboxTest/network/ListenerTest.kt index e05f7b5b..918ab045 100644 --- a/test/dorkboxTest/network/ListenerTest.kt +++ b/test/dorkboxTest/network/ListenerTest.kt @@ -41,7 +41,6 @@ import dorkbox.network.connection.ConnectionParams import dorkbox.util.exceptions.InitializationException import dorkbox.util.exceptions.SecurityException import kotlinx.atomicfu.atomic -import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Test import java.io.IOException @@ -158,9 +157,7 @@ class ListenerTest : BaseTest() { } - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) waitForThreads() diff --git a/test/dorkboxTest/network/MultipleServerTest.kt b/test/dorkboxTest/network/MultipleServerTest.kt index 9083e489..910ce610 100644 --- a/test/dorkboxTest/network/MultipleServerTest.kt +++ b/test/dorkboxTest/network/MultipleServerTest.kt @@ -38,7 +38,6 @@ import dorkbox.network.Client import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkbox.util.exceptions.SecurityException -import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Assert.assertTrue import org.junit.Test @@ -114,9 +113,7 @@ class MultipleServerTest : BaseTest() { connection.send("client_$count") } - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } waitForThreads() @@ -146,6 +143,7 @@ class MultipleServerTest : BaseTest() { configuration.subscriptionPort += offset configuration.publicationPort += offset configuration.aeronDirectory = serverAeronDir + configuration.enableIpc = true val server: Server = Server(configuration) addEndPoint(server) @@ -178,6 +176,7 @@ class MultipleServerTest : BaseTest() { configuration.subscriptionPort += offset configuration.publicationPort += offset configuration.aeronDirectory = clientAeronDir + configuration.enableIpc = true val client: Client = Client(configuration) addEndPoint(client) @@ -189,9 +188,7 @@ class MultipleServerTest : BaseTest() { connection.send("client_$count") } - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } waitForThreads() diff --git a/test/dorkboxTest/network/PingPongTest.kt b/test/dorkboxTest/network/PingPongTest.kt index e452abb3..6b3b4005 100644 --- a/test/dorkboxTest/network/PingPongTest.kt +++ b/test/dorkboxTest/network/PingPongTest.kt @@ -109,9 +109,7 @@ class PingPongTest : BaseTest() { } } - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } diff --git a/test/dorkboxTest/network/PingTest.kt b/test/dorkboxTest/network/PingTest.kt index 5c49f417..7cf0486c 100644 --- a/test/dorkboxTest/network/PingTest.kt +++ b/test/dorkboxTest/network/PingTest.kt @@ -1,65 +1,59 @@ package dorkboxTest.network -import dorkbox.network.Client -import dorkbox.network.Server -import dorkbox.network.connection.Connection -import kotlinx.atomicfu.atomic -import kotlinx.coroutines.runBlocking -import org.junit.Assert import org.junit.Test class PingTest : BaseTest() { @Test fun onServerPing() { - val serverSuccess = atomic(false) - val clientSuccess = atomic(false) - - run { - val configuration = serverConfig() - - val server: Server = Server(configuration) - addEndPoint(server) - server.bind() - - server.onPing { ping -> - serverSuccess.value = true - println("Ping info ${ping.time}") - close() - } - } - - run { - val config = clientConfig() - - val client: Client = Client(config) - addEndPoint(client) - - client.onConnect { - clientSuccess.value = true - - it.ping { - println("received ping back! Val: $time") - } - } - - client.onDisconnect { - stopEndPoints() - } - - runBlocking { - try { - client.connect(LOOPBACK) - } catch (e: Exception) { - stopEndPoints() - throw e - } - } - } - - - waitForThreads() - - Assert.assertTrue(serverSuccess.value) - Assert.assertTrue(clientSuccess.value) +// val serverSuccess = atomic(false) +// val clientSuccess = atomic(false) +// +// run { +// val configuration = serverConfig() +// +// val server: Server = Server(configuration) +// addEndPoint(server) +// server.bind() +// +// server.onPing { ping -> +// serverSuccess.value = true +// println("Ping info ${ping.time}") +// close() +// } +// } +// +// run { +// val config = clientConfig() +// +// val client: Client = Client(config) +// addEndPoint(client) +// +// client.onConnect { +// clientSuccess.value = true +// +// it.ping { +// println("received ping back! Val: $time") +// } +// } +// +// client.onDisconnect { +// stopEndPoints() +// } +// +// runBlocking { +// try { +// client.connect(LOOPBACK) +// } catch (e: Exception) { +// stopEndPoints() +// throw e +// } +// } +// } +// +// +// waitForThreads() +// +// Assert.assertTrue(serverSuccess.value) +// Assert.assertTrue(clientSuccess.value) } } diff --git a/test/dorkboxTest/network/SerializationValidationTest.kt b/test/dorkboxTest/network/SerializationValidationTest.kt index a79aebae..2f701272 100644 --- a/test/dorkboxTest/network/SerializationValidationTest.kt +++ b/test/dorkboxTest/network/SerializationValidationTest.kt @@ -20,7 +20,6 @@ import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkbox.network.serialization.KryoExtra import dorkbox.network.serialization.Serialization -import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Test @@ -51,10 +50,7 @@ class SerializationValidationTest : BaseTest() { connection.send(FinishedCommand()) } - - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } waitForThreads() @@ -113,10 +109,7 @@ class SerializationValidationTest : BaseTest() { } } - - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } waitForThreads() @@ -160,10 +153,7 @@ class SerializationValidationTest : BaseTest() { } } - - runBlocking { - client.connect(LOOPBACK) - } + client.connect(LOOPBACK) } waitForThreads() diff --git a/test/dorkboxTest/network/StorageTest.kt b/test/dorkboxTest/network/StorageTest.kt index 22a39172..c076d662 100644 --- a/test/dorkboxTest/network/StorageTest.kt +++ b/test/dorkboxTest/network/StorageTest.kt @@ -51,8 +51,7 @@ class StorageTest : BaseTest() { } val client = Client(config) - - client.connect("localhost") + client.connect(LOOPBACK) Assert.assertTrue(server.storage.getSalt().contentEquals(client.storage.getSalt())) diff --git a/test/dorkboxTest/network/memoryTest/MemoryTest.kt b/test/dorkboxTest/network/memoryTest/MemoryTest.kt index 6404d123..64a243ef 100644 --- a/test/dorkboxTest/network/memoryTest/MemoryTest.kt +++ b/test/dorkboxTest/network/memoryTest/MemoryTest.kt @@ -70,7 +70,7 @@ class MemoryTest : BaseTest() { } } - client.connect() + client.connectIpc() } Thread.sleep(Long.MAX_VALUE) diff --git a/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt b/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt index d63493e8..8b1c4040 100644 --- a/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt +++ b/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt @@ -21,7 +21,6 @@ import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkbox.network.serialization.Serialization import dorkboxTest.network.BaseTest -import kotlinx.coroutines.runBlocking import org.junit.Test import java.util.concurrent.atomic.AtomicInteger @@ -31,17 +30,13 @@ class RmiDelayedInvocationTest : BaseTest() { @Test fun rmiNetwork() { - runBlocking { - rmi { configuration -> - configuration.enableIpcForLoopback = false - } - } + rmi() } @Test fun rmiIpc() { - runBlocking { - rmi() + rmi { + enableIpc = true } } @@ -53,7 +48,7 @@ class RmiDelayedInvocationTest : BaseTest() { * In this test the server has two objects in an object space. The client * uses the first remote object to get the second remote object. */ - suspend fun rmi(config: (Configuration) -> Unit = {}) { + fun rmi(config: Configuration.() -> Unit = {}) { run { val configuration = serverConfig() config(configuration) diff --git a/test/dorkboxTest/network/rmi/RmiNestedTest.kt b/test/dorkboxTest/network/rmi/RmiNestedTest.kt index 3bf0ee33..487f927b 100644 --- a/test/dorkboxTest/network/rmi/RmiNestedTest.kt +++ b/test/dorkboxTest/network/rmi/RmiNestedTest.kt @@ -19,16 +19,13 @@ import dorkbox.network.Client import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkboxTest.network.BaseTest -import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Test import java.util.concurrent.atomic.AtomicInteger -@Suppress("unused", "RedundantSuspendModifier") class RmiNestedTest : BaseTest() { - companion object { private val idCounter = AtomicInteger() } @@ -118,9 +115,7 @@ class RmiNestedTest : BaseTest() { } } - runBlocking { - client.connect(LOOPBACK, 5000) - } + client.connect(LOOPBACK) } waitForThreads() } @@ -185,9 +180,7 @@ class RmiNestedTest : BaseTest() { } } - runBlocking { - client.connect(LOOPBACK, 5000) - } + client.connect(LOOPBACK) } waitForThreads() } @@ -245,9 +238,7 @@ class RmiNestedTest : BaseTest() { } } - runBlocking { - client.connect(LOOPBACK, 5000) - } + client.connect(LOOPBACK) } waitForThreads() } @@ -306,9 +297,7 @@ class RmiNestedTest : BaseTest() { } } - runBlocking { - client.connect(LOOPBACK, 5000) - } + client.connect(LOOPBACK) } waitForThreads() } diff --git a/test/dorkboxTest/network/rmi/RmiSimpleTest.kt b/test/dorkboxTest/network/rmi/RmiSimpleTest.kt index b36de062..b832d5f8 100644 --- a/test/dorkboxTest/network/rmi/RmiSimpleTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSimpleTest.kt @@ -52,72 +52,60 @@ class RmiSimpleTest : BaseTest() { @Test fun rmiIPv4NetworkGlobal() { - rmiGlobal(isIpv4 = true, isIpv6 = false) { configuration -> - configuration.enableIpcForLoopback = false - } + rmiGlobal(isIpv4 = true, isIpv6 = false) } @Test fun rmiIPv6NetworkGlobal() { - rmiGlobal(isIpv4 = true, isIpv6 = false) { configuration -> - configuration.enableIpcForLoopback = false - } + rmiGlobal(isIpv4 = true, isIpv6 = false) } @Test fun rmiBothIPv4ConnectNetworkGlobal() { - rmiGlobal(isIpv4 = true, isIpv6 = true) { configuration -> - configuration.enableIpcForLoopback = false - } + rmiGlobal(isIpv4 = true, isIpv6 = true) } @Test fun rmiBothIPv6ConnectNetworkGlobal() { - rmiGlobal(isIpv4 = true, isIpv6 = true, runIpv4Connect = true) { configuration -> - configuration.enableIpcForLoopback = false - } + rmiGlobal(isIpv4 = true, isIpv6 = true, runIpv4Connect = true) } @Test fun rmiIPv4NetworkConnection() { - rmi(isIpv4 = true, isIpv6 = false) { configuration -> - configuration.enableIpcForLoopback = false - } + rmi(isIpv4 = true, isIpv6 = false) } @Test fun rmiIPv6NetworkConnection() { - rmi(isIpv4 = false, isIpv6 = true) { configuration -> - configuration.enableIpcForLoopback = false - } + rmi(isIpv4 = false, isIpv6 = true) } @Test fun rmiBothIPv4ConnectNetworkConnection() { - rmi(isIpv4 = true, isIpv6 = true) { configuration -> - configuration.enableIpcForLoopback = false - } + rmi(isIpv4 = true, isIpv6 = true) } @Test fun rmiBothIPv6ConnectNetworkConnection() { - rmi(isIpv4 = true, isIpv6 = true, runIpv4Connect = true) { configuration -> - configuration.enableIpcForLoopback = false - } + rmi(isIpv4 = true, isIpv6 = true, runIpv4Connect = true) } @Test fun rmiIpcNetworkGlobal() { - rmiGlobal() + rmiGlobal() { + enableIpc = true + } } @Test fun rmiIpcNetworkConnection() { - rmi() + rmi() { + enableIpc = true + } } - fun rmi(isIpv4: Boolean = false, isIpv6: Boolean = false, runIpv4Connect: Boolean = true, config: (Configuration) -> Unit = {}) { + fun rmi(isIpv4: Boolean = false, isIpv6: Boolean = false, runIpv4Connect: Boolean = true, config: Configuration.() -> Unit = {}) { run { val configuration = serverConfig() configuration.enableIPv4 = isIpv4 @@ -176,21 +164,19 @@ class RmiSimpleTest : BaseTest() { stopEndPoints(2000) } - runBlocking { - when { - isIpv4 && isIpv6 && runIpv4Connect -> client.connect(IPv4.LOCALHOST) - isIpv4 && isIpv6 && !runIpv4Connect -> client.connect(IPv6.LOCALHOST) - isIpv4 -> client.connect(IPv4.LOCALHOST) - isIpv6 -> client.connect(IPv6.LOCALHOST) - else -> client.connect() - } + when { + isIpv4 && isIpv6 && runIpv4Connect -> client.connect(IPv4.LOCALHOST) + isIpv4 && isIpv6 && !runIpv4Connect -> client.connect(IPv6.LOCALHOST) + isIpv4 -> client.connect(IPv4.LOCALHOST) + isIpv6 -> client.connect(IPv6.LOCALHOST) + else -> client.connect() } } waitForThreads() } - fun rmiGlobal(isIpv4: Boolean = false, isIpv6: Boolean = false, runIpv4Connect: Boolean = true, config: (Configuration) -> Unit = {}) { + fun rmiGlobal(isIpv4: Boolean = false, isIpv6: Boolean = false, runIpv4Connect: Boolean = true, config: Configuration.() -> Unit = {}) { run { val configuration = serverConfig() configuration.enableIPv4 = isIpv4 @@ -244,18 +230,18 @@ class RmiSimpleTest : BaseTest() { stopEndPoints(2000) } + when { + isIpv4 && isIpv6 && runIpv4Connect -> client.connect(IPv4.LOCALHOST) + isIpv4 && isIpv6 && !runIpv4Connect -> client.connect(IPv6.LOCALHOST) + isIpv4 -> client.connect(IPv4.LOCALHOST) + isIpv6 -> client.connect(IPv6.LOCALHOST) + else -> client.connect() + } + + client.logger.error("Starting test for: Client -> Server") + + // this creates a GLOBAL object on the server (instead of a connection specific object) runBlocking { - when { - isIpv4 && isIpv6 && runIpv4Connect -> client.connect(IPv4.LOCALHOST) - isIpv4 && isIpv6 && !runIpv4Connect -> client.connect(IPv6.LOCALHOST) - isIpv4 -> client.connect(IPv4.LOCALHOST) - isIpv6 -> client.connect(IPv6.LOCALHOST) - else -> client.connect() - } - - client.logger.error("Starting test for: Client -> Server") - - // this creates a GLOBAL object on the server (instead of a connection specific object) client.createObject(44) { client.logger.error("Running test for: Client -> Server") RmiCommonTest.runTests(client.connection, this, 44) diff --git a/test/dorkboxTest/network/rmi/RmiSpamAsyncTest.kt b/test/dorkboxTest/network/rmi/RmiSpamAsyncTest.kt index da8902f6..dc4df2f5 100644 --- a/test/dorkboxTest/network/rmi/RmiSpamAsyncTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSpamAsyncTest.kt @@ -22,7 +22,6 @@ import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkbox.network.rmi.RemoteObject import dorkboxTest.network.BaseTest -import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Test import java.util.concurrent.atomic.AtomicLong @@ -39,17 +38,13 @@ class RmiSpamAsyncTest : BaseTest() { @Test fun rmiNetworkAsync() { - runBlocking { - rmi { configuration -> - configuration.enableIpcForLoopback = false - } - } + rmi() } @Test fun rmiIpcAsync() { - runBlocking { - rmi() + rmi() { + enableIpc = true } } @@ -57,7 +52,7 @@ class RmiSpamAsyncTest : BaseTest() { * In this test the server has two objects in an object space. The client * uses the first remote object to get the second remote object. */ - suspend fun rmi(config: (Configuration) -> Unit = {}) { + fun rmi(config: Configuration.() -> Unit = {}) { val server: Server val mod = 100_000L diff --git a/test/dorkboxTest/network/rmi/RmiSpamSyncSuspendingTest.kt b/test/dorkboxTest/network/rmi/RmiSpamSyncSuspendingTest.kt index 1ff20b4a..6a10fb03 100644 --- a/test/dorkboxTest/network/rmi/RmiSpamSyncSuspendingTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSpamSyncSuspendingTest.kt @@ -21,7 +21,6 @@ import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkbox.network.rmi.RemoteObject import dorkboxTest.network.BaseTest -import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Test import java.util.concurrent.atomic.AtomicLong @@ -38,18 +37,14 @@ class RmiSpamSyncSuspendingTest : BaseTest() { @Test fun rmiNetwork() { - runBlocking { - rmi { configuration -> - configuration.enableIpcForLoopback = false - } + rmi { + enableIpc = false } } @Test fun rmiIpc() { - runBlocking { - rmi() - } + rmi() } @@ -57,7 +52,7 @@ class RmiSpamSyncSuspendingTest : BaseTest() { * In this test the server has two objects in an object space. The client * uses the first remote object to get the second remote object. */ - suspend fun rmi(config: (Configuration) -> Unit = {}) { + fun rmi(config: Configuration.() -> Unit = {}) { val server: Server val mod = 400L diff --git a/test/dorkboxTest/network/rmi/RmiSpamSyncTest.kt b/test/dorkboxTest/network/rmi/RmiSpamSyncTest.kt index 8450bb5e..2b658bf5 100644 --- a/test/dorkboxTest/network/rmi/RmiSpamSyncTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSpamSyncTest.kt @@ -22,7 +22,6 @@ import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkbox.network.rmi.RemoteObject import dorkboxTest.network.BaseTest -import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Test import java.util.concurrent.atomic.AtomicLong @@ -39,17 +38,13 @@ class RmiSpamSyncTest : BaseTest() { @Test fun rmiNetwork() { - runBlocking { - rmi { configuration -> - configuration.enableIpcForLoopback = false - } - } + rmi() } @Test fun rmiIpc() { - runBlocking { - rmi() + rmi() { + enableIpc = true } } @@ -58,7 +53,7 @@ class RmiSpamSyncTest : BaseTest() { * In this test the server has two objects in an object space. The client * uses the first remote object to get the second remote object. */ - suspend fun rmi(config: (Configuration) -> Unit = {}) { + fun rmi(config: Configuration.() -> Unit = {}) { val server: Server val mod = 400L diff --git a/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt b/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt index 6570f991..1bef4fec 100644 --- a/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt +++ b/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt @@ -102,9 +102,9 @@ object TestClient { connection.close() } + client.connect(BaseTest.LOOPBACK) runBlocking { - client.connect(BaseTest.LOOPBACK) client.waitForClose() } }