Skip to content

Commit

Permalink
#1088 Put dynamic RMI port values into Karaf's management configurat…
Browse files Browse the repository at this point in the history
…ion file
  • Loading branch information
oliverlietz committed Aug 16, 2023
1 parent 99b01c4 commit bf5d72a
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFileExtend;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.rbc.Constants.RMI_HOST_PROPERTY;
import static org.ops4j.pax.exam.rbc.Constants.RMI_NAME_PROPERTY;
import static org.ops4j.pax.exam.rbc.Constants.RMI_PORT_PROPERTY;
Expand Down Expand Up @@ -145,19 +146,21 @@ public synchronized TestContainer start() {

Option invokerConfiguration = getInvokerConfiguration();

//registry.selectGracefully();
String host = InetAddress.getLoopbackAddress().getHostAddress();
System.setProperty("java.rmi.server.hostname", host);
int port = findFreePort();
LOGGER.info("Creating RMI registry server on {}:{}", host, port);
registry = LocateRegistry.createRegistry(port);
final int rmiRegistryPort = findFreePort();
final int rmiServerPort = findFreePort();
LOGGER.info("Creating RMI registry server on {}:{}", host, rmiRegistryPort);
registry = LocateRegistry.createRegistry(rmiRegistryPort);

ExamSystem subsystem = system
.fork(options(
systemProperty("java.rmi.server.hostname").value(host),
systemProperty(RMI_HOST_PROPERTY).value(host),
systemProperty(RMI_PORT_PROPERTY).value(Integer.toString(port)),
systemProperty(RMI_PORT_PROPERTY).value(Integer.toString(rmiRegistryPort)),
systemProperty(RMI_NAME_PROPERTY).value(name),
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", Integer.toString(rmiRegistryPort)),
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", Integer.toString(rmiServerPort)),
invokerConfiguration,
systemProperty(EXAM_INJECT_PROPERTY).value("true"),
editConfigurationFileExtend("etc/system.properties", "jline.shutdownhook",
Expand All @@ -173,7 +176,7 @@ public synchronized TestContainer start() {
ArchiveExtractor.extract(sourceDistribution, targetFolder);
}

target = new RBCRemoteTarget(name, port, subsystem.getTimeout());
target = new RBCRemoteTarget(name, rmiRegistryPort, subsystem.getTimeout());

karafBase = searchKarafBase(targetFolder);
File karafHome = karafBase;
Expand Down

0 comments on commit bf5d72a

Please sign in to comment.