Added multi-jvm registration validation check. Fixed bug with registration detection for RMI types

This commit is contained in:
nathan 2020-08-13 16:53:24 +02:00
parent a58af6ba00
commit 618168b68b
2 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,87 @@
package dorkboxTest.network.rmi.multiJVM
/*
* Copyright 2019 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.
*/
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.classic.joran.JoranConfigurator
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.ConsoleAppender
import dorkbox.network.Client
import dorkbox.network.connection.Connection
import dorkboxTest.network.BaseTest
import dorkboxTest.network.rmi.RmiTest
import dorkboxTest.network.rmi.classes.TestCow
import kotlinx.coroutines.runBlocking
import org.slf4j.LoggerFactory
object TestClient {
fun setup() {
// assume SLF4J is bound to logback in the current environment
val rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME) as Logger
val context = rootLogger.loggerContext
val jc = JoranConfigurator()
jc.context = context
context.reset() // override default configuration
// rootLogger.setLevel(Level.OFF);
// rootLogger.setLevel(Level.DEBUG);
rootLogger.level = Level.TRACE
// rootLogger.setLevel(Level.ALL);
// we only want error messages
val kryoLogger = LoggerFactory.getLogger("com.esotericsoftware") as Logger
kryoLogger.level = Level.ERROR
val encoder = PatternLayoutEncoder()
encoder.context = context
encoder.pattern = "%date{HH:mm:ss.SSS} %-5level [%logger{35}] %msg%n"
encoder.start()
val consoleAppender = ConsoleAppender<ILoggingEvent>()
consoleAppender.context = context
consoleAppender.encoder = encoder
consoleAppender.start()
rootLogger.addAppender(consoleAppender)
}
@JvmStatic
fun main(args: Array<String>) {
setup()
val configuration = BaseTest.clientConfig()
RmiTest.register(configuration.serialization)
configuration.serialization.register(TestCow::class.java)
val client = Client<Connection>(configuration)
client.disableRemoteKeyValidation()
client.onConnect { connection ->
System.err.println("Starting test for: Client -> Server")
connection.createObject<TestCow>(124123) { _, remoteObject ->
RmiTest.runTests(connection, remoteObject, 124123)
System.err.println("DONE")
client.close()
}
}
runBlocking {
client.connect(BaseTest.LOOPBACK)
}
client.waitForShutdown()
}
}

View File

@ -0,0 +1,41 @@
package dorkboxTest.network.rmi.multiJVM
/*
* Copyright 2019 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.
*/
import dorkbox.network.Server
import dorkbox.network.connection.Connection
import dorkboxTest.network.BaseTest
import dorkboxTest.network.rmi.RmiTest
import dorkboxTest.network.rmi.classes.TestCow
import dorkboxTest.network.rmi.classes.TestCowImpl
import dorkboxTest.network.rmi.multiJVM.TestClient.setup
/**
*
*/
object TestServer {
@JvmStatic
fun main(args: Array<String>) {
setup()
val configuration = BaseTest.serverConfig()
RmiTest.register(configuration.serialization)
configuration.serialization.registerRmi(TestCow::class.java, TestCowImpl::class.java)
val server = Server<Connection>(configuration)
server.disableRemoteKeyValidation()
server.bind(false)
}
}