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
Improve available port discovery in tests #3555
Conversation
private static String getCallerClassName() { | ||
return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE) | ||
.walk(s -> s.map(StackWalker.StackFrame::getClassName) | ||
.filter(className -> !className.equals(AvailablePortFinder.class.getName())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we make AvailablePortFinder class final, to better match the assumption made on the above line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we make AvailablePortFinder class final
The class declaration is:
public final class AvailablePortFinder {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filtering on className should be enough then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class declaration is:
public final class AvailablePortFinder { }
I am blind. Sorry for the noise.
...ts-support/test-support/src/main/java/org/apache/camel/quarkus/test/AvailablePortFinder.java
Show resolved
Hide resolved
LOGGER.info("getNextAvailable() -> {}", port); | ||
return port; | ||
String callerClassName = getCallerClassName(); | ||
String value = RESERVED_PORTS.putIfAbsent(port, callerClassName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this making some assumptions about whether this class can concurrently exist in multiple JVMs or multiple class loaders within a single maven invocation? IIRC surefire is forking a new JVM for each Maven module. So if building with mvnd, the AvailablePortFinder class (and thus also separate RESERVED_PORTS instances) may exist in several concurrent JVMs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate a bit more? It's not entirely clear to me why it matters in this context.
All it's doing is trying to track which class reserved a specific port. Arguably we don't need to do that. It just provides some nice logging output and a way to clear out stale entries from the RESERVED_PORTS
map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - after re-reading. It's about separate RESERVED_PORTS
instances.
In which case, yes, I suppose the map contents would be different between concurrent JVMs or class loaders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining. If it is just for logging, indeed, multiple RESERVED_PORTS instances in concurrent per-module JVMs do not matter.
No description provided.