21
21
import com .navercorp .pinpoint .pubsub .endpoint .PubSubServerFactory ;
22
22
import com .navercorp .pinpoint .pubsub .endpoint .PubSubServiceDescriptor ;
23
23
import com .navercorp .pinpoint .redis .stream .RedisStreamConfig ;
24
- import org .junit .jupiter .api .BeforeAll ;
25
24
import org .junit .jupiter .api .DisplayName ;
26
25
import org .junit .jupiter .api .Test ;
27
- import org .junit .jupiter .api .extension .ExtendWith ;
28
26
import org .springframework .beans .factory .annotation .Autowired ;
27
+ import org .springframework .boot .test .context .SpringBootTest ;
29
28
import org .springframework .test .context .ContextConfiguration ;
30
- import org .springframework .test .context .junit .jupiter .SpringExtension ;
29
+ import org .springframework .test .context .DynamicPropertyRegistry ;
30
+ import org .springframework .test .context .DynamicPropertySource ;
31
31
import org .testcontainers .containers .GenericContainer ;
32
32
import org .testcontainers .junit .jupiter .Container ;
33
33
import org .testcontainers .junit .jupiter .Testcontainers ;
44
44
* @author youngjin.kim2
45
45
*/
46
46
@ DisplayName ("req/res based on redis stream" )
47
- @ ExtendWith (SpringExtension .class )
48
47
@ ContextConfiguration (classes = {RedisStreamConfig .class })
48
+ @ SpringBootTest
49
49
@ Testcontainers
50
50
public class RedisStreamReqResTest {
51
51
52
52
@ Container
53
53
@ SuppressWarnings ("resource" )
54
- private static final GenericContainer <?> redisContainer = new GenericContainer <>(DockerImageName .parse ("redis:7.0" ))
54
+ private static final GenericContainer <?> REDIS_CONTAINER = new GenericContainer <>(DockerImageName .parse ("redis:7.0" ))
55
55
.withExposedPorts (6379 )
56
56
.withReuse (true );
57
57
@@ -61,12 +61,12 @@ public class RedisStreamReqResTest {
61
61
@ Autowired
62
62
private PubSubClientFactory clientFactory ;
63
63
64
- @ BeforeAll
65
- public static void beforeAll ( ) {
66
- System . setProperty ("spring.data.redis.host" , redisContainer . getHost () );
67
- System . setProperty ("spring.redis.host" , redisContainer . getHost () );
68
- System . setProperty ("spring.data.redis.port" , redisContainer . getMappedPort ( 6379 ). toString () );
69
- System . setProperty ("spring.redis.port" , redisContainer . getMappedPort ( 6379 ). toString () );
64
+ @ DynamicPropertySource
65
+ static void redisProperties ( DynamicPropertyRegistry registry ) {
66
+ registry . add ("spring.data.redis.host" , REDIS_CONTAINER :: getHost );
67
+ registry . add ("spring.redis.host" , REDIS_CONTAINER :: getHost );
68
+ registry . add ("spring.data.redis.port" , REDIS_CONTAINER :: getFirstMappedPort );
69
+ registry . add ("spring.redis.port" , REDIS_CONTAINER :: getFirstMappedPort );
70
70
}
71
71
72
72
@ DisplayName ("req/res based on redis stream" )
0 commit comments