-
Notifications
You must be signed in to change notification settings - Fork 0
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 #2 from joon6093/1.0.x
Release v1.0.1
- Loading branch information
Showing
5 changed files
with
85 additions
and
40 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
12 changes: 0 additions & 12 deletions
12
handler/src/main/java/io/jeyong/handler/HandlerApplication.java
This file was deleted.
Oops, something went wrong.
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
75 changes: 75 additions & 0 deletions
75
test/src/test/java/io/jeyong/test/SigtermListenerTest.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,75 @@ | ||
package io.jeyong.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.images.builder.ImageFromDockerfile; | ||
|
||
@SpringBootTest | ||
public class SigtermListenerTest { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(SigtermListenerTest.class); | ||
|
||
@Test | ||
void testSigtermHandling() throws Exception { | ||
// given | ||
Path tempDir = Files.createTempDirectory("docker-context"); | ||
copyFile("../gradlew", tempDir.resolve("gradlew")); | ||
copyDirectory("../gradle", tempDir.resolve("gradle")); | ||
copyFile("../settings.gradle", tempDir.resolve("settings.gradle")); | ||
copyDirectory("../handler", tempDir.resolve("handler")); | ||
copyDirectory("../test", tempDir.resolve("test")); | ||
|
||
ImageFromDockerfile image = new ImageFromDockerfile() | ||
.withFileFromPath(".", tempDir) | ||
.withDockerfileFromBuilder(builder -> { | ||
builder.from("eclipse-temurin:17") | ||
.workDir("/app") | ||
.copy("gradlew", "/app/gradlew") | ||
.copy("gradle", "/app/gradle") | ||
.copy("settings.gradle", "/app/settings.gradle") | ||
.copy("handler", "/app/handler") | ||
.copy("test", "/app/test") | ||
.run("chmod +x ./gradlew") | ||
.run("./gradlew bootJar") | ||
.cmd("java", "-jar", "/app/test/build/libs/test-0.0.1-SNAPSHOT.jar") | ||
.build(); | ||
}); | ||
|
||
// when | ||
try (GenericContainer<?> container = new GenericContainer<>(image) | ||
.withLogConsumer(new Slf4jLogConsumer(logger))) { | ||
container.start(); | ||
sendSigtermToContainer(container); | ||
|
||
// then | ||
Integer exitCode = container.getCurrentContainerInfo().getState().getExitCode(); | ||
assertThat(exitCode).isEqualTo(0); | ||
} | ||
} | ||
|
||
private void sendSigtermToContainer(GenericContainer<?> container) { | ||
String containerId = container.getContainerId(); | ||
container.getDockerClient() | ||
.killContainerCmd(containerId) | ||
.withSignal("SIGTERM") | ||
.exec(); | ||
} | ||
|
||
private void copyFile(String source, Path destination) throws Exception { | ||
FileUtils.copyFile(new File(source), destination.toFile()); | ||
} | ||
|
||
private void copyDirectory(String source, Path destination) throws Exception { | ||
FileUtils.copyDirectory(new File(source), destination.toFile()); | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
test/src/test/java/io/jeyong/test/TestApplicationTests.java
This file was deleted.
Oops, something went wrong.