Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for starting up with a automatically selected available port #349

Closed
sparsick opened this issue Nov 5, 2020 · 3 comments
Closed
Assignees
Milestone

Comments

@sparsick
Copy link

sparsick commented Nov 5, 2020

Like Wiremock, Mockserver and Testcontainer are doing it, it would be awesome, if Greenmail could find a free port on the machine by itself. The benefit is that the developer needn't care if the needed port for Greenmail is free on the machine that running the tests.

Furthermore, the developer should have a possibility to ask Greenmail which port is selected.

Current workaround:

    private static int smtpPort = SocketUtils.findAvailableTcpPort();
    private static final ServerSetup SERVER_SETUP_SMTP = new ServerSetup(smtpPort, null, ServerSetup.PROTOCOL_SMTP);
@marcelmay
Copy link
Member

If you set the port to 0, GreenMail will actually try to find an available port (see example).

The documentation definitely needs an update describing this feature, and a convenience method for creating a ServerSetup configuration, eg ServerSetup.PROTOCOL_SMTP. dynamicPort() , similar as you suggested with WireMock. Thx alot!

@marcelmay marcelmay self-assigned this Nov 5, 2020
@marcelmay marcelmay added this to the 1.6.1 milestone Nov 5, 2020
marcelmay added a commit that referenced this issue Nov 5, 2020
…(issue #349)

- Added ServerSetup.dynamicPort()
- Server should update ServerSetup port with actual port
- Updated docs
@marcelmay
Copy link
Member

Updated example link with dynamicPort()

@sparsick
Copy link
Author

sparsick commented Nov 6, 2020

Thank you for pointing me to the example and updating the documentation. I didn't find it.

@sparsick sparsick closed this as completed Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants