diff --git a/.github/workflows/boot-jpa-hibernate2ndlevelcache-sample.yml b/.github/workflows/boot-jpa-hibernate2ndlevelcache-sample.yml index bd9935c6b..dd7453164 100644 --- a/.github/workflows/boot-jpa-hibernate2ndlevelcache-sample.yml +++ b/.github/workflows/boot-jpa-hibernate2ndlevelcache-sample.yml @@ -31,11 +31,5 @@ jobs: java-version: 21 distribution: "temurin" cache: "maven" - - name: Start up redis via Docker Compose - run: | - cd docker - docker compose up -d redis - sleep 5 - docker ps -a - name: Build and analyze run: ./mvnw clean verify diff --git a/.vscode/launch.json b/.vscode/launch.json index 939849c22..94ef3969b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -113,6 +113,16 @@ "projectName": "boot-shedlock-sample", "args": "--spring.profiles.active=local", "envFile": "${workspaceFolder}/.env" + }, + { + "type": "java", + "name": "Spring Boot-TestApplication", + "request": "launch", + "cwd": "${workspaceFolder}", + "mainClass": "com.example.hibernatecache.TestApplication", + "projectName": "boot-hibernate2ndlevelcache-sample", + "args": "", + "envFile": "${workspaceFolder}/.env" } ] } \ No newline at end of file diff --git a/boot-ultimate-redis/src/test/java/com/example/ultimateredis/TestUltimateRedisApplication.java b/boot-ultimate-redis/src/test/java/com/example/ultimateredis/TestUltimateRedisApplication.java index 50996b8cb..aa76830d0 100644 --- a/boot-ultimate-redis/src/test/java/com/example/ultimateredis/TestUltimateRedisApplication.java +++ b/boot-ultimate-redis/src/test/java/com/example/ultimateredis/TestUltimateRedisApplication.java @@ -14,12 +14,12 @@ class TestUltimateRedisApplication { @Bean @ServiceConnection(name = "redis") GenericContainer redisContainer(DynamicPropertyRegistry dynamicPropertyRegistry) { - GenericContainer redisContiner = + GenericContainer redisContainer = new GenericContainer<>(DockerImageName.parse("redis").withTag("7.2.5-alpine")) .withExposedPorts(6379); - dynamicPropertyRegistry.add("cache.redis-port", () -> redisContiner.getMappedPort(6379)); - dynamicPropertyRegistry.add("cache.redis-host", redisContiner::getHost); - return redisContiner; + dynamicPropertyRegistry.add("cache.redis-port", () -> redisContainer.getMappedPort(6379)); + dynamicPropertyRegistry.add("cache.redis-host", redisContainer::getHost); + return redisContainer; } public static void main(String[] args) { diff --git a/jpa/boot-hibernate2ndlevelcache-sample/src/test/java/com/example/hibernatecache/TestApplication.java b/jpa/boot-hibernate2ndlevelcache-sample/src/test/java/com/example/hibernatecache/TestApplication.java index 5f4024cfb..ab97cc880 100644 --- a/jpa/boot-hibernate2ndlevelcache-sample/src/test/java/com/example/hibernatecache/TestApplication.java +++ b/jpa/boot-hibernate2ndlevelcache-sample/src/test/java/com/example/hibernatecache/TestApplication.java @@ -1,15 +1,46 @@ package com.example.hibernatecache; import com.example.hibernatecache.common.ContainersConfig; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import org.springframework.boot.SpringApplication; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.testcontainers.context.ImportTestcontainers; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; +import org.springframework.core.io.ClassPathResource; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.utility.DockerImageName; @TestConfiguration(proxyBeanMethods = false) @ImportTestcontainers(ContainersConfig.class) public class TestApplication { + @Bean + @ServiceConnection(name = "redis") + GenericContainer redisContainer() throws IOException { + GenericContainer redisContainer = + new GenericContainer<>(DockerImageName.parse("redis").withTag("7.2.5-alpine")) + .withExposedPorts(6379); + redisContainer.start(); + String ymlContent = + """ + singleServerConfig: + address: "redis://%s:%d" + """; + String finalYml = + ymlContent.formatted(redisContainer.getHost(), redisContainer.getMappedPort(6379)); + String resourcesPath = new ClassPathResource("").getURL().getPath(); + String yamlFilePath = resourcesPath + "redisson-test.yml"; + try (FileWriter writer = new FileWriter(new File(yamlFilePath))) { + writer.write(finalYml); + } + return redisContainer; + } + public static void main(String[] args) { + System.setProperty("spring.profiles.active", "test"); SpringApplication.from(Application::main).with(TestApplication.class).run(args); } } diff --git a/jpa/boot-hibernate2ndlevelcache-sample/src/test/java/com/example/hibernatecache/common/ContainersConfig.java b/jpa/boot-hibernate2ndlevelcache-sample/src/test/java/com/example/hibernatecache/common/ContainersConfig.java index 3c3035091..b969ed5d2 100644 --- a/jpa/boot-hibernate2ndlevelcache-sample/src/test/java/com/example/hibernatecache/common/ContainersConfig.java +++ b/jpa/boot-hibernate2ndlevelcache-sample/src/test/java/com/example/hibernatecache/common/ContainersConfig.java @@ -6,5 +6,5 @@ public interface ContainersConfig { @ServiceConnection - PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>("postgres:16.2-alpine"); + PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>("postgres:16.3-alpine"); } diff --git a/jpa/boot-hibernate2ndlevelcache-sample/src/test/resources/redisson-test.yml b/jpa/boot-hibernate2ndlevelcache-sample/src/test/resources/redisson-test.yml deleted file mode 100644 index ab834b4cb..000000000 --- a/jpa/boot-hibernate2ndlevelcache-sample/src/test/resources/redisson-test.yml +++ /dev/null @@ -1,2 +0,0 @@ -singleServerConfig: - address: "redis://localhost:6379"