Description
ApacheDS's TcpTransport
allows for a zero port, selecting any available port at startup. It does not correctly propagate that port up through the object graph, though.
For example, giving a TcpTransport
a port of zero:
server = new LdapServer();
TcpTransport transport = new TcpTransport(port);
server.setTransports(transport);
server.start();
will result in a server that is listening on a random port, but server.getPort()
still returns 0
.
Because ApacheDS has not had a GA release in many years, it's unlikely that this enhancement will get applied to the ApacheDS project.
Still, it would be nice if ApacheDSContainer
could accept 0
as a port value. One immediate benefit from this is reducing the likelihood of a port collision when multiple LDAP servers are started up simultaneously.
For this to happen, the following test would need to pass:
ApacheDSContainer container = new ApacheDSContainer("dc=springframework,dc=org",
"classpath:test-server.ldif");
container.setPort(0);
container.afterPropertiesSet();
assertNotEquals(container.getPort(), 0);
assertNotEquals(container.server.getPort(), 0);
assertNotEquals(container.server.getPortSSL(), 0);
It may be possible to post-process the server
instance in ApacheDSContainer#afterPropertiesSet
into a state where the selected port is correctly returned.
Note that UnboundIdContainerTests
has a test that would likely be good to port over into ApacheDSContainerTests
for testing this feature.