2020-08-13 16:53:24 +02:00
|
|
|
/*
|
2020-08-19 15:29:35 +02:00
|
|
|
* Copyright 2020 dorkbox, llc
|
2020-08-13 16:53:24 +02:00
|
|
|
*
|
|
|
|
* 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
|
2020-08-19 15:29:35 +02:00
|
|
|
*
|
2020-08-13 16:53:24 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
2020-08-19 15:29:35 +02:00
|
|
|
package dorkboxTest.network.rmi.multiJVM
|
|
|
|
|
2020-08-13 16:53:24 +02:00
|
|
|
import dorkbox.network.Server
|
|
|
|
import dorkbox.network.connection.Connection
|
2021-08-23 08:39:55 +02:00
|
|
|
import dorkbox.storage.Storage
|
2020-08-13 16:53:24 +02:00
|
|
|
import dorkboxTest.network.BaseTest
|
2020-08-31 14:52:42 +02:00
|
|
|
import dorkboxTest.network.rmi.cows.MessageWithTestCow
|
2020-09-02 15:02:52 +02:00
|
|
|
import dorkboxTest.network.rmi.cows.TestBabyCowImpl
|
2020-08-31 14:52:42 +02:00
|
|
|
import dorkboxTest.network.rmi.cows.TestCow
|
|
|
|
import dorkboxTest.network.rmi.cows.TestCowImpl
|
2020-08-13 16:53:24 +02:00
|
|
|
import dorkboxTest.network.rmi.multiJVM.TestClient.setup
|
2020-09-22 17:40:39 +02:00
|
|
|
import kotlinx.coroutines.runBlocking
|
2020-08-25 17:45:08 +02:00
|
|
|
import org.junit.Assert
|
2020-08-13 16:53:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
object TestServer {
|
|
|
|
@JvmStatic
|
|
|
|
fun main(args: Array<String>) {
|
|
|
|
setup()
|
|
|
|
|
|
|
|
val configuration = BaseTest.serverConfig()
|
2020-09-23 16:00:47 +02:00
|
|
|
configuration.enableRemoteSignatureValidation = false
|
2021-08-23 08:39:55 +02:00
|
|
|
configuration.settingsStore = Storage.Memory() // don't want to persist anything on disk!
|
2020-08-18 23:18:35 +02:00
|
|
|
|
2021-07-02 11:40:20 +02:00
|
|
|
configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java)
|
2020-09-03 14:34:50 +02:00
|
|
|
configuration.serialization.register(MessageWithTestCow::class.java)
|
|
|
|
configuration.serialization.register(UnsupportedOperationException::class.java)
|
|
|
|
|
2020-09-02 15:02:52 +02:00
|
|
|
configuration.serialization.register(TestBabyCowImpl::class.java)
|
2021-07-02 11:40:20 +02:00
|
|
|
configuration.serialization.rmi.register(TestCow::class.java, TestCowImpl::class.java)
|
2020-08-13 16:53:24 +02:00
|
|
|
|
|
|
|
val server = Server<Connection>(configuration)
|
|
|
|
|
2021-07-02 11:40:20 +02:00
|
|
|
server.rmiGlobal.save(TestCowImpl(12123), 12123)
|
|
|
|
|
2021-04-30 22:39:36 +02:00
|
|
|
server.onMessage<MessageWithTestCow> { m ->
|
|
|
|
logger.error("Received finish signal for test for: Client -> Server")
|
2020-08-25 17:45:08 +02:00
|
|
|
val `object` = m.testCow
|
|
|
|
val id = `object`.id()
|
2021-07-06 15:38:53 +02:00
|
|
|
Assert.assertEquals(124123, id)
|
2021-04-30 22:39:36 +02:00
|
|
|
logger.error("Finished test for: Client -> Server")
|
2020-08-25 17:45:08 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// System.err.println("Starting test for: Server -> Client")
|
|
|
|
// connection.createObject<TestCow>(123) { rmiId, remoteObject ->
|
|
|
|
// System.err.println("Running test for: Server -> Client")
|
|
|
|
// RmiTest.runTests(connection, remoteObject, 123)
|
|
|
|
// System.err.println("Done with test for: Server -> Client")
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
2021-04-30 22:39:36 +02:00
|
|
|
server.onMessage<TestCow> { test ->
|
|
|
|
logger.error("Received test cow from client")
|
2020-08-25 17:45:08 +02:00
|
|
|
// this object LIVES on the server.
|
|
|
|
|
2020-08-26 15:34:04 +02:00
|
|
|
try {
|
|
|
|
test.moo()
|
|
|
|
Assert.fail("Should catch an exception!")
|
|
|
|
} catch (e: Exception) {
|
|
|
|
}
|
2020-08-25 17:45:08 +02:00
|
|
|
|
2020-08-26 15:34:04 +02:00
|
|
|
// now test sending this object BACK to the client. The client SHOULD have the same RMI proxy object as before!
|
2021-04-30 22:39:36 +02:00
|
|
|
send(test)
|
2020-08-25 17:45:08 +02:00
|
|
|
|
|
|
|
// System.err.println("Starting test for: Server -> Client")
|
|
|
|
// connection.createObject<TestCow>(123) { rmiId, remoteObject ->
|
|
|
|
// System.err.println("Running test for: Server -> Client")
|
|
|
|
// RmiTest.runTests(connection, remoteObject, 123)
|
|
|
|
// System.err.println("Done with test for: Server -> Client")
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
2020-09-02 03:18:10 +02:00
|
|
|
server.bind()
|
2020-09-22 17:40:39 +02:00
|
|
|
|
|
|
|
runBlocking {
|
|
|
|
server.waitForClose()
|
|
|
|
}
|
2020-08-13 16:53:24 +02:00
|
|
|
}
|
|
|
|
}
|