Skip to content

Commit

Permalink
Merge pull request #231 from zeroturnaround/manual-reaper
Browse files Browse the repository at this point in the history
Expose reaper's trigger to public API
  • Loading branch information
rnorth committed Nov 7, 2016
2 parents ba15667 + a6f6d82 commit 4e284ec
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/src/main/java/org/testcontainers/utility/ResourceReaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ private ResourceReaper() {
dockerClient = DockerClientFactory.instance().client();

// If the JVM stops without containers being stopped, try and stop the container.
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
registeredContainers.forEach(this::stopContainer);
registeredNetworks.forEach(this::removeNetwork);
}));
Runtime.getRuntime().addShutdownHook(new Thread(this::performCleanup));
}

public synchronized static ResourceReaper instance() {
Expand All @@ -44,6 +41,15 @@ public synchronized static ResourceReaper instance() {
return instance;
}

/**
* Perform a cleanup.
*
*/
public synchronized void performCleanup() {
registeredContainers.forEach(this::stopContainer);
registeredNetworks.forEach(this::removeNetwork);
}

/**
* Register a container to be cleaned up, either on explicit call to stopAndRemoveContainer, or at JVM shutdown.
*
Expand Down

0 comments on commit 4e284ec

Please sign in to comment.