From 4dda540f38fb5ac3cfcaf30db84d1d9856c3c101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Thu, 18 Dec 2025 12:39:55 +0100 Subject: [PATCH] feature/Improve Pekko find available port --- .../code/actorsystem/ObpActorConfig.scala | 41 ++++++++++++++----- .../akka/actor/AkkaConnectorActorConfig.scala | 40 ++++++++++++------ .../test/scala/code/setup/ServerSetup.scala | 5 +++ 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/obp-api/src/main/scala/code/actorsystem/ObpActorConfig.scala b/obp-api/src/main/scala/code/actorsystem/ObpActorConfig.scala index 848e2efd6..996d3b236 100644 --- a/obp-api/src/main/scala/code/actorsystem/ObpActorConfig.scala +++ b/obp-api/src/main/scala/code/actorsystem/ObpActorConfig.scala @@ -7,7 +7,14 @@ import code.util.Helper object ObpActorConfig { val localHostname = "127.0.0.1" - def localPort = Helper.findAvailablePort() + def localPort = { + val systemPort = APIUtil.getPropsAsIntValue("pekko.remote.artery.canonical.port", 0) + if (systemPort == 0) { + Helper.findAvailablePort() + } else { + systemPort + } + } val akka_loglevel = APIUtil.getPropsValue("remotedata.loglevel").openOr("INFO") @@ -64,12 +71,16 @@ object ObpActorConfig { } } remote { - enabled-transports = ["org.apache.pekko.remote.netty.tcp"] - netty { - tcp { - send-buffer-size = 50000000 - receive-buffer-size = 50000000 - maximum-frame-size = 52428800 + artery { + transport = tcp + canonical.hostname = """ + localHostname + """ + canonical.port = 0 + bind.hostname = """ + localHostname + """ + bind.port = 0 + advanced { + maximum-frame-size = 52428800 + buffer-pool-size = 128 + maximum-large-frame-size = 52428800 } } } @@ -80,8 +91,12 @@ object ObpActorConfig { s""" ${commonConf} pekko { - remote.netty.tcp.hostname = ${localHostname} - remote.netty.tcp.port = 0 + remote.artery { + canonical.hostname = ${localHostname} + canonical.port = 0 + bind.hostname = ${localHostname} + bind.port = 0 + } } """ @@ -89,8 +104,12 @@ object ObpActorConfig { s""" ${commonConf} pekko { - remote.netty.tcp.hostname = ${localHostname} - remote.netty.tcp.port = ${localPort} + remote.artery { + canonical.hostname = ${localHostname} + canonical.port = ${localPort} + bind.hostname = ${localHostname} + bind.port = ${localPort} + } } """ } diff --git a/obp-api/src/main/scala/code/bankconnectors/akka/actor/AkkaConnectorActorConfig.scala b/obp-api/src/main/scala/code/bankconnectors/akka/actor/AkkaConnectorActorConfig.scala index ca811607b..1925ce9d4 100644 --- a/obp-api/src/main/scala/code/bankconnectors/akka/actor/AkkaConnectorActorConfig.scala +++ b/obp-api/src/main/scala/code/bankconnectors/akka/actor/AkkaConnectorActorConfig.scala @@ -67,12 +67,16 @@ object AkkaConnectorActorConfig { } } remote { - enabled-transports = ["org.apache.pekko.remote.netty.tcp"] - netty { - tcp { - send-buffer-size = 50000000 - receive-buffer-size = 50000000 - maximum-frame-size = 52428800 + artery { + transport = tcp + canonical.hostname = "127.0.0.1" + canonical.port = 0 + bind.hostname = "127.0.0.1" + bind.port = 0 + advanced { + maximum-frame-size = 52428800 + buffer-pool-size = 128 + maximum-large-frame-size = 52428800 } } } @@ -83,8 +87,12 @@ object AkkaConnectorActorConfig { s""" ${commonConf} pekko { - remote.netty.tcp.hostname = ${localHostname} - remote.netty.tcp.port = 0 + remote.artery { + canonical.hostname = ${localHostname} + canonical.port = 0 + bind.hostname = ${localHostname} + bind.port = 0 + } } """ @@ -92,8 +100,12 @@ object AkkaConnectorActorConfig { s""" ${commonConf} pekko { - remote.netty.tcp.hostname = ${localHostname} - remote.netty.tcp.port = ${localPort} + remote.artery { + canonical.hostname = ${localHostname} + canonical.port = ${localPort} + bind.hostname = ${localHostname} + bind.port = ${localPort} + } } """ @@ -101,8 +113,12 @@ object AkkaConnectorActorConfig { s""" ${commonConf} pekko { - remote.netty.tcp.hostname = ${remoteHostname} - remote.netty.tcp.port = ${remotePort} + remote.artery { + canonical.hostname = ${remoteHostname} + canonical.port = ${remotePort} + bind.hostname = ${remoteHostname} + bind.port = ${remotePort} + } } """ } diff --git a/obp-api/src/test/scala/code/setup/ServerSetup.scala b/obp-api/src/test/scala/code/setup/ServerSetup.scala index 176ccfcd2..f6acfc8c1 100644 --- a/obp-api/src/test/scala/code/setup/ServerSetup.scala +++ b/obp-api/src/test/scala/code/setup/ServerSetup.scala @@ -60,6 +60,11 @@ trait ServerSetup extends FeatureSpec with SendServerRequests setPropsValues("berlin_group_mandatory_headers" -> "") setPropsValues("berlin_group_mandatory_header_consent" -> "") + // Set system properties to force Pekko to use random available ports + // This prevents conflicts when both RunWebApp and tests are running + System.setProperty("pekko.remote.artery.canonical.port", "0") + System.setProperty("pekko.remote.artery.bind.port", "0") + val server = TestServer def baseRequest = host(server.host, server.port) val secured = APIUtil.getPropsAsBoolValue("external.https", false)