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 .AfterAll ;
25
+ import org .junit .jupiter .api .BeforeAll ;
24
26
import org .junit .jupiter .api .DisplayName ;
25
27
import org .junit .jupiter .api .Test ;
26
28
import org .springframework .context .ApplicationContext ;
41
43
@ DisplayName ("req/res based on redis" )
42
44
public class RedisReqResTest {
43
45
46
+ private static GenericContainer <?> redisContainer ;
47
+
48
+ @ BeforeAll
49
+ @ SuppressWarnings ("resource" )
50
+ public static void beforeAll () {
51
+ redisContainer = new GenericContainer <>(DockerImageName .parse ("redis:7.0" ))
52
+ .withExposedPorts (6379 )
53
+ .withReuse (true );
54
+ redisContainer .start ();
55
+
56
+ System .setProperty ("spring.data.redis.host" , redisContainer .getHost ());
57
+ System .setProperty ("spring.redis.host" , redisContainer .getHost ());
58
+ System .setProperty ("spring.data.redis.port" , redisContainer .getMappedPort (6379 ).toString ());
59
+ System .setProperty ("spring.redis.port" , redisContainer .getMappedPort (6379 ).toString ());
60
+ }
61
+
62
+ @ AfterAll
63
+ public static void afterAll () {
64
+ redisContainer .stop ();
65
+ redisContainer .close ();
66
+ }
67
+
44
68
@ DisplayName ("req/res based on redis pubsub" )
45
69
@ Test
46
70
public void testRedisPubSub () {
@@ -54,31 +78,11 @@ public void testRedisStreamPubSub() {
54
78
}
55
79
56
80
private void testConfigClass (Class <?> configClass ) {
57
- runWithRedisContainer (() -> {
58
- final ApplicationContext context = new AnnotationConfigApplicationContext (configClass );
59
- testServerClientFactory (
60
- context .getBean (PubSubServerFactory .class ),
61
- context .getBean (PubSubClientFactory .class )
62
- );
63
- });
64
- }
65
-
66
- @ SuppressWarnings ("resource" )
67
- private void runWithRedisContainer (Runnable r ) {
68
- try (final GenericContainer <?> redisContainer = new GenericContainer <>(DockerImageName .parse ("redis:7.0" ))
69
- .withExposedPorts (6379 )
70
- .withReuse (true )
71
- ) {
72
- redisContainer .start ();
73
- System .setProperty ("spring.data.redis.host" , redisContainer .getHost ());
74
- System .setProperty ("spring.redis.host" , redisContainer .getHost ());
75
- System .setProperty ("spring.data.redis.port" , redisContainer .getMappedPort (6379 ).toString ());
76
- System .setProperty ("spring.redis.port" , redisContainer .getMappedPort (6379 ).toString ());
77
-
78
- r .run ();
79
-
80
- redisContainer .stop ();
81
- }
81
+ final ApplicationContext context = new AnnotationConfigApplicationContext (configClass );
82
+ testServerClientFactory (
83
+ context .getBean (PubSubServerFactory .class ),
84
+ context .getBean (PubSubClientFactory .class )
85
+ );
82
86
}
83
87
84
88
private void testServerClientFactory (
@@ -99,6 +103,7 @@ private void testServerClientFactory(
99
103
PubSubServiceDescriptor .flux ("range" , Integer .class , Integer .class );
100
104
serverFactory .build (el -> Flux .range (0 , el ), rangeService ).afterPropertiesSet ();
101
105
assertThat (syncRequestFlux (clientFactory , rangeService , 5 )).isEqualTo (List .of (0 , 1 , 2 , 3 , 4 ));
106
+ assertThat (syncRequestFlux (clientFactory , rangeService , 3 )).isEqualTo (List .of (0 , 1 , 2 ));
102
107
}
103
108
104
109
private <D , S > S syncRequestMono (
0 commit comments