diff --git a/test/dorkboxTest/network/DisconnectReconnectTest.kt b/test/dorkboxTest/network/DisconnectReconnectTest.kt index 39d85e1c..8ed4047f 100644 --- a/test/dorkboxTest/network/DisconnectReconnectTest.kt +++ b/test/dorkboxTest/network/DisconnectReconnectTest.kt @@ -143,7 +143,7 @@ class DisconnectReconnectTest : BaseTest() { run { val config = serverConfig() - config.serialization.registerRmi(CloseIface::class.java) + config.serialization.rmi.register(CloseIface::class.java) val server: Server = Server(config) addEndPoint(server) @@ -155,18 +155,21 @@ class DisconnectReconnectTest : BaseTest() { delay(2000) logger.error("Disconnecting via RMI ....") - val closerObject = getGlobalObject(CLOSE_ID) + val closerObject = rmi.getGlobal(CLOSE_ID) closerObject.close() } } run { val config = clientConfig() - config.serialization.registerRmi(CloseIface::class.java, CloseImpl::class.java) + config.serialization.rmi.register(CloseIface::class.java, CloseImpl::class.java) val client: Client = Client(config) addEndPoint(client) - client.saveGlobalObject(CloseImpl(), CLOSE_ID) + + client.onConnect { + rmi.save(CloseImpl(), CLOSE_ID) + } client.onDisconnect { logger.error("Disconnected!") diff --git a/test/dorkboxTest/network/PingPongTest.kt b/test/dorkboxTest/network/PingPongTest.kt index 7c77e017..cdcddc50 100644 --- a/test/dorkboxTest/network/PingPongTest.kt +++ b/test/dorkboxTest/network/PingPongTest.kt @@ -120,7 +120,7 @@ class PingPongTest : BaseTest() { } } - private fun register(manager: Serialization) { + private fun register(manager: Serialization) { manager.register(Data::class.java) } diff --git a/test/dorkboxTest/network/SerializationValidationTest.kt b/test/dorkboxTest/network/SerializationValidationTest.kt index 13c82c3f..76abed77 100644 --- a/test/dorkboxTest/network/SerializationValidationTest.kt +++ b/test/dorkboxTest/network/SerializationValidationTest.kt @@ -60,7 +60,7 @@ class SerializationValidationTest : BaseTest() { fun checkTakeKryo() { val serialization = serverConfig().serialization - val kryos = mutableListOf() + val kryos = mutableListOf>() for (i in 0 until 17) { kryos.add(serialization.takeKryo()) } @@ -75,12 +75,14 @@ class SerializationValidationTest : BaseTest() { fun checkOutOfOrder() { run { val configuration = serverConfig() - configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) configuration.serialization.register(TestObjectImpl::class.java) // this is again, on purpose to verify registration order! val server = Server(configuration) addEndPoint(server) + server.rmiGlobal.save(TestObjectImpl(), 1) + server.onMessage { message -> stopEndPoints() } @@ -96,7 +98,7 @@ class SerializationValidationTest : BaseTest() { client.onConnect { logger.error("Connected") - createObject { + rmi.getGlobal(1).apply { logger.error("Starting test") setValue(43.21f) @@ -119,12 +121,14 @@ class SerializationValidationTest : BaseTest() { fun checkOutOfOrder2() { run { val configuration = serverConfig() - configuration.serialization.registerRmi(TestObject::class.java) - configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) val server = Server(configuration) addEndPoint(server) + server.rmiGlobal.save(TestObjectImpl(), 1) + server.onMessage { message -> stopEndPoints() } @@ -140,7 +144,7 @@ class SerializationValidationTest : BaseTest() { client.onConnect { logger.error("Connected") - createObject { + rmi.getGlobal(1).apply { logger.error("Starting test") setValue(43.21f) @@ -159,7 +163,7 @@ class SerializationValidationTest : BaseTest() { waitForThreads() } - private fun register(serialization: Serialization) { + private fun register(serialization: Serialization) { serialization.register(Command1::class.java) serialization.register(Command2::class.java) serialization.register(Command3::class.java) diff --git a/test/dorkboxTest/network/memoryTest/MemoryTest.kt b/test/dorkboxTest/network/memoryTest/MemoryTest.kt index 851b6f02..e127ec25 100644 --- a/test/dorkboxTest/network/memoryTest/MemoryTest.kt +++ b/test/dorkboxTest/network/memoryTest/MemoryTest.kt @@ -31,8 +31,6 @@ import java.util.concurrent.atomic.AtomicLong class MemoryTest : BaseTest() { private val counter = AtomicLong(0) - private val RMI_ID = 12251 - init { // the logger cannot keep-up if it's on trace setLogLevel(Level.DEBUG) @@ -41,12 +39,14 @@ class MemoryTest : BaseTest() { @Test fun runForeverIpcAsyncNormal() { runBlocking { + val RMI_ID = 12251 + run { val configuration = serverConfig() - configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) val server = Server(configuration) - server.saveGlobalObject(TestObjectImpl(counter), RMI_ID) + server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID) server.bind() } @@ -54,7 +54,7 @@ class MemoryTest : BaseTest() { run { val client = Client(clientConfig()) client.onConnect { - val remoteObject = getGlobalObject(RMI_ID) + val remoteObject = rmi.getGlobal(RMI_ID) val obj = remoteObject as RemoteObject obj.async = true @@ -79,13 +79,15 @@ class MemoryTest : BaseTest() { @Test fun runForeverIpcAsyncSuspend() { + val RMI_ID = 12251 + runBlocking { run { val configuration = serverConfig() - configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) val server = Server(configuration) - server.saveGlobalObject(TestObjectImpl(counter), RMI_ID) + server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID) server.bind() } @@ -93,7 +95,7 @@ class MemoryTest : BaseTest() { run { val client = Client(clientConfig()) client.onConnect { - val remoteObject = getGlobalObject(RMI_ID) + val remoteObject = rmi.getGlobal(RMI_ID) val obj = remoteObject as RemoteObject obj.async = true @@ -155,23 +157,23 @@ class MemoryTest : BaseTest() { val serialization = serverConfig().serialization // 17 to force a pool size change - var kryo1: KryoExtra - var kryo2: KryoExtra - var kryo3: KryoExtra - var kryo4: KryoExtra - var kryo5: KryoExtra - var kryo6: KryoExtra - var kryo7: KryoExtra - var kryo8: KryoExtra - var kryo9: KryoExtra - var kryo10: KryoExtra - var kryo11: KryoExtra - var kryo12: KryoExtra - var kryo13: KryoExtra - var kryo14: KryoExtra - var kryo15: KryoExtra - var kryo16: KryoExtra - var kryo17: KryoExtra + var kryo1: KryoExtra + var kryo2: KryoExtra + var kryo3: KryoExtra + var kryo4: KryoExtra + var kryo5: KryoExtra + var kryo6: KryoExtra + var kryo7: KryoExtra + var kryo8: KryoExtra + var kryo9: KryoExtra + var kryo10: KryoExtra + var kryo11: KryoExtra + var kryo12: KryoExtra + var kryo13: KryoExtra + var kryo14: KryoExtra + var kryo15: KryoExtra + var kryo16: KryoExtra + var kryo17: KryoExtra while (true) { kryo1 = serialization.takeKryo() diff --git a/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt b/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt index 7c231f02..6d4ee74e 100644 --- a/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt +++ b/test/dorkboxTest/network/rmi/RmiDelayedInvocationTest.kt @@ -40,8 +40,8 @@ class RmiDelayedInvocationTest : BaseTest() { } } - fun register(serialization: Serialization) { - serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + fun register(serialization: Serialization) { + serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) } /** @@ -57,7 +57,7 @@ class RmiDelayedInvocationTest : BaseTest() { val server = Server(configuration) addEndPoint(server) - server.saveGlobalObject(TestObjectImpl(iterateLock), OBJ_ID) + server.rmiGlobal.save(TestObjectImpl(iterateLock), OBJ_ID) server.bind() } @@ -69,7 +69,7 @@ class RmiDelayedInvocationTest : BaseTest() { addEndPoint(client) client.onConnect { - val remoteObject = getGlobalObject(OBJ_ID) + val remoteObject = rmi.getGlobal(OBJ_ID) val totalRuns = 100 var abort = false diff --git a/test/dorkboxTest/network/rmi/RmiNestedTest.kt b/test/dorkboxTest/network/rmi/RmiNestedTest.kt index 4af4e350..bce41996 100644 --- a/test/dorkboxTest/network/rmi/RmiNestedTest.kt +++ b/test/dorkboxTest/network/rmi/RmiNestedTest.kt @@ -59,12 +59,14 @@ class RmiNestedTest : BaseTest() { run { val configuration = serverConfig() - configuration.serialization.registerRmi(TestObject::class.java, TestObjectAnnotImpl::class.java) - configuration.serialization.registerRmi(OtherObject::class.java, OtherObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectAnnotImpl::class.java) + configuration.serialization.rmi.register(OtherObject::class.java, OtherObjectImpl::class.java) val server = Server(configuration) addEndPoint(server) + server.rmiGlobal.save(TestObjectImpl(), 1) + server.onMessage { message -> // The test is complete when the client sends the OtherObject instance. // this 'object' is the REAL object, not a proxy, because this object is created within this connection. @@ -87,7 +89,7 @@ class RmiNestedTest : BaseTest() { client.onConnect { logger.error("Connected") - createObject { + rmi.getGlobal(1).apply { logger.error("Starting test") setValue(43.21f) @@ -124,12 +126,14 @@ class RmiNestedTest : BaseTest() { fun doubleRmi() { run { val configuration = serverConfig() - configuration.serialization.registerRmi(TestObject::class.java, TestObjectAnnotImpl::class.java) - configuration.serialization.registerRmi(OtherObject::class.java, OtherObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectAnnotImpl::class.java) + configuration.serialization.rmi.register(OtherObject::class.java, OtherObjectImpl::class.java) val server = Server(configuration) addEndPoint(server) + server.rmiGlobal.save(TestObjectImpl(), 1) + server.onMessage { message -> // The test is complete when the client sends the OtherObject instance. // this 'object' is the REAL object, not a proxy, because this object is created within this connection. @@ -152,7 +156,7 @@ class RmiNestedTest : BaseTest() { client.onConnect { logger.error("Connected") - createObject { + rmi.getGlobal(1).apply { logger.error("Starting test") setValue(43.21f) @@ -189,12 +193,14 @@ class RmiNestedTest : BaseTest() { fun singleRmi() { run { val configuration = serverConfig() - configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) configuration.serialization.register(OtherObjectImpl::class.java) val server = Server(configuration) addEndPoint(server) + server.rmiGlobal.save(TestObjectImpl(), 1) + server.onMessage { message -> // The test is complete when the client sends the OtherObject instance. // this 'object' is the REAL object @@ -217,7 +223,8 @@ class RmiNestedTest : BaseTest() { client.onConnect { logger.error("Connected") - createObject { + + rmi.getGlobal(1).apply { logger.error("Starting test") setOtherValue(43.21f) @@ -247,7 +254,7 @@ class RmiNestedTest : BaseTest() { fun singleReverseRmi() { run { val configuration = serverConfig() - configuration.serialization.registerRmi(TestObject::class.java, null) + configuration.serialization.rmi.register(TestObject::class.java, null) configuration.serialization.register(OtherObjectImpl::class.java) val server = Server(configuration) @@ -255,7 +262,8 @@ class RmiNestedTest : BaseTest() { server.onConnect { logger.error("Connected") - createObject { + + rmi.get(1).apply { logger.error("Starting test") setOtherValue(43.21f) @@ -282,11 +290,16 @@ class RmiNestedTest : BaseTest() { run { val configuration = clientConfig() - configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) val client = Client(configuration) addEndPoint(client) + client.onConnect { + rmi.save(TestObjectImpl(), 1) + } + + client.onMessage { message -> // The test is complete when the client sends the OtherObject instance. // this 'object' is the REAL object @@ -347,6 +360,7 @@ class RmiNestedTest : BaseTest() { throw RuntimeException("Whoops!") } + @Suppress("UNUSED_PARAMETER") fun other(connection: Connection): Float { return aFloat } @@ -388,6 +402,7 @@ class RmiNestedTest : BaseTest() { throw RuntimeException("Whoops!") } + @Suppress("UNUSED_PARAMETER") fun other(connection: Connection): Float { return aFloat } diff --git a/test/dorkboxTest/network/rmi/RmiSimpleActionsTest.kt b/test/dorkboxTest/network/rmi/RmiSimpleActionsTest.kt new file mode 100644 index 00000000..3a3339e7 --- /dev/null +++ b/test/dorkboxTest/network/rmi/RmiSimpleActionsTest.kt @@ -0,0 +1,288 @@ +/* + * Copyright 2016 dorkbox, llc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (c) 2008, Nathan Sweet + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the distribution. + * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package dorkboxTest.network.rmi + +import dorkbox.netUtil.IPv4 +import dorkbox.netUtil.IPv6 +import dorkbox.network.Client +import dorkbox.network.Configuration +import dorkbox.network.Server +import dorkbox.network.connection.Connection +import dorkbox.network.rmi.RemoteObject +import dorkboxTest.network.BaseTest +import dorkboxTest.network.rmi.cows.MessageWithTestCow +import dorkboxTest.network.rmi.cows.TestCow +import dorkboxTest.network.rmi.cows.TestCowImpl +import kotlinx.coroutines.runBlocking +import org.junit.Assert +import org.junit.Test + +class RmiSimpleActionsTest : BaseTest() { + + @Test + fun rmiIPv4NetworkGlobalDelete() { + rmiConnectionDelete(isIpv4 = true, isIpv6 = false) + } + + + + + + @Test + fun testGlobalDeleteServer() { + val OBJ_ID = 3423 + + val configuration = serverConfig() + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + configuration.serialization.register(MessageWithTestCow::class.java) + configuration.serialization.register(UnsupportedOperationException::class.java) + + // for Client -> Server RMI + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + + val server = Server(configuration) + addEndPoint(server) + + val testCowImpl = TestCowImpl(OBJ_ID) + server.rmiGlobal.save(testCowImpl, OBJ_ID) +// Assert.assertNotNull(server.rmi.get(OBJ_ID)) + + Assert.assertTrue(server.rmiGlobal.delete(testCowImpl)) + Assert.assertFalse(server.rmiGlobal.delete(testCowImpl)) + Assert.assertFalse(server.rmiGlobal.delete(OBJ_ID)) +// Assert.assertNull(server.rmi.get(OBJ_ID)) + + val newId = server.rmiGlobal.save(testCowImpl) +// Assert.assertNotNull(server.rmi.get(newId)) + + Assert.assertTrue(server.rmiGlobal.delete(newId)) + Assert.assertFalse(server.rmiGlobal.delete(newId)) + Assert.assertFalse(server.rmiGlobal.delete(testCowImpl)) +// Assert.assertNull(server.rmi.get(newId)) + } + + @Test + fun testGlobalDelete() { + val SERVER_ID = 1123 + val CLIENT_ID = 3423 + + val server = run { + val configuration = serverConfig() + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + + val server = Server(configuration) + addEndPoint(server) + server.bind() + + server + } + + + val client = run { + val configuration = clientConfig() + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + + val client = Client(configuration) + addEndPoint(client) + client.connect(LOOPBACK) + + client + } + + val serverCow = TestCowImpl(SERVER_ID) + server.rmiGlobal.save(serverCow, SERVER_ID) + +// val clientCow = TestCowImpl(CLIENT_ID) +// client.rmi.save(serverCow, CLIENT_ID) + + val get1 = client.connection.rmi.get(CLIENT_ID) + get1 as RemoteObject + get1.enableEquals(true) + + Assert.assertNotNull(get1) + Assert.assertTrue(get1 == serverCow) + +// Assert.assertTrue(client.rmi.delete(clientCow)) +// Assert.assertFalse(client.rmi.delete(clientCow)) +// Assert.assertFalse(client.rmi.delete(CLIENT_ID)) +// Assert.assertNull(client.rmi.get(CLIENT_ID)) +// +// val newId = client.rmi.save(clientCow) +// Assert.assertNotNull(client.rmi.get(CLIENT_ID)) +// +// Assert.assertTrue(client.rmi.delete(CLIENT_ID)) +// Assert.assertFalse(client.rmi.delete(CLIENT_ID)) +// Assert.assertFalse(client.rmi.delete(clientCow)) +// Assert.assertNull(client.rmi.get(CLIENT_ID)) + + runBlocking { + stopEndPoints() + waitForThreads() + } + } + + @Test + fun testGlobalDelete3() { + val OBJ_ID = 3423 + + val configuration = serverConfig() + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + configuration.serialization.register(MessageWithTestCow::class.java) + configuration.serialization.register(UnsupportedOperationException::class.java) + + // for Client -> Server RMI + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + + val server = Server(configuration) + addEndPoint(server) + + val testCowImpl = TestCowImpl(OBJ_ID) + server.rmiGlobal.save(testCowImpl, OBJ_ID) + Assert.assertTrue(server.rmiGlobal.delete(OBJ_ID)) + Assert.assertFalse(server.rmiGlobal.delete(testCowImpl)) + } + + @Test + fun testGlobalDelete4() { + val OBJ_ID = 3423 + + val configuration = serverConfig() + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + configuration.serialization.register(MessageWithTestCow::class.java) + configuration.serialization.register(UnsupportedOperationException::class.java) + + // for Client -> Server RMI + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + + val server = Server(configuration) + addEndPoint(server) + + val testCowImpl = TestCowImpl(OBJ_ID) + server.rmiGlobal.save(testCowImpl, OBJ_ID) + Assert.assertTrue(server.rmiGlobal.delete(OBJ_ID)) + Assert.assertFalse(server.rmiGlobal.delete(testCowImpl)) + } + + + + fun rmiConnectionDelete(isIpv4: Boolean = false, isIpv6: Boolean = false, runIpv4Connect: Boolean = true, config: Configuration.() -> Unit = {}) { + val OBJ_ID = 3423 + + run { + val configuration = serverConfig() + configuration.enableIPv4 = isIpv4 + configuration.enableIPv6 = isIpv6 + config(configuration) + + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + configuration.serialization.register(MessageWithTestCow::class.java) + configuration.serialization.register(UnsupportedOperationException::class.java) + + // for Client -> Server RMI + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + + val server = Server(configuration) + addEndPoint(server) + server.bind() + + server.rmiGlobal.save(TestCowImpl(44), 44) + + server.onMessage { m -> + server.logger.error("Received finish signal for test for: Client -> Server") + + val `object` = m.testCow + val id = `object`.id() + + Assert.assertEquals(44, id.toLong()) + + server.logger.error("Finished test for: Client -> Server") + + // normally this is in the 'connected', but we do it here, so that it's more linear and easier to debug + server.logger.error("Running test for: Server -> Client") + RmiCommonTest.runTests(this@onMessage, rmi.getGlobal(4), 4) + server.logger.error("Done with test for: Server -> Client") + } + } + + run { + val configuration = clientConfig() + config(configuration) +// configuration.serialization.registerRmi(TestCow::class.java, TestCowImpl::class.java) + + val client = Client(configuration) + addEndPoint(client) + + client.onConnect { + rmi.save(TestCowImpl(4), 4) + } + + + client.onMessage { m -> + client.logger.error("Received finish signal for test for: Client -> Server") + val `object` = m.testCow + val id = `object`.id() + Assert.assertEquals(4, id.toLong()) + client.logger.error("Finished test for: Client -> Server") + 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 { +// client.rmi.get() + + +// client.createObject(44) { +// client.deleteObject(this) + +// client.logger.error("Running test for: Client -> Server") +// RmiCommonTest.runTests(client.connection, this, 44) +// client.logger.error("Done with test for: Client -> Server") +// } + } + } + + waitForThreads() + } +} diff --git a/test/dorkboxTest/network/rmi/RmiSimpleTest.kt b/test/dorkboxTest/network/rmi/RmiSimpleTest.kt index 4b0b3776..192cf20c 100644 --- a/test/dorkboxTest/network/rmi/RmiSimpleTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSimpleTest.kt @@ -70,6 +70,18 @@ class RmiSimpleTest : BaseTest() { rmiGlobal(isIpv4 = true, isIpv6 = true, runIpv4Connect = true) } + @Test + fun rmiIpcNetworkGlobal() { + rmiGlobal { + enableIpc = true + } + } + + + + + + @Test fun rmiIPv4NetworkConnection() { rmi(isIpv4 = true, isIpv6 = false) @@ -92,19 +104,100 @@ class RmiSimpleTest : BaseTest() { } @Test - fun rmiIpcNetworkGlobal() { - rmiGlobal() { + fun rmiIpcNetworkConnection() { + rmi { enableIpc = true } } - @Test - fun rmiIpcNetworkConnection() { - rmi() { - enableIpc = true + private fun doConnect(isIpv4: Boolean, isIpv6: Boolean, runIpv4Connect: Boolean, client: Client) { + 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() } } + + // GLOBAL rmi stuff cannot CREATE or DELETE (only save/get) + private fun rmiGlobal(isIpv4: Boolean = false, isIpv6: Boolean = false, runIpv4Connect: Boolean = true, config: Configuration.() -> Unit = {}) { + run { + val configuration = serverConfig() + configuration.enableIPv4 = isIpv4 + configuration.enableIPv6 = isIpv6 + config(configuration) + + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + configuration.serialization.register(MessageWithTestCow::class.java) + configuration.serialization.register(UnsupportedOperationException::class.java) + + // for Client -> Server RMI + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) + + val server = Server(configuration) + addEndPoint(server) + server.bind() + + server.rmiGlobal.save(TestCowImpl(44), 44) + + server.onMessage { m -> + server.logger.error("Received finish signal for test for: Client -> Server") + + val `object` = m.testCow + val id = `object`.id() + + Assert.assertEquals(44, id.toLong()) + + server.logger.error("Finished test for: Client -> Server") + + // normally this is in the 'connected', but we do it here, so that it's more linear and easier to debug + + server.logger.error("Running test for: Server -> Client") + RmiCommonTest.runTests(this@onMessage, rmi.get(4), 4) + server.logger.error("Done with test for: Server -> Client") + } + } + + run { + val configuration = clientConfig() + config(configuration) + // configuration.serialization.registerRmi(TestCow::class.java, TestCowImpl::class.java) + + val client = Client(configuration) + addEndPoint(client) + + client.onConnect { + rmi.save(TestCowImpl(4), 4) + } + + client.onMessage { m -> + client.logger.error("Received finish signal for test for: Client -> Server") + val `object` = m.testCow + val id = `object`.id() + Assert.assertEquals(4, id.toLong()) + client.logger.error("Finished test for: Client -> Server") + stopEndPoints(2000) + } + + doConnect(isIpv4, isIpv6, runIpv4Connect, client) + + client.logger.error("Starting test for: Client -> Server") + + // this creates a GLOBAL object on the server (instead of a connection specific object) + runBlocking { + client.logger.error("Running test for: Client -> Server") + RmiCommonTest.runTests(client.connection, client.connection.rmi.getGlobal(44), 44) + client.logger.error("Done with test for: Client -> Server") + } + } + + waitForThreads() + } + + + fun rmi(isIpv4: Boolean = false, isIpv6: Boolean = false, runIpv4Connect: Boolean = true, config: Configuration.() -> Unit = {}) { run { val configuration = serverConfig() @@ -112,7 +205,7 @@ class RmiSimpleTest : BaseTest() { configuration.enableIPv6 = isIpv6 config(configuration) - configuration.serialization.registerRmi(TestCow::class.java, TestCowImpl::class.java) + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) configuration.serialization.register(MessageWithTestCow::class.java) configuration.serialization.register(UnsupportedOperationException::class.java) @@ -131,7 +224,7 @@ class RmiSimpleTest : BaseTest() { server.logger.error("Starting test for: Server -> Client") // NOTE: THIS IS BI-DIRECTIONAL! - createObject(123) { + rmi.create(123) { server.logger.error("Running test for: Server -> Client") RmiCommonTest.runTests(this@onMessage, this, 123) server.logger.error("Done with test for: Server -> Client") @@ -148,7 +241,7 @@ class RmiSimpleTest : BaseTest() { addEndPoint(client) client.onConnect { - createObject(23) { + rmi.create(23) { client.logger.error("Running test for: Client -> Server") RmiCommonTest.runTests(this@onConnect, this, 23) client.logger.error("Done with test for: Client -> Server") @@ -164,90 +257,7 @@ 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() - } - } - - waitForThreads() - } - - fun rmiGlobal(isIpv4: Boolean = false, isIpv6: Boolean = false, runIpv4Connect: Boolean = true, config: Configuration.() -> Unit = {}) { - run { - val configuration = serverConfig() - configuration.enableIPv4 = isIpv4 - configuration.enableIPv6 = isIpv6 - config(configuration) - - configuration.serialization.registerRmi(TestCow::class.java, TestCowImpl::class.java) - configuration.serialization.register(MessageWithTestCow::class.java) - configuration.serialization.register(UnsupportedOperationException::class.java) - - // for Client -> Server RMI - configuration.serialization.registerRmi(TestCow::class.java, TestCowImpl::class.java) - - val server = Server(configuration) - addEndPoint(server) - server.bind() - - server.onMessage { m -> - server.logger.error("Received finish signal for test for: Client -> Server") - - val `object` = m.testCow - val id = `object`.id() - - Assert.assertEquals(44, id.toLong()) - - server.logger.error("Finished test for: Client -> Server") - - // normally this is in the 'connected', but we do it here, so that it's more linear and easier to debug - createObject(4) { - server.logger.error("Running test for: Server -> Client") - RmiCommonTest.runTests(this@onMessage, this, 4) - server.logger.error("Done with test for: Server -> Client") - } - } - } - - run { - val configuration = clientConfig() - config(configuration) -// configuration.serialization.registerRmi(TestCow::class.java, TestCowImpl::class.java) - - val client = Client(configuration) - addEndPoint(client) - - client.onMessage { m -> - client.logger.error("Received finish signal for test for: Client -> Server") - val `object` = m.testCow - val id = `object`.id() - Assert.assertEquals(4, id.toLong()) - client.logger.error("Finished test for: Client -> Server") - 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 { - client.createObject(44) { - client.logger.error("Running test for: Client -> Server") - RmiCommonTest.runTests(client.connection, this, 44) - client.logger.error("Done with test for: Client -> Server") - } - } + doConnect(isIpv4, isIpv6, runIpv4Connect, client) } waitForThreads() diff --git a/test/dorkboxTest/network/rmi/RmiSpamAsyncTest.kt b/test/dorkboxTest/network/rmi/RmiSpamAsyncTest.kt index 760a6957..ebf6b7f4 100644 --- a/test/dorkboxTest/network/rmi/RmiSpamAsyncTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSpamAsyncTest.kt @@ -61,12 +61,12 @@ class RmiSpamAsyncTest : BaseTest() { // the logger cannot keep-up if it's on trace setLogLevel(Level.DEBUG) - configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) server = Server(configuration) addEndPoint(server) - server.saveGlobalObject(TestObjectImpl(counter), RMI_ID) + server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID) server.bind() } @@ -83,7 +83,7 @@ class RmiSpamAsyncTest : BaseTest() { addEndPoint(client) client.onConnect { - val remoteObject = getGlobalObject(RMI_ID) + val remoteObject = rmi.getGlobal(RMI_ID) val obj = remoteObject as RemoteObject obj.async = true diff --git a/test/dorkboxTest/network/rmi/RmiSpamSyncSuspendingTest.kt b/test/dorkboxTest/network/rmi/RmiSpamSyncSuspendingTest.kt index 6b1c694b..64590392 100644 --- a/test/dorkboxTest/network/rmi/RmiSpamSyncSuspendingTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSpamSyncSuspendingTest.kt @@ -62,12 +62,12 @@ class RmiSpamSyncSuspendingTest : BaseTest() { val configuration = serverConfig() config(configuration) - configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) server = Server(configuration) addEndPoint(server) - server.saveGlobalObject(TestObjectImpl(counter), RMI_ID) + server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID) server.bind() } @@ -81,7 +81,7 @@ class RmiSpamSyncSuspendingTest : BaseTest() { addEndPoint(client) client.onConnect { - val remoteObject = getGlobalObject(RMI_ID) + val remoteObject = rmi.getGlobal(RMI_ID) val obj = remoteObject as RemoteObject obj.async = false diff --git a/test/dorkboxTest/network/rmi/RmiSpamSyncTest.kt b/test/dorkboxTest/network/rmi/RmiSpamSyncTest.kt index 59903386..0d9c3e10 100644 --- a/test/dorkboxTest/network/rmi/RmiSpamSyncTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSpamSyncTest.kt @@ -63,12 +63,12 @@ class RmiSpamSyncTest : BaseTest() { val configuration = serverConfig() config(configuration) - configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java) server = Server(configuration) addEndPoint(server) - server.saveGlobalObject(TestObjectImpl(counter), RMI_ID) + server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID) server.bind() } @@ -82,7 +82,7 @@ class RmiSpamSyncTest : BaseTest() { addEndPoint(client) client.onConnect { - val remoteObject = getGlobalObject(RMI_ID) + val remoteObject = rmi.getGlobal(RMI_ID) val obj = remoteObject as RemoteObject obj.async = false diff --git a/test/dorkboxTest/network/rmi/cows/TestCowImpl.kt b/test/dorkboxTest/network/rmi/cows/TestCowImpl.kt index 8d048c7e..031bf021 100644 --- a/test/dorkboxTest/network/rmi/cows/TestCowImpl.kt +++ b/test/dorkboxTest/network/rmi/cows/TestCowImpl.kt @@ -65,20 +65,20 @@ open class TestCowImpl(val id: Int) : TestCowBaseImpl(), TestCow { } override suspend fun withSuspend(value: String, v2: Int) { - throw RuntimeException("Should never be executed!") + throw RuntimeException("'$value : $v2' should never be executed!") } suspend fun withSuspend(connection: Connection, value: String, v2: Int) { - connection.logger.error("Suspending!") + connection.logger.error("Suspending '$value : $v2'!") delay(2000) } override suspend fun withSuspendAndReturn(value: String, v2: Int): Int { - throw RuntimeException("Should never be executed!") + throw RuntimeException("'$value : $v2' should never be executed!") } suspend fun withSuspendAndReturn(connection: Connection, value: String, v2: Int): Int { - connection.logger.error("Suspending with return!") + connection.logger.error("Suspending '$value' with return!") delay(2000) return v2 } diff --git a/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt b/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt index 870d9b61..fc541caf 100644 --- a/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt +++ b/test/dorkboxTest/network/rmi/multiJVM/TestClient.kt @@ -78,8 +78,8 @@ object TestClient { client.onConnect { logger.error("Starting test for: Client -> Server") - createObject(124123) { - RmiCommonTest.runTests(this@onConnect, this, 124123) + rmi.getGlobal(12123).apply { + RmiCommonTest.runTests(this@onConnect, this, 12123) logger.error("DONE") // now send this remote object ACROSS the wire to the server (on the server, this is where the IMPLEMENTATION lives) diff --git a/test/dorkboxTest/network/rmi/multiJVM/TestServer.kt b/test/dorkboxTest/network/rmi/multiJVM/TestServer.kt index 10002ecd..bceb65a1 100644 --- a/test/dorkboxTest/network/rmi/multiJVM/TestServer.kt +++ b/test/dorkboxTest/network/rmi/multiJVM/TestServer.kt @@ -39,15 +39,17 @@ object TestServer { configuration.enableRemoteSignatureValidation = false configuration.settingsStore = MemoryStore.type() // don't want to persist anything on disk! - configuration.serialization.registerRmi(TestCow::class.java, TestCowImpl::class.java) + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) configuration.serialization.register(MessageWithTestCow::class.java) configuration.serialization.register(UnsupportedOperationException::class.java) configuration.serialization.register(TestBabyCowImpl::class.java) - configuration.serialization.registerRmi(TestCow::class.java, TestCowImpl::class.java) + configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java) val server = Server(configuration) + server.rmiGlobal.save(TestCowImpl(12123), 12123) + server.onMessage { m -> logger.error("Received finish signal for test for: Client -> Server") val `object` = m.testCow