code polish
This commit is contained in:
parent
29367c4d5c
commit
f4bffabbcf
|
@ -63,7 +63,6 @@ object AeronServer {
|
||||||
configuration.listenIpAddress = "127.0.0.1"
|
configuration.listenIpAddress = "127.0.0.1"
|
||||||
configuration.subscriptionPort = 2000
|
configuration.subscriptionPort = 2000
|
||||||
configuration.publicationPort = 2001
|
configuration.publicationPort = 2001
|
||||||
configuration.clientStartPort = 2500
|
|
||||||
configuration.maxClientCount = 5
|
configuration.maxClientCount = 5
|
||||||
configuration.maxConnectionsPerIpAddress = 5
|
configuration.maxConnectionsPerIpAddress = 5
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,40 @@ abstract class BaseTest {
|
||||||
companion object {
|
companion object {
|
||||||
const val LOOPBACK = "loopback"
|
const val LOOPBACK = "loopback"
|
||||||
|
|
||||||
|
init {
|
||||||
|
println("---- " + javaClass.simpleName)
|
||||||
|
|
||||||
|
// 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.level = Level.INFO;
|
||||||
|
// rootLogger.level = Level.DEBUG
|
||||||
|
// rootLogger.level = Level.TRACE;
|
||||||
|
// rootLogger.level = 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)
|
||||||
|
}
|
||||||
|
|
||||||
fun clientConfig(): Configuration {
|
fun clientConfig(): Configuration {
|
||||||
val configuration = Configuration()
|
val configuration = Configuration()
|
||||||
configuration.subscriptionPort = 2000
|
configuration.subscriptionPort = 2000
|
||||||
|
@ -71,7 +105,6 @@ abstract class BaseTest {
|
||||||
configuration.subscriptionPort = 2000
|
configuration.subscriptionPort = 2000
|
||||||
configuration.publicationPort = 2001
|
configuration.publicationPort = 2001
|
||||||
|
|
||||||
configuration.clientStartPort = 2500
|
|
||||||
configuration.maxClientCount = 5
|
configuration.maxClientCount = 5
|
||||||
configuration.maxConnectionsPerIpAddress = 5
|
configuration.maxConnectionsPerIpAddress = 5
|
||||||
|
|
||||||
|
@ -200,47 +233,4 @@ abstract class BaseTest {
|
||||||
} catch (ignored: InterruptedException) {
|
} catch (ignored: InterruptedException) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
|
||||||
println("---- " + javaClass.simpleName)
|
|
||||||
|
|
||||||
// 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.level = Level.INFO;
|
|
||||||
rootLogger.level = Level.DEBUG
|
|
||||||
// rootLogger.level = Level.TRACE;
|
|
||||||
// rootLogger.level = Level.ALL;
|
|
||||||
|
|
||||||
|
|
||||||
// serialization error logs/etc
|
|
||||||
(LoggerFactory.getLogger("Client.SERIAL") as Logger).level = Level.ERROR
|
|
||||||
(LoggerFactory.getLogger("Server.SERIAL") as Logger).level = Level.ERROR
|
|
||||||
|
|
||||||
|
|
||||||
// we only want error messages
|
|
||||||
val nettyLogger = LoggerFactory.getLogger("io.netty") as Logger
|
|
||||||
nettyLogger.level = Level.ERROR
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@ package dorkboxTest.network
|
||||||
import dorkbox.network.Client
|
import dorkbox.network.Client
|
||||||
import dorkbox.network.Server
|
import dorkbox.network.Server
|
||||||
import dorkbox.network.connection.Connection
|
import dorkbox.network.connection.Connection
|
||||||
import dorkbox.network.connection.EndPoint
|
import dorkbox.network.connection.ConnectionParams
|
||||||
import dorkbox.network.connection.MediaDriverConnection
|
|
||||||
import dorkbox.util.exceptions.InitializationException
|
import dorkbox.util.exceptions.InitializationException
|
||||||
import dorkbox.util.exceptions.SecurityException
|
import dorkbox.util.exceptions.SecurityException
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
@ -42,13 +41,15 @@ class ListenerTest : BaseTest() {
|
||||||
|
|
||||||
var overrideCheck = AtomicBoolean(false)
|
var overrideCheck = AtomicBoolean(false)
|
||||||
var serverOnMessage = AtomicBoolean(false)
|
var serverOnMessage = AtomicBoolean(false)
|
||||||
|
var serverConnectionOnMessage = AtomicBoolean(false)
|
||||||
|
var serverDisconnectMessage = AtomicBoolean(false)
|
||||||
var serverConnect = AtomicBoolean(false)
|
var serverConnect = AtomicBoolean(false)
|
||||||
var serverDisconnect = AtomicBoolean(false)
|
var serverDisconnect = AtomicBoolean(false)
|
||||||
var clientConnect = AtomicBoolean(false)
|
var clientConnect = AtomicBoolean(false)
|
||||||
var clientDisconnect = AtomicBoolean(false)
|
var clientDisconnect = AtomicBoolean(false)
|
||||||
|
|
||||||
// quick and dirty test to also test connection sub-classing
|
// quick and dirty test to also test connection sub-classing
|
||||||
internal open inner class TestConnectionA(endPointConnection: EndPoint<TestConnectionA>, driverConnection: MediaDriverConnection) : Connection(endPointConnection, driverConnection) {
|
internal open inner class TestConnectionA(connectionParameters: ConnectionParams<TestConnectionA>) : Connection(connectionParameters) {
|
||||||
open fun check() {
|
open fun check() {
|
||||||
overrideCheck.set(true)
|
overrideCheck.set(true)
|
||||||
}
|
}
|
||||||
|
@ -59,8 +60,8 @@ class ListenerTest : BaseTest() {
|
||||||
fun listener() {
|
fun listener() {
|
||||||
val server: Server<TestConnectionA> = object : Server<TestConnectionA>(
|
val server: Server<TestConnectionA> = object : Server<TestConnectionA>(
|
||||||
serverConfig()) {
|
serverConfig()) {
|
||||||
override fun newConnection(endPoint: EndPoint<TestConnectionA>, mediaDriverConnection: MediaDriverConnection): TestConnectionA {
|
override fun newConnection(connectionParameters: ConnectionParams<TestConnectionA>): TestConnectionA {
|
||||||
return TestConnectionA(endPoint, mediaDriverConnection)
|
return TestConnectionA(connectionParameters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addEndPoint(server)
|
addEndPoint(server)
|
||||||
|
@ -79,8 +80,15 @@ class ListenerTest : BaseTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard connect check
|
// standard connect check
|
||||||
server.onConnect {
|
server.onConnect { connection ->
|
||||||
serverConnect.set(true)
|
serverConnect.set(true)
|
||||||
|
connection.onMessage<Any> {_, _ ->
|
||||||
|
serverConnectionOnMessage.set(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.onDisconnect { _ ->
|
||||||
|
serverDisconnectMessage.set(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard listener disconnect check
|
// standard listener disconnect check
|
||||||
|
@ -97,8 +105,8 @@ class ListenerTest : BaseTest() {
|
||||||
// ----
|
// ----
|
||||||
val client: Client<TestConnectionA> = object : Client<TestConnectionA>(
|
val client: Client<TestConnectionA> = object : Client<TestConnectionA>(
|
||||||
clientConfig()) {
|
clientConfig()) {
|
||||||
override fun newConnection(endPoint: EndPoint<TestConnectionA>, mediaDriverConnection: MediaDriverConnection): TestConnectionA {
|
override fun newConnection(connectionParameters: ConnectionParams<TestConnectionA>): TestConnectionA {
|
||||||
return TestConnectionA(endPoint, mediaDriverConnection)
|
return TestConnectionA(connectionParameters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addEndPoint(client)
|
addEndPoint(client)
|
||||||
|
@ -145,6 +153,8 @@ class ListenerTest : BaseTest() {
|
||||||
Assert.assertEquals(limit.toLong(), count.get() - 1.toLong())
|
Assert.assertEquals(limit.toLong(), count.get() - 1.toLong())
|
||||||
Assert.assertTrue(overrideCheck.get())
|
Assert.assertTrue(overrideCheck.get())
|
||||||
Assert.assertTrue(serverOnMessage.get())
|
Assert.assertTrue(serverOnMessage.get())
|
||||||
|
Assert.assertTrue(serverConnectionOnMessage.get())
|
||||||
|
Assert.assertTrue(serverDisconnectMessage.get())
|
||||||
Assert.assertTrue(serverConnect.get())
|
Assert.assertTrue(serverConnect.get())
|
||||||
Assert.assertTrue(serverDisconnect.get())
|
Assert.assertTrue(serverDisconnect.get())
|
||||||
Assert.assertTrue(clientConnect.get())
|
Assert.assertTrue(clientConnect.get())
|
||||||
|
|
|
@ -51,7 +51,6 @@ class MultipleServerTest : BaseTest() {
|
||||||
val configuration = serverConfig()
|
val configuration = serverConfig()
|
||||||
configuration.subscriptionPort += offset
|
configuration.subscriptionPort += offset
|
||||||
configuration.publicationPort += offset
|
configuration.publicationPort += offset
|
||||||
configuration.clientStartPort += configuration.maxClientCount * offset
|
|
||||||
configuration.aeronLogDirectory = serverAeronDir
|
configuration.aeronLogDirectory = serverAeronDir
|
||||||
|
|
||||||
val server: Server<Connection> = Server(configuration)
|
val server: Server<Connection> = Server(configuration)
|
||||||
|
@ -64,6 +63,7 @@ class MultipleServerTest : BaseTest() {
|
||||||
|
|
||||||
didReceive[count].set(true)
|
didReceive[count].set(true)
|
||||||
if (received.incrementAndGet() == total) {
|
if (received.incrementAndGet() == total) {
|
||||||
|
println("Done, stopping endpoints")
|
||||||
stopEndPoints()
|
stopEndPoints()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user