WIP unit tests with updated RMI api
This commit is contained in:
parent
ad9729b0ff
commit
bcad2f8d12
|
@ -143,7 +143,7 @@ class DisconnectReconnectTest : BaseTest() {
|
||||||
|
|
||||||
run {
|
run {
|
||||||
val config = serverConfig()
|
val config = serverConfig()
|
||||||
config.serialization.registerRmi(CloseIface::class.java)
|
config.serialization.rmi.register(CloseIface::class.java)
|
||||||
|
|
||||||
val server: Server<Connection> = Server(config)
|
val server: Server<Connection> = Server(config)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
@ -155,18 +155,21 @@ class DisconnectReconnectTest : BaseTest() {
|
||||||
delay(2000)
|
delay(2000)
|
||||||
|
|
||||||
logger.error("Disconnecting via RMI ....")
|
logger.error("Disconnecting via RMI ....")
|
||||||
val closerObject = getGlobalObject<CloseIface>(CLOSE_ID)
|
val closerObject = rmi.getGlobal<CloseIface>(CLOSE_ID)
|
||||||
closerObject.close()
|
closerObject.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
val config = clientConfig()
|
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<Connection> = Client(config)
|
val client: Client<Connection> = Client(config)
|
||||||
addEndPoint(client)
|
addEndPoint(client)
|
||||||
client.saveGlobalObject(CloseImpl(), CLOSE_ID)
|
|
||||||
|
client.onConnect {
|
||||||
|
rmi.save(CloseImpl(), CLOSE_ID)
|
||||||
|
}
|
||||||
|
|
||||||
client.onDisconnect {
|
client.onDisconnect {
|
||||||
logger.error("Disconnected!")
|
logger.error("Disconnected!")
|
||||||
|
|
|
@ -120,7 +120,7 @@ class PingPongTest : BaseTest() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun register(manager: Serialization) {
|
private fun register(manager: Serialization<Connection>) {
|
||||||
manager.register(Data::class.java)
|
manager.register(Data::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ class SerializationValidationTest : BaseTest() {
|
||||||
fun checkTakeKryo() {
|
fun checkTakeKryo() {
|
||||||
val serialization = serverConfig().serialization
|
val serialization = serverConfig().serialization
|
||||||
|
|
||||||
val kryos = mutableListOf<KryoExtra>()
|
val kryos = mutableListOf<KryoExtra<Connection>>()
|
||||||
for (i in 0 until 17) {
|
for (i in 0 until 17) {
|
||||||
kryos.add(serialization.takeKryo())
|
kryos.add(serialization.takeKryo())
|
||||||
}
|
}
|
||||||
|
@ -75,12 +75,14 @@ class SerializationValidationTest : BaseTest() {
|
||||||
fun checkOutOfOrder() {
|
fun checkOutOfOrder() {
|
||||||
run {
|
run {
|
||||||
val configuration = serverConfig()
|
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!
|
configuration.serialization.register(TestObjectImpl::class.java) // this is again, on purpose to verify registration order!
|
||||||
|
|
||||||
val server = Server<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
|
||||||
|
server.rmiGlobal.save(TestObjectImpl(), 1)
|
||||||
|
|
||||||
server.onMessage<TestObject> { message ->
|
server.onMessage<TestObject> { message ->
|
||||||
stopEndPoints()
|
stopEndPoints()
|
||||||
}
|
}
|
||||||
|
@ -96,7 +98,7 @@ class SerializationValidationTest : BaseTest() {
|
||||||
|
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
logger.error("Connected")
|
logger.error("Connected")
|
||||||
createObject<TestObject> {
|
rmi.getGlobal<TestObject>(1).apply {
|
||||||
logger.error("Starting test")
|
logger.error("Starting test")
|
||||||
setValue(43.21f)
|
setValue(43.21f)
|
||||||
|
|
||||||
|
@ -119,12 +121,14 @@ class SerializationValidationTest : BaseTest() {
|
||||||
fun checkOutOfOrder2() {
|
fun checkOutOfOrder2() {
|
||||||
run {
|
run {
|
||||||
val configuration = serverConfig()
|
val configuration = serverConfig()
|
||||||
configuration.serialization.registerRmi(TestObject::class.java)
|
configuration.serialization.rmi.register(TestObject::class.java)
|
||||||
configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java)
|
configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java)
|
||||||
|
|
||||||
val server = Server<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
|
||||||
|
server.rmiGlobal.save(TestObjectImpl(), 1)
|
||||||
|
|
||||||
server.onMessage<TestObject> { message ->
|
server.onMessage<TestObject> { message ->
|
||||||
stopEndPoints()
|
stopEndPoints()
|
||||||
}
|
}
|
||||||
|
@ -140,7 +144,7 @@ class SerializationValidationTest : BaseTest() {
|
||||||
|
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
logger.error("Connected")
|
logger.error("Connected")
|
||||||
createObject<TestObject> {
|
rmi.getGlobal<TestObject>(1).apply {
|
||||||
logger.error("Starting test")
|
logger.error("Starting test")
|
||||||
setValue(43.21f)
|
setValue(43.21f)
|
||||||
|
|
||||||
|
@ -159,7 +163,7 @@ class SerializationValidationTest : BaseTest() {
|
||||||
waitForThreads()
|
waitForThreads()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun register(serialization: Serialization) {
|
private fun register(serialization: Serialization<Connection>) {
|
||||||
serialization.register(Command1::class.java)
|
serialization.register(Command1::class.java)
|
||||||
serialization.register(Command2::class.java)
|
serialization.register(Command2::class.java)
|
||||||
serialization.register(Command3::class.java)
|
serialization.register(Command3::class.java)
|
||||||
|
|
|
@ -31,8 +31,6 @@ import java.util.concurrent.atomic.AtomicLong
|
||||||
class MemoryTest : BaseTest() {
|
class MemoryTest : BaseTest() {
|
||||||
private val counter = AtomicLong(0)
|
private val counter = AtomicLong(0)
|
||||||
|
|
||||||
private val RMI_ID = 12251
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// the logger cannot keep-up if it's on trace
|
// the logger cannot keep-up if it's on trace
|
||||||
setLogLevel(Level.DEBUG)
|
setLogLevel(Level.DEBUG)
|
||||||
|
@ -41,12 +39,14 @@ class MemoryTest : BaseTest() {
|
||||||
@Test
|
@Test
|
||||||
fun runForeverIpcAsyncNormal() {
|
fun runForeverIpcAsyncNormal() {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
|
val RMI_ID = 12251
|
||||||
|
|
||||||
run {
|
run {
|
||||||
val configuration = serverConfig()
|
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<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
server.saveGlobalObject(TestObjectImpl(counter), RMI_ID)
|
server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID)
|
||||||
server.bind()
|
server.bind()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class MemoryTest : BaseTest() {
|
||||||
run {
|
run {
|
||||||
val client = Client<Connection>(clientConfig())
|
val client = Client<Connection>(clientConfig())
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
val remoteObject = getGlobalObject<TestObject>(RMI_ID)
|
val remoteObject = rmi.getGlobal<TestObject>(RMI_ID)
|
||||||
val obj = remoteObject as RemoteObject
|
val obj = remoteObject as RemoteObject
|
||||||
obj.async = true
|
obj.async = true
|
||||||
|
|
||||||
|
@ -79,13 +79,15 @@ class MemoryTest : BaseTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun runForeverIpcAsyncSuspend() {
|
fun runForeverIpcAsyncSuspend() {
|
||||||
|
val RMI_ID = 12251
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
run {
|
run {
|
||||||
val configuration = serverConfig()
|
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<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
server.saveGlobalObject(TestObjectImpl(counter), RMI_ID)
|
server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID)
|
||||||
server.bind()
|
server.bind()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +95,7 @@ class MemoryTest : BaseTest() {
|
||||||
run {
|
run {
|
||||||
val client = Client<Connection>(clientConfig())
|
val client = Client<Connection>(clientConfig())
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
val remoteObject = getGlobalObject<TestObject>(RMI_ID)
|
val remoteObject = rmi.getGlobal<TestObject>(RMI_ID)
|
||||||
val obj = remoteObject as RemoteObject
|
val obj = remoteObject as RemoteObject
|
||||||
obj.async = true
|
obj.async = true
|
||||||
|
|
||||||
|
@ -155,23 +157,23 @@ class MemoryTest : BaseTest() {
|
||||||
val serialization = serverConfig().serialization
|
val serialization = serverConfig().serialization
|
||||||
|
|
||||||
// 17 to force a pool size change
|
// 17 to force a pool size change
|
||||||
var kryo1: KryoExtra
|
var kryo1: KryoExtra<Connection>
|
||||||
var kryo2: KryoExtra
|
var kryo2: KryoExtra<Connection>
|
||||||
var kryo3: KryoExtra
|
var kryo3: KryoExtra<Connection>
|
||||||
var kryo4: KryoExtra
|
var kryo4: KryoExtra<Connection>
|
||||||
var kryo5: KryoExtra
|
var kryo5: KryoExtra<Connection>
|
||||||
var kryo6: KryoExtra
|
var kryo6: KryoExtra<Connection>
|
||||||
var kryo7: KryoExtra
|
var kryo7: KryoExtra<Connection>
|
||||||
var kryo8: KryoExtra
|
var kryo8: KryoExtra<Connection>
|
||||||
var kryo9: KryoExtra
|
var kryo9: KryoExtra<Connection>
|
||||||
var kryo10: KryoExtra
|
var kryo10: KryoExtra<Connection>
|
||||||
var kryo11: KryoExtra
|
var kryo11: KryoExtra<Connection>
|
||||||
var kryo12: KryoExtra
|
var kryo12: KryoExtra<Connection>
|
||||||
var kryo13: KryoExtra
|
var kryo13: KryoExtra<Connection>
|
||||||
var kryo14: KryoExtra
|
var kryo14: KryoExtra<Connection>
|
||||||
var kryo15: KryoExtra
|
var kryo15: KryoExtra<Connection>
|
||||||
var kryo16: KryoExtra
|
var kryo16: KryoExtra<Connection>
|
||||||
var kryo17: KryoExtra
|
var kryo17: KryoExtra<Connection>
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
kryo1 = serialization.takeKryo()
|
kryo1 = serialization.takeKryo()
|
||||||
|
|
|
@ -40,8 +40,8 @@ class RmiDelayedInvocationTest : BaseTest() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun register(serialization: Serialization) {
|
fun register(serialization: Serialization<Connection>) {
|
||||||
serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java)
|
serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +57,7 @@ class RmiDelayedInvocationTest : BaseTest() {
|
||||||
val server = Server<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
|
||||||
server.saveGlobalObject(TestObjectImpl(iterateLock), OBJ_ID)
|
server.rmiGlobal.save(TestObjectImpl(iterateLock), OBJ_ID)
|
||||||
server.bind()
|
server.bind()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class RmiDelayedInvocationTest : BaseTest() {
|
||||||
addEndPoint(client)
|
addEndPoint(client)
|
||||||
|
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
val remoteObject = getGlobalObject<TestObject>(OBJ_ID)
|
val remoteObject = rmi.getGlobal<TestObject>(OBJ_ID)
|
||||||
|
|
||||||
val totalRuns = 100
|
val totalRuns = 100
|
||||||
var abort = false
|
var abort = false
|
||||||
|
|
|
@ -59,12 +59,14 @@ class RmiNestedTest : BaseTest() {
|
||||||
run {
|
run {
|
||||||
val configuration = serverConfig()
|
val configuration = serverConfig()
|
||||||
|
|
||||||
configuration.serialization.registerRmi(TestObject::class.java, TestObjectAnnotImpl::class.java)
|
configuration.serialization.rmi.register(TestObject::class.java, TestObjectAnnotImpl::class.java)
|
||||||
configuration.serialization.registerRmi(OtherObject::class.java, OtherObjectImpl::class.java)
|
configuration.serialization.rmi.register(OtherObject::class.java, OtherObjectImpl::class.java)
|
||||||
|
|
||||||
val server = Server<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
|
||||||
|
server.rmiGlobal.save(TestObjectImpl(), 1)
|
||||||
|
|
||||||
server.onMessage<OtherObject> { message ->
|
server.onMessage<OtherObject> { message ->
|
||||||
// The test is complete when the client sends the OtherObject instance.
|
// 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.
|
// 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 {
|
client.onConnect {
|
||||||
logger.error("Connected")
|
logger.error("Connected")
|
||||||
createObject<TestObject> {
|
rmi.getGlobal<TestObject>(1).apply {
|
||||||
logger.error("Starting test")
|
logger.error("Starting test")
|
||||||
setValue(43.21f)
|
setValue(43.21f)
|
||||||
|
|
||||||
|
@ -124,12 +126,14 @@ class RmiNestedTest : BaseTest() {
|
||||||
fun doubleRmi() {
|
fun doubleRmi() {
|
||||||
run {
|
run {
|
||||||
val configuration = serverConfig()
|
val configuration = serverConfig()
|
||||||
configuration.serialization.registerRmi(TestObject::class.java, TestObjectAnnotImpl::class.java)
|
configuration.serialization.rmi.register(TestObject::class.java, TestObjectAnnotImpl::class.java)
|
||||||
configuration.serialization.registerRmi(OtherObject::class.java, OtherObjectImpl::class.java)
|
configuration.serialization.rmi.register(OtherObject::class.java, OtherObjectImpl::class.java)
|
||||||
|
|
||||||
val server = Server<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
|
||||||
|
server.rmiGlobal.save(TestObjectImpl(), 1)
|
||||||
|
|
||||||
server.onMessage<OtherObject> { message ->
|
server.onMessage<OtherObject> { message ->
|
||||||
// The test is complete when the client sends the OtherObject instance.
|
// 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.
|
// 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 {
|
client.onConnect {
|
||||||
logger.error("Connected")
|
logger.error("Connected")
|
||||||
createObject<TestObject> {
|
rmi.getGlobal<TestObject>(1).apply {
|
||||||
logger.error("Starting test")
|
logger.error("Starting test")
|
||||||
setValue(43.21f)
|
setValue(43.21f)
|
||||||
|
|
||||||
|
@ -189,12 +193,14 @@ class RmiNestedTest : BaseTest() {
|
||||||
fun singleRmi() {
|
fun singleRmi() {
|
||||||
run {
|
run {
|
||||||
val configuration = serverConfig()
|
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)
|
configuration.serialization.register(OtherObjectImpl::class.java)
|
||||||
|
|
||||||
val server = Server<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
|
||||||
|
server.rmiGlobal.save(TestObjectImpl(), 1)
|
||||||
|
|
||||||
server.onMessage<OtherObject> { message ->
|
server.onMessage<OtherObject> { message ->
|
||||||
// The test is complete when the client sends the OtherObject instance.
|
// The test is complete when the client sends the OtherObject instance.
|
||||||
// this 'object' is the REAL object
|
// this 'object' is the REAL object
|
||||||
|
@ -217,7 +223,8 @@ class RmiNestedTest : BaseTest() {
|
||||||
|
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
logger.error("Connected")
|
logger.error("Connected")
|
||||||
createObject<TestObject> {
|
|
||||||
|
rmi.getGlobal<TestObject>(1).apply {
|
||||||
logger.error("Starting test")
|
logger.error("Starting test")
|
||||||
setOtherValue(43.21f)
|
setOtherValue(43.21f)
|
||||||
|
|
||||||
|
@ -247,7 +254,7 @@ class RmiNestedTest : BaseTest() {
|
||||||
fun singleReverseRmi() {
|
fun singleReverseRmi() {
|
||||||
run {
|
run {
|
||||||
val configuration = serverConfig()
|
val configuration = serverConfig()
|
||||||
configuration.serialization.registerRmi(TestObject::class.java, null)
|
configuration.serialization.rmi.register(TestObject::class.java, null)
|
||||||
configuration.serialization.register(OtherObjectImpl::class.java)
|
configuration.serialization.register(OtherObjectImpl::class.java)
|
||||||
|
|
||||||
val server = Server<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
|
@ -255,7 +262,8 @@ class RmiNestedTest : BaseTest() {
|
||||||
|
|
||||||
server.onConnect {
|
server.onConnect {
|
||||||
logger.error("Connected")
|
logger.error("Connected")
|
||||||
createObject<TestObject> {
|
|
||||||
|
rmi.get<TestObject>(1).apply {
|
||||||
logger.error("Starting test")
|
logger.error("Starting test")
|
||||||
setOtherValue(43.21f)
|
setOtherValue(43.21f)
|
||||||
|
|
||||||
|
@ -282,11 +290,16 @@ class RmiNestedTest : BaseTest() {
|
||||||
|
|
||||||
run {
|
run {
|
||||||
val configuration = clientConfig()
|
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<Connection>(configuration)
|
val client = Client<Connection>(configuration)
|
||||||
addEndPoint(client)
|
addEndPoint(client)
|
||||||
|
|
||||||
|
client.onConnect {
|
||||||
|
rmi.save(TestObjectImpl(), 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
client.onMessage<OtherObject> { message ->
|
client.onMessage<OtherObject> { message ->
|
||||||
// The test is complete when the client sends the OtherObject instance.
|
// The test is complete when the client sends the OtherObject instance.
|
||||||
// this 'object' is the REAL object
|
// this 'object' is the REAL object
|
||||||
|
@ -347,6 +360,7 @@ class RmiNestedTest : BaseTest() {
|
||||||
throw RuntimeException("Whoops!")
|
throw RuntimeException("Whoops!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun other(connection: Connection): Float {
|
fun other(connection: Connection): Float {
|
||||||
return aFloat
|
return aFloat
|
||||||
}
|
}
|
||||||
|
@ -388,6 +402,7 @@ class RmiNestedTest : BaseTest() {
|
||||||
throw RuntimeException("Whoops!")
|
throw RuntimeException("Whoops!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun other(connection: Connection): Float {
|
fun other(connection: Connection): Float {
|
||||||
return aFloat
|
return aFloat
|
||||||
}
|
}
|
||||||
|
|
288
test/dorkboxTest/network/rmi/RmiSimpleActionsTest.kt
Normal file
288
test/dorkboxTest/network/rmi/RmiSimpleActionsTest.kt
Normal file
|
@ -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<Connection>(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<Connection>(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<Connection>(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<TestCow>(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<Connection>(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<Connection>(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<Connection>(configuration)
|
||||||
|
addEndPoint(server)
|
||||||
|
server.bind()
|
||||||
|
|
||||||
|
server.rmiGlobal.save(TestCowImpl(44), 44)
|
||||||
|
|
||||||
|
server.onMessage<MessageWithTestCow> { 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<Connection>(configuration)
|
||||||
|
addEndPoint(client)
|
||||||
|
|
||||||
|
client.onConnect {
|
||||||
|
rmi.save(TestCowImpl(4), 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
client.onMessage<MessageWithTestCow> { 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<TestCow>(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()
|
||||||
|
}
|
||||||
|
}
|
|
@ -70,6 +70,18 @@ class RmiSimpleTest : BaseTest() {
|
||||||
rmiGlobal(isIpv4 = true, isIpv6 = true, runIpv4Connect = true)
|
rmiGlobal(isIpv4 = true, isIpv6 = true, runIpv4Connect = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun rmiIpcNetworkGlobal() {
|
||||||
|
rmiGlobal {
|
||||||
|
enableIpc = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun rmiIPv4NetworkConnection() {
|
fun rmiIPv4NetworkConnection() {
|
||||||
rmi(isIpv4 = true, isIpv6 = false)
|
rmi(isIpv4 = true, isIpv6 = false)
|
||||||
|
@ -92,19 +104,100 @@ class RmiSimpleTest : BaseTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun rmiIpcNetworkGlobal() {
|
fun rmiIpcNetworkConnection() {
|
||||||
rmiGlobal() {
|
rmi {
|
||||||
enableIpc = true
|
enableIpc = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private fun doConnect(isIpv4: Boolean, isIpv6: Boolean, runIpv4Connect: Boolean, client: Client<Connection>) {
|
||||||
fun rmiIpcNetworkConnection() {
|
when {
|
||||||
rmi() {
|
isIpv4 && isIpv6 && runIpv4Connect -> client.connect(IPv4.LOCALHOST)
|
||||||
enableIpc = true
|
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<Connection>(configuration)
|
||||||
|
addEndPoint(server)
|
||||||
|
server.bind()
|
||||||
|
|
||||||
|
server.rmiGlobal.save(TestCowImpl(44), 44)
|
||||||
|
|
||||||
|
server.onMessage<MessageWithTestCow> { 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<Connection>(configuration)
|
||||||
|
addEndPoint(client)
|
||||||
|
|
||||||
|
client.onConnect {
|
||||||
|
rmi.save(TestCowImpl(4), 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
client.onMessage<MessageWithTestCow> { 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 = {}) {
|
fun rmi(isIpv4: Boolean = false, isIpv6: Boolean = false, runIpv4Connect: Boolean = true, config: Configuration.() -> Unit = {}) {
|
||||||
run {
|
run {
|
||||||
val configuration = serverConfig()
|
val configuration = serverConfig()
|
||||||
|
@ -112,7 +205,7 @@ class RmiSimpleTest : BaseTest() {
|
||||||
configuration.enableIPv6 = isIpv6
|
configuration.enableIPv6 = isIpv6
|
||||||
config(configuration)
|
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(MessageWithTestCow::class.java)
|
||||||
configuration.serialization.register(UnsupportedOperationException::class.java)
|
configuration.serialization.register(UnsupportedOperationException::class.java)
|
||||||
|
|
||||||
|
@ -131,7 +224,7 @@ class RmiSimpleTest : BaseTest() {
|
||||||
|
|
||||||
server.logger.error("Starting test for: Server -> Client")
|
server.logger.error("Starting test for: Server -> Client")
|
||||||
// NOTE: THIS IS BI-DIRECTIONAL!
|
// NOTE: THIS IS BI-DIRECTIONAL!
|
||||||
createObject<TestCow>(123) {
|
rmi.create<TestCow>(123) {
|
||||||
server.logger.error("Running test for: Server -> Client")
|
server.logger.error("Running test for: Server -> Client")
|
||||||
RmiCommonTest.runTests(this@onMessage, this, 123)
|
RmiCommonTest.runTests(this@onMessage, this, 123)
|
||||||
server.logger.error("Done with test for: Server -> Client")
|
server.logger.error("Done with test for: Server -> Client")
|
||||||
|
@ -148,7 +241,7 @@ class RmiSimpleTest : BaseTest() {
|
||||||
addEndPoint(client)
|
addEndPoint(client)
|
||||||
|
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
createObject<TestCow>(23) {
|
rmi.create<TestCow>(23) {
|
||||||
client.logger.error("Running test for: Client -> Server")
|
client.logger.error("Running test for: Client -> Server")
|
||||||
RmiCommonTest.runTests(this@onConnect, this, 23)
|
RmiCommonTest.runTests(this@onConnect, this, 23)
|
||||||
client.logger.error("Done with test for: Client -> Server")
|
client.logger.error("Done with test for: Client -> Server")
|
||||||
|
@ -164,90 +257,7 @@ class RmiSimpleTest : BaseTest() {
|
||||||
stopEndPoints(2000)
|
stopEndPoints(2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
when {
|
doConnect(isIpv4, isIpv6, runIpv4Connect, client)
|
||||||
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<Connection>(configuration)
|
|
||||||
addEndPoint(server)
|
|
||||||
server.bind()
|
|
||||||
|
|
||||||
server.onMessage<MessageWithTestCow> { 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<TestCow>(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<Connection>(configuration)
|
|
||||||
addEndPoint(client)
|
|
||||||
|
|
||||||
client.onMessage<MessageWithTestCow> { 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<TestCow>(44) {
|
|
||||||
client.logger.error("Running test for: Client -> Server")
|
|
||||||
RmiCommonTest.runTests(client.connection, this, 44)
|
|
||||||
client.logger.error("Done with test for: Client -> Server")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForThreads()
|
waitForThreads()
|
||||||
|
|
|
@ -61,12 +61,12 @@ class RmiSpamAsyncTest : BaseTest() {
|
||||||
// the logger cannot keep-up if it's on trace
|
// the logger cannot keep-up if it's on trace
|
||||||
setLogLevel(Level.DEBUG)
|
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)
|
server = Server(configuration)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
|
||||||
server.saveGlobalObject(TestObjectImpl(counter), RMI_ID)
|
server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID)
|
||||||
server.bind()
|
server.bind()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class RmiSpamAsyncTest : BaseTest() {
|
||||||
addEndPoint(client)
|
addEndPoint(client)
|
||||||
|
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
val remoteObject = getGlobalObject<TestObject>(RMI_ID)
|
val remoteObject = rmi.getGlobal<TestObject>(RMI_ID)
|
||||||
val obj = remoteObject as RemoteObject
|
val obj = remoteObject as RemoteObject
|
||||||
obj.async = true
|
obj.async = true
|
||||||
|
|
||||||
|
|
|
@ -62,12 +62,12 @@ class RmiSpamSyncSuspendingTest : BaseTest() {
|
||||||
val configuration = serverConfig()
|
val configuration = serverConfig()
|
||||||
config(configuration)
|
config(configuration)
|
||||||
|
|
||||||
configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java)
|
configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java)
|
||||||
|
|
||||||
server = Server(configuration)
|
server = Server(configuration)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
|
||||||
server.saveGlobalObject(TestObjectImpl(counter), RMI_ID)
|
server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID)
|
||||||
server.bind()
|
server.bind()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class RmiSpamSyncSuspendingTest : BaseTest() {
|
||||||
addEndPoint(client)
|
addEndPoint(client)
|
||||||
|
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
val remoteObject = getGlobalObject<TestObject>(RMI_ID)
|
val remoteObject = rmi.getGlobal<TestObject>(RMI_ID)
|
||||||
val obj = remoteObject as RemoteObject
|
val obj = remoteObject as RemoteObject
|
||||||
obj.async = false
|
obj.async = false
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,12 @@ class RmiSpamSyncTest : BaseTest() {
|
||||||
val configuration = serverConfig()
|
val configuration = serverConfig()
|
||||||
config(configuration)
|
config(configuration)
|
||||||
|
|
||||||
configuration.serialization.registerRmi(TestObject::class.java, TestObjectImpl::class.java)
|
configuration.serialization.rmi.register(TestObject::class.java, TestObjectImpl::class.java)
|
||||||
|
|
||||||
server = Server(configuration)
|
server = Server(configuration)
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
|
||||||
server.saveGlobalObject(TestObjectImpl(counter), RMI_ID)
|
server.rmiGlobal.save(TestObjectImpl(counter), RMI_ID)
|
||||||
server.bind()
|
server.bind()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class RmiSpamSyncTest : BaseTest() {
|
||||||
addEndPoint(client)
|
addEndPoint(client)
|
||||||
|
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
val remoteObject = getGlobalObject<TestObject>(RMI_ID)
|
val remoteObject = rmi.getGlobal<TestObject>(RMI_ID)
|
||||||
val obj = remoteObject as RemoteObject
|
val obj = remoteObject as RemoteObject
|
||||||
obj.async = false
|
obj.async = false
|
||||||
|
|
||||||
|
|
|
@ -65,20 +65,20 @@ open class TestCowImpl(val id: Int) : TestCowBaseImpl(), TestCow {
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun withSuspend(value: String, v2: Int) {
|
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) {
|
suspend fun withSuspend(connection: Connection, value: String, v2: Int) {
|
||||||
connection.logger.error("Suspending!")
|
connection.logger.error("Suspending '$value : $v2'!")
|
||||||
delay(2000)
|
delay(2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun withSuspendAndReturn(value: String, v2: Int): Int {
|
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 {
|
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)
|
delay(2000)
|
||||||
return v2
|
return v2
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,8 @@ object TestClient {
|
||||||
client.onConnect {
|
client.onConnect {
|
||||||
logger.error("Starting test for: Client -> Server")
|
logger.error("Starting test for: Client -> Server")
|
||||||
|
|
||||||
createObject<TestCow>(124123) {
|
rmi.getGlobal<TestCow>(12123).apply {
|
||||||
RmiCommonTest.runTests(this@onConnect, this, 124123)
|
RmiCommonTest.runTests(this@onConnect, this, 12123)
|
||||||
logger.error("DONE")
|
logger.error("DONE")
|
||||||
|
|
||||||
// now send this remote object ACROSS the wire to the server (on the server, this is where the IMPLEMENTATION lives)
|
// now send this remote object ACROSS the wire to the server (on the server, this is where the IMPLEMENTATION lives)
|
||||||
|
|
|
@ -39,15 +39,17 @@ object TestServer {
|
||||||
configuration.enableRemoteSignatureValidation = false
|
configuration.enableRemoteSignatureValidation = false
|
||||||
configuration.settingsStore = MemoryStore.type() // don't want to persist anything on disk!
|
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(MessageWithTestCow::class.java)
|
||||||
configuration.serialization.register(UnsupportedOperationException::class.java)
|
configuration.serialization.register(UnsupportedOperationException::class.java)
|
||||||
|
|
||||||
configuration.serialization.register(TestBabyCowImpl::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<Connection>(configuration)
|
val server = Server<Connection>(configuration)
|
||||||
|
|
||||||
|
server.rmiGlobal.save(TestCowImpl(12123), 12123)
|
||||||
|
|
||||||
server.onMessage<MessageWithTestCow> { m ->
|
server.onMessage<MessageWithTestCow> { m ->
|
||||||
logger.error("Received finish signal for test for: Client -> Server")
|
logger.error("Received finish signal for test for: Client -> Server")
|
||||||
val `object` = m.testCow
|
val `object` = m.testCow
|
||||||
|
|
Loading…
Reference in New Issue
Block a user