-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from palantir/kill.dont.stop
Speed up test teardown
- Loading branch information
Showing
5 changed files
with
71 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...le-core/src/main/java/com/palantir/docker/compose/execution/KillDownShutdownStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
*/ | ||
|
||
package com.palantir.docker.compose.execution; | ||
|
||
import com.palantir.docker.compose.configuration.ShutdownStrategy; | ||
import java.io.IOException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Shuts down fast but cleanly by issuing a kill (fast shutdown) followed by a down (thorough cleanup) | ||
* | ||
* <p>"down" would be ideal as a single command if it didn't first execute an impotent SIGTERM, which | ||
* many Docker images simply ignore due to being run by bash as process 1. We don't need a graceful | ||
* shutdown period anyway since the tests are done and we're destroying the docker image. | ||
*/ | ||
public class KillDownShutdownStrategy implements ShutdownStrategy { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(KillDownShutdownStrategy.class); | ||
|
||
@Override | ||
public void shutdown(DockerCompose dockerCompose, Docker docker) | ||
throws IOException, InterruptedException { | ||
log.debug("Killing docker-compose cluster"); | ||
dockerCompose.kill(); | ||
log.debug("Downing docker-compose cluster"); | ||
dockerCompose.down(); | ||
log.debug("docker-compose cluster killed"); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...e/src/test/java/com/palantir/docker/compose/execution/KillDownShutdownStrategyShould.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2016 Palantir Technologies, Inc. All rights reserved. | ||
*/ | ||
|
||
package com.palantir.docker.compose.execution; | ||
|
||
import static org.mockito.Mockito.inOrder; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import com.palantir.docker.compose.configuration.ShutdownStrategy; | ||
import org.junit.Test; | ||
import org.mockito.InOrder; | ||
|
||
public class KillDownShutdownStrategyShould { | ||
|
||
@Test | ||
public void call_kill_then_down() throws Exception { | ||
DockerCompose dockerCompose = mock(DockerCompose.class); | ||
Docker docker = mock(Docker.class); | ||
|
||
ShutdownStrategy.KILL_DOWN.shutdown(dockerCompose, docker); | ||
|
||
InOrder inOrder = inOrder(dockerCompose); | ||
inOrder.verify(dockerCompose).kill(); | ||
inOrder.verify(dockerCompose).down(); | ||
inOrder.verifyNoMoreInteractions(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 8 additions & 20 deletions
28
docker-compose-rule-junit4/src/test/resources/docker-compose.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,23 @@ | ||
db: | ||
image: kiasaki/alpine-postgres | ||
environment: | ||
- "POSTGRES_DB=source" | ||
- "POSTGRES_USER=palantir" | ||
- "POSTGRES_PASSWORD=palantir" | ||
image: appropriate/nc | ||
command: /bin/sh -c 'echo server started && nc -lk 5432' | ||
ports: | ||
- "5432" | ||
|
||
db2: | ||
image: kiasaki/alpine-postgres | ||
environment: | ||
- "POSTGRES_DB=source" | ||
- "POSTGRES_USER=palantir" | ||
- "POSTGRES_PASSWORD=palantir" | ||
image: appropriate/nc | ||
command: /bin/sh -c 'echo server started && nc -lk 5432' | ||
ports: | ||
- "5432" | ||
|
||
db3: | ||
image: kiasaki/alpine-postgres | ||
environment: | ||
- "POSTGRES_DB=source" | ||
- "POSTGRES_USER=palantir" | ||
- "POSTGRES_PASSWORD=palantir" | ||
image: appropriate/nc | ||
command: /bin/sh -c 'echo server started && nc -lk 5432' | ||
ports: | ||
- "5432" | ||
|
||
db4: | ||
image: kiasaki/alpine-postgres | ||
environment: | ||
- "POSTGRES_DB=source" | ||
- "POSTGRES_USER=palantir" | ||
- "POSTGRES_PASSWORD=palantir" | ||
image: appropriate/nc | ||
command: /bin/sh -c 'echo server started && nc -lk 5432' | ||
ports: | ||
- "5432" |