From 08a72736b9d4c586f080960f9076a687681d3cd4 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 3 Sep 2020 02:40:53 +0200 Subject: [PATCH] cleaned up unittests --- test/dorkboxTest/network/rmi/RmiNestedTest.kt | 65 ++++++++++++++++++- test/dorkboxTest/network/rmi/RmiSimpleTest.kt | 2 +- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/test/dorkboxTest/network/rmi/RmiNestedTest.kt b/test/dorkboxTest/network/rmi/RmiNestedTest.kt index 47211e12..17b4b311 100644 --- a/test/dorkboxTest/network/rmi/RmiNestedTest.kt +++ b/test/dorkboxTest/network/rmi/RmiNestedTest.kt @@ -189,7 +189,7 @@ class RmiNestedTest : BaseTest() { client.connect(LOOPBACK, 5000) } } - waitForThreads(999999) + waitForThreads() } @Test @@ -249,7 +249,68 @@ class RmiNestedTest : BaseTest() { client.connect(LOOPBACK, 5000) } } - waitForThreads(999999) + waitForThreads() + } + + @Test + fun singleReverseRmi() { + run { + val configuration = serverConfig() + configuration.serialization.registerRmi(TestObject::class.java, null) + configuration.serialization.register(OtherObjectImpl::class.java) + + val server = Server(configuration) + addEndPoint(server) + + server.onConnect { connection -> + connection.logger.error("Connected") + connection.createObject { rmiId, remoteObject -> + connection.logger.error("Starting test") + remoteObject.setOtherValue(43.21f) + + // Normal remote method call. + Assert.assertEquals(43.21f, remoteObject.getOtherValue(), .0001f) + + // real object + val otherObject: OtherObject = remoteObject.getOtherObject() + + // Normal remote method call on the second object. + val value = otherObject.value() + Assert.assertEquals(43.21f, value, .0001f) + + + // When a proxy object is sent, the other side receives its ACTUAL object (not a proxy of it), because + // that is where that object actually exists. + connection.send(otherObject) + } + } + + server.bind() + } + + + run { + val configuration = clientConfig() + configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java) + + val client = Client(configuration) + addEndPoint(client) + + client.onMessage { connection, message -> + // The test is complete when the client sends the OtherObject instance. + // this 'object' is the REAL object + if (message.value() == 43.21f) { + stopEndPoints() + } else { + Assert.fail("Incorrect object value") + } + } + + runBlocking { + client.connect(LOOPBACK, 5000) + } + } + waitForThreads() } diff --git a/test/dorkboxTest/network/rmi/RmiSimpleTest.kt b/test/dorkboxTest/network/rmi/RmiSimpleTest.kt index c5655b68..7e5227bb 100644 --- a/test/dorkboxTest/network/rmi/RmiSimpleTest.kt +++ b/test/dorkboxTest/network/rmi/RmiSimpleTest.kt @@ -187,7 +187,7 @@ class RmiSimpleTest : BaseTest() { // this creates a GLOBAL object on the server (instead of a connection specific object) client.createObject(44) { rmiId, remoteObject -> System.err.println("Running test for: Client -> Server") - RmiCommonTest.runTests(client.getConnection(), remoteObject, 44) + RmiCommonTest.runTests(client.connection, remoteObject, 44) System.err.println("Done with test for: Client -> Server") } }