4
4
import static org .junit .Assert .assertEquals ;
5
5
import static org .junit .Assert .assertNull ;
6
6
7
- import java .util .Arrays ;
8
7
import java .util .HashMap ;
8
+ import java .util .HashSet ;
9
9
import java .util .Set ;
10
10
import java .util .function .Supplier ;
11
- import java .util .stream .Collectors ;
12
11
13
12
import org .apache .commons .pool2 .impl .GenericObjectPoolConfig ;
14
13
import org .hamcrest .Matchers ;
14
+ import org .junit .After ;
15
+ import org .junit .Before ;
15
16
import org .junit .Test ;
16
17
17
18
import redis .clients .jedis .Connection ;
18
19
import redis .clients .jedis .ConnectionPoolConfig ;
19
20
import redis .clients .jedis .DefaultJedisClientConfig ;
20
21
import redis .clients .jedis .HostAndPort ;
22
+ import redis .clients .jedis .HostAndPorts ;
21
23
import redis .clients .jedis .JedisClientConfig ;
22
24
import redis .clients .jedis .JedisCluster ;
23
- import redis .clients .jedis .JedisClusterTestBase ;
24
25
25
- public class JedisClusterClientSideCacheTest extends JedisClusterTestBase {
26
+ public class JedisClusterClientSideCacheTest {
26
27
27
- private static final Set <HostAndPort > hnp = Arrays . asList ( nodeInfo1 , nodeInfo2 , nodeInfo3 ). stream (). collect ( Collectors . toSet ());
28
+ private static final Set <HostAndPort > hnp = new HashSet <>( HostAndPorts . getStableClusterServers ());
28
29
29
30
private static final Supplier <JedisClientConfig > clientConfig
30
31
= () -> DefaultJedisClientConfig .builder ().resp3 ().password ("cluster" ).build ();
@@ -36,12 +37,25 @@ public class JedisClusterClientSideCacheTest extends JedisClusterTestBase {
36
37
return poolConfig ;
37
38
};
38
39
40
+ protected JedisCluster control ;
41
+
42
+ @ Before
43
+ public void setUp () throws Exception {
44
+ control = new JedisCluster (hnp , clientConfig .get ());
45
+ control .flushAll ();
46
+ }
47
+
48
+ @ After
49
+ public void tearDown () throws Exception {
50
+ control .close ();
51
+ }
52
+
39
53
@ Test
40
54
public void simple () {
41
55
try (JedisCluster jedis = new JedisCluster (hnp , clientConfig .get (), new MapClientSideCache ())) {
42
- jedis .set ("foo" , "bar" );
56
+ control .set ("foo" , "bar" );
43
57
assertEquals ("bar" , jedis .get ("foo" ));
44
- jedis .del ("foo" );
58
+ control .del ("foo" );
45
59
assertThat (jedis .get ("foo" ), Matchers .oneOf ("bar" , null )); // ?
46
60
}
47
61
}
@@ -51,11 +65,11 @@ public void simpleWithSimpleMap() {
51
65
HashMap <Long , Object > map = new HashMap <>();
52
66
try (JedisCluster jedis = new JedisCluster (hnp , clientConfig .get (), new MapClientSideCache (map ),
53
67
singleConnectionPoolConfig .get ())) {
54
- jedis .set ("foo" , "bar" );
68
+ control .set ("foo" , "bar" );
55
69
assertThat (map , Matchers .aMapWithSize (0 ));
56
70
assertEquals ("bar" , jedis .get ("foo" ));
57
71
assertThat (map , Matchers .aMapWithSize (1 ));
58
- jedis .del ("foo" );
72
+ control .del ("foo" );
59
73
assertThat (map , Matchers .aMapWithSize (1 ));
60
74
assertEquals ("bar" , jedis .get ("foo" ));
61
75
assertThat (map , Matchers .aMapWithSize (1 ));
@@ -69,9 +83,9 @@ public void simpleWithSimpleMap() {
69
83
@ Test
70
84
public void flushAll () {
71
85
try (JedisCluster jedis = new JedisCluster (hnp , clientConfig .get (), new MapClientSideCache ())) {
72
- jedis .set ("foo" , "bar" );
86
+ control .set ("foo" , "bar" );
73
87
assertEquals ("bar" , jedis .get ("foo" ));
74
- jedis .flushAll ();
88
+ control .flushAll ();
75
89
assertThat (jedis .get ("foo" ), Matchers .oneOf ("bar" , null )); // ?
76
90
}
77
91
}
@@ -81,11 +95,11 @@ public void flushAllWithSimpleMap() {
81
95
HashMap <Long , Object > map = new HashMap <>();
82
96
try (JedisCluster jedis = new JedisCluster (hnp , clientConfig .get (), new MapClientSideCache (map ),
83
97
singleConnectionPoolConfig .get ())) {
84
- jedis .set ("foo" , "bar" );
98
+ control .set ("foo" , "bar" );
85
99
assertThat (map , Matchers .aMapWithSize (0 ));
86
100
assertEquals ("bar" , jedis .get ("foo" ));
87
101
assertThat (map , Matchers .aMapWithSize (1 ));
88
- jedis .flushAll ();
102
+ control .flushAll ();
89
103
assertThat (map , Matchers .aMapWithSize (1 ));
90
104
assertEquals ("bar" , jedis .get ("foo" ));
91
105
assertThat (map , Matchers .aMapWithSize (1 ));
0 commit comments