Replies: 4 comments 1 reply
-
|
The reason port fields in modules like
For the Arconia use case, if you need to extend a module and reference the port: public class CustomPostgresContainer extends PostgreSQLContainer<CustomPostgresContainer> {
private static final int CUSTOM_PORT = 5432;
public CustomPostgresContainer() {
super();
addExposedPort(CUSTOM_PORT);
}
}Alternatively, you could open a PR to add |
Beta Was this translation helpful? Give feedback.
-
|
placeholder |
Beta Was this translation helpful? Give feedback.
-
|
I was a bit unclear. I meant that the constants are now private but they should be protected so that classes inheriting can access them. |
Beta Was this translation helpful? Give feedback.
-
|
It seems there’s a clear consensus that the current inconsistency across modules (where some ports are public and others are private) creates friction for developers extending these classes. Aligning these constants to public static final or at least protected static final would be the best approach for a few reasons: Dry Principle: It prevents developers from having to redeclare standard ports (like 5672 or 5432) in their subclasses, reducing hardcoded magic numbers. API Consistency: As @ThomasVitale pointed out, modules like PostgreSQL already expose these as public. Standardizing this across Oracle, Artemis, and others makes the library more predictable. Refactoring Safety: If a default port ever needs to change in a future version of a container image, users who reference the constant will get the update automatically, whereas those who hardcoded the value will face silent failures. A good middle ground would be providing protected getters (e.g., getDefaultPort()) if we want to keep the fields encapsulated, but since these are industry-standard constants, making the static final fields public or protected is a very common and safe pattern in Testcontainers. Would the maintainers be open to a PR that standardizes these access modifiers across all container modules? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to contribute to Arconia and noticed that the port number in the different Container classes are private.
E.g. for
RabbitMQContainerThis causes some duplication of code when such as class is extended and the subclass has the add those constants again.
Would it be possible to be a bit more lenient with the access and change it to
protected?Beta Was this translation helpful? Give feedback.
All reactions