Skip to content

Commit

Permalink
[#noissue] Applied dynamic property source to redis test
Browse files Browse the repository at this point in the history
  • Loading branch information
smilu97 committed May 19, 2023
1 parent 97edea0 commit 460738c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

import com.navercorp.pinpoint.pubsub.endpoint.PubSubClientFactory;
import com.navercorp.pinpoint.pubsub.endpoint.PubSubServerFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand All @@ -35,14 +35,14 @@
* @author youngjin.kim2
*/
@DisplayName("req/res based on redis pubsub")
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {RedisPubSubConfig.class})
@SpringBootTest
@Testcontainers
public class RedisPubSubReqResTest {

@Container
@SuppressWarnings("resource")
private static final GenericContainer<?> redisContainer = new GenericContainer<>(DockerImageName.parse("redis:7.0"))
private static final GenericContainer<?> REDIS_CONTAINER = new GenericContainer<>(DockerImageName.parse("redis:7.0"))
.withExposedPorts(6379)
.withReuse(true);

Expand All @@ -52,12 +52,12 @@ public class RedisPubSubReqResTest {
@Autowired
private PubSubClientFactory clientFactory;

@BeforeAll
public static void beforeAll() {
System.setProperty("spring.data.redis.host", redisContainer.getHost());
System.setProperty("spring.redis.host", redisContainer.getHost());
System.setProperty("spring.data.redis.port", redisContainer.getMappedPort(6379).toString());
System.setProperty("spring.redis.port", redisContainer.getMappedPort(6379).toString());
@DynamicPropertySource
static void redisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.redis.host", REDIS_CONTAINER::getHost);
registry.add("spring.redis.host", REDIS_CONTAINER::getHost);
registry.add("spring.data.redis.port", REDIS_CONTAINER::getFirstMappedPort);
registry.add("spring.redis.port", REDIS_CONTAINER::getFirstMappedPort);
}

@DisplayName("req/res based on redis pubsub")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import com.navercorp.pinpoint.pubsub.endpoint.PubSubServerFactory;
import com.navercorp.pinpoint.pubsub.endpoint.PubSubServiceDescriptor;
import com.navercorp.pinpoint.redis.stream.RedisStreamConfig;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand All @@ -44,14 +44,14 @@
* @author youngjin.kim2
*/
@DisplayName("req/res based on redis stream")
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {RedisStreamConfig.class})
@SpringBootTest
@Testcontainers
public class RedisStreamReqResTest {

@Container
@SuppressWarnings("resource")
private static final GenericContainer<?> redisContainer = new GenericContainer<>(DockerImageName.parse("redis:7.0"))
private static final GenericContainer<?> REDIS_CONTAINER = new GenericContainer<>(DockerImageName.parse("redis:7.0"))
.withExposedPorts(6379)
.withReuse(true);

Expand All @@ -61,12 +61,12 @@ public class RedisStreamReqResTest {
@Autowired
private PubSubClientFactory clientFactory;

@BeforeAll
public static void beforeAll() {
System.setProperty("spring.data.redis.host", redisContainer.getHost());
System.setProperty("spring.redis.host", redisContainer.getHost());
System.setProperty("spring.data.redis.port", redisContainer.getMappedPort(6379).toString());
System.setProperty("spring.redis.port", redisContainer.getMappedPort(6379).toString());
@DynamicPropertySource
static void redisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.redis.host", REDIS_CONTAINER::getHost);
registry.add("spring.redis.host", REDIS_CONTAINER::getHost);
registry.add("spring.data.redis.port", REDIS_CONTAINER::getFirstMappedPort);
registry.add("spring.redis.port", REDIS_CONTAINER::getFirstMappedPort);
}

@DisplayName("req/res based on redis stream")
Expand Down

0 comments on commit 460738c

Please sign in to comment.