Skip to content

Commit

Permalink
withCustomizer -> withCreateContainerCmdModifier. Add JavaDoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup authored and rnorth committed Mar 12, 2017
1 parent 634401d commit 7d6d200
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class GenericContainer<SELF extends GenericContainer<SELF>>

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

private final Set<Consumer<CreateContainerCmd>> createContainerCmdHooks = new HashSet<>();
private final Set<Consumer<CreateContainerCmd>> createContainerCmdMidifiers = new HashSet<>();

private static final Set<String> AVAILABLE_IMAGE_NAME_CACHE = new HashSet<>();
private static final RateLimiter DOCKER_CLIENT_RATE_LIMITER = RateLimiterBuilder
Expand Down Expand Up @@ -193,7 +193,7 @@ private void tryStart(Profiler profiler) {
profiler.start("Create container");
CreateContainerCmd createCommand = dockerClient.createContainerCmd(dockerImageName);
applyConfiguration(createCommand);
createContainerCmdHooks.forEach(hook -> hook.accept(createCommand));
createContainerCmdMidifiers.forEach(hook -> hook.accept(createCommand));

containerId = createCommand.exec().getId();
ResourceReaper.instance().registerContainerForCleanup(containerId, dockerImageName);
Expand Down Expand Up @@ -891,8 +891,16 @@ public void close() {
stop();
}

public SELF withCustomizer(Consumer<CreateContainerCmd> hook) {
createContainerCmdHooks.add(hook);
/**
* Allow low level modifications of {@link CreateContainerCmd} after it was pre-configured in {@link #tryStart(Profiler)}.
* Invocation happens eagerly on a moment when container is created.
* Warning: this does expose the underlying docker-java API so might change outside of our control.
*
* @param modifier {@link Consumer} of {@link CreateContainerCmd}.
* @return this
*/
public SELF withCreateContainerCmdModifier(Consumer<CreateContainerCmd> modifier) {
createContainerCmdMidifiers.add(modifier);
return self();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ public void createContainerCmdHookTest() {
try(
GenericContainer container = new GenericContainer<>("redis:3.0.2")
.withCommand("redis-server", "--help")
.withCustomizer(cmd -> cmd.withName("overrideMe"))
.withCreateContainerCmdModifier(cmd -> cmd.withName("overrideMe"))
// Preserves the order
.withCustomizer(cmd -> cmd.withName(randomName))
.withCreateContainerCmdModifier(cmd -> cmd.withName(randomName))
// Allows to override pre-configured values by GenericContainer
.withCustomizer(cmd -> cmd.withCmd("redis-server", "--port", "6379"))
.withCreateContainerCmdModifier(cmd -> cmd.withCmd("redis-server", "--port", "6379"))
) {
container.start();

Expand Down

0 comments on commit 7d6d200

Please sign in to comment.