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

Expose low level API #301

Merged
merged 4 commits into from
Mar 12, 2017
Merged

Expose low level API #301

merged 4 commits into from
Mar 12, 2017

Conversation

bsideup
Copy link
Member

@bsideup bsideup commented Mar 1, 2017

Makes it possible to override unsupported CreateContainerCmd properties without waiting until TestContainers adds support for it.

…eContainerCmd properties without waiting until TestContainers adds support for it.
/**
* @deprecated set by GenericContainer and should never be set outside
*/
@Deprecated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided to do the deprecations here

@@ -58,7 +58,7 @@
@EqualsAndHashCode(callSuper = false)
public class GenericContainer<SELF extends GenericContainer<SELF>>
extends FailureDetectingExternalResource
implements Container<SELF> {
implements Container<SELF>, AutoCloseable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small non-related change to simplify the testing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!

Copy link
Contributor

@vmassol vmassol Jun 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR IntelliJ IDEA is barking about this, see https://imgur.com/a/sD1WNyG ;)

(and I cannot use try with resources in my use case)

@bsideup bsideup requested a review from rnorth March 1, 2017 12:07
@bsideup bsideup self-assigned this Mar 1, 2017
@bsideup bsideup added this to the 1.1.10 milestone Mar 1, 2017
stop();
}

public SELF withCustomizer(Consumer<CreateContainerCmd> hook) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need a help with the naming here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something more verbose like withPostCreateContainerCmd()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny thing - I initially named it withCreateContainerCmdHook and then was playing with different names and accidentally committed this one :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this name too ;)
Although this name does not indicate whether this is a pre- or postcreate hook. Is it important for users of the API to know about this fact? Might be.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided to go with "post" hooks only because GenericObject does "pre" part already, and this new API just allows you to configure the final result and override some configuration. Do you have any example where "pre" hook might be helpful? Because I don't :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, don't think we need it. My point was only about the naming, including the word post makes the API a bit more self documenting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked pre/post, but actually doesn't it make it confusing wrt. what it is before or after?

This change is post- testcontainer's configuration step, but pre- creation of the container. So actually it seems to be confusing if we're not careful 😂

Some other ideas for the name: withConfigurationCustomizer, withConfigModifier or maybe even just with(Consumer<CreateContainerCmd> hook)..? (The latter would need heavier documentation so as to be more discoverable though)

I'm not sure though 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your post clarified the API a lot for me and now I agree, pre/post seems to introduce confusing semantics here.

From a general API naming standpoint, withConfigurationCustomizer and withConfigModifier both sound good, but isn't it actually more a withCreateContainerCmdModifier? Sounds awkward and very verbose, but kind of in line with the docker-java API (which seems appropriate, since docker-java does leak through this method after all).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withCreateContainerCmdModifier seems OK to me - like you say, verbose but clear.

We should probably be making it clear to the developer, through naming and javadoc comments, that this does expose the underlying docker-java API so might change outside of our control.

WDYT @bsideup ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! I'll add JavaDoc and rename the method now :)

@martin-g
Copy link

martin-g commented Mar 1, 2017

What would be the syntax for --tmpfs /var/lib/mysql:rw ?
https://vladmihalcea.com/2017/02/09/how-to-run-integration-tests-at-warp-speed-with-docker-and-tmpfs/

@bsideup
Copy link
Member Author

bsideup commented Mar 1, 2017

@martin-g I guess we have to wait until tmpfs is supported in docker-java, then it will be something like withCreateContainerCmdHook(cmd -> cmd.withTmpfs())

@martin-g
Copy link

martin-g commented Mar 1, 2017

I see. Thanks!

@@ -58,7 +58,7 @@
@EqualsAndHashCode(callSuper = false)
public class GenericContainer<SELF extends GenericContainer<SELF>>
extends FailureDetectingExternalResource
implements Container<SELF> {
implements Container<SELF>, AutoCloseable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!

public void createContainerCmdHookTest() {
// Use random name to avoid the conflicts between the tests
String randomName = Base58.randomString(5);
try(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -134,6 +134,8 @@

private List<Consumer<OutputFrame>> logConsumers = new ArrayList<>();

private final Set<Consumer<CreateContainerCmd>> createContainerCmdMidifiers = new LinkedHashSet<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling: Midifiers -> Modifiers

@rnorth
Copy link
Member

rnorth commented Mar 10, 2017

Aside from a spelling error this LGTM!

I think this warrants separate mention in the docs, though. I can try and do this at the weekend if you don't have time though - up to you.

@rnorth rnorth merged commit 570b4e8 into master Mar 12, 2017
@rnorth rnorth deleted the low_level_api branch March 12, 2017 20:05
rnorth added a commit that referenced this pull request Mar 12, 2017
## [1.2.0] - 2017-03-12
### Fixed
- Fix various escaping issues that may arise when paths contain spaces (#263, #279)
- General documentation fixes/improvements (#300, #303, #304)
- Improve reliability of `ResourceReaper` when there are a large number of containers returned by `docker ps -a` (#295)

### Changed
- Support Docker for Windows via TCP socket connection (#291, #297, #309). _Note that Docker Compose is not yet supported under Docker for Windows (see #306)
- Expose `docker-java`'s `CreateContainerCmd` API for low-level container tweaking (#301)
- Shade `org.newsclub` and Guava dependencies (#299, #292)
- Add `org.testcontainers` label to all containers created by Testcontainers (#294)
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

Successfully merging this pull request may close these issues.

None yet

5 participants