Skip to content

Commit 767fc01

Browse files
authored
Fix client side cache tests (#3799)
Due to redis/redis#13167 * Fix JedisClusterClientSideCacheTest * Fix JedisSentineledClientSideCacheTest
1 parent b7881ac commit 767fc01

File tree

2 files changed

+52
-23
lines changed

2 files changed

+52
-23
lines changed

src/test/java/redis/clients/jedis/csc/JedisClusterClientSideCacheTest.java

+27-13
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@
44
import static org.junit.Assert.assertEquals;
55
import static org.junit.Assert.assertNull;
66

7-
import java.util.Arrays;
87
import java.util.HashMap;
8+
import java.util.HashSet;
99
import java.util.Set;
1010
import java.util.function.Supplier;
11-
import java.util.stream.Collectors;
1211

1312
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
1413
import org.hamcrest.Matchers;
14+
import org.junit.After;
15+
import org.junit.Before;
1516
import org.junit.Test;
1617

1718
import redis.clients.jedis.Connection;
1819
import redis.clients.jedis.ConnectionPoolConfig;
1920
import redis.clients.jedis.DefaultJedisClientConfig;
2021
import redis.clients.jedis.HostAndPort;
22+
import redis.clients.jedis.HostAndPorts;
2123
import redis.clients.jedis.JedisClientConfig;
2224
import redis.clients.jedis.JedisCluster;
23-
import redis.clients.jedis.JedisClusterTestBase;
2425

25-
public class JedisClusterClientSideCacheTest extends JedisClusterTestBase {
26+
public class JedisClusterClientSideCacheTest {
2627

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());
2829

2930
private static final Supplier<JedisClientConfig> clientConfig
3031
= () -> DefaultJedisClientConfig.builder().resp3().password("cluster").build();
@@ -36,12 +37,25 @@ public class JedisClusterClientSideCacheTest extends JedisClusterTestBase {
3637
return poolConfig;
3738
};
3839

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+
3953
@Test
4054
public void simple() {
4155
try (JedisCluster jedis = new JedisCluster(hnp, clientConfig.get(), new MapClientSideCache())) {
42-
jedis.set("foo", "bar");
56+
control.set("foo", "bar");
4357
assertEquals("bar", jedis.get("foo"));
44-
jedis.del("foo");
58+
control.del("foo");
4559
assertThat(jedis.get("foo"), Matchers.oneOf("bar", null)); // ?
4660
}
4761
}
@@ -51,11 +65,11 @@ public void simpleWithSimpleMap() {
5165
HashMap<Long, Object> map = new HashMap<>();
5266
try (JedisCluster jedis = new JedisCluster(hnp, clientConfig.get(), new MapClientSideCache(map),
5367
singleConnectionPoolConfig.get())) {
54-
jedis.set("foo", "bar");
68+
control.set("foo", "bar");
5569
assertThat(map, Matchers.aMapWithSize(0));
5670
assertEquals("bar", jedis.get("foo"));
5771
assertThat(map, Matchers.aMapWithSize(1));
58-
jedis.del("foo");
72+
control.del("foo");
5973
assertThat(map, Matchers.aMapWithSize(1));
6074
assertEquals("bar", jedis.get("foo"));
6175
assertThat(map, Matchers.aMapWithSize(1));
@@ -69,9 +83,9 @@ public void simpleWithSimpleMap() {
6983
@Test
7084
public void flushAll() {
7185
try (JedisCluster jedis = new JedisCluster(hnp, clientConfig.get(), new MapClientSideCache())) {
72-
jedis.set("foo", "bar");
86+
control.set("foo", "bar");
7387
assertEquals("bar", jedis.get("foo"));
74-
jedis.flushAll();
88+
control.flushAll();
7589
assertThat(jedis.get("foo"), Matchers.oneOf("bar", null)); // ?
7690
}
7791
}
@@ -81,11 +95,11 @@ public void flushAllWithSimpleMap() {
8195
HashMap<Long, Object> map = new HashMap<>();
8296
try (JedisCluster jedis = new JedisCluster(hnp, clientConfig.get(), new MapClientSideCache(map),
8397
singleConnectionPoolConfig.get())) {
84-
jedis.set("foo", "bar");
98+
control.set("foo", "bar");
8599
assertThat(map, Matchers.aMapWithSize(0));
86100
assertEquals("bar", jedis.get("foo"));
87101
assertThat(map, Matchers.aMapWithSize(1));
88-
jedis.flushAll();
102+
control.flushAll();
89103
assertThat(map, Matchers.aMapWithSize(1));
90104
assertEquals("bar", jedis.get("foo"));
91105
assertThat(map, Matchers.aMapWithSize(1));

src/test/java/redis/clients/jedis/csc/JedisSentineledClientSideCacheTest.java

+25-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
import java.util.Arrays;
88
import java.util.HashMap;
9+
import java.util.HashSet;
910
import java.util.Set;
10-
import java.util.stream.Collectors;
1111
import org.hamcrest.Matchers;
12+
import org.junit.After;
13+
import org.junit.Before;
1214
import org.junit.Test;
1315

1416
import redis.clients.jedis.DefaultJedisClientConfig;
@@ -24,19 +26,32 @@ public class JedisSentineledClientSideCacheTest {
2426
protected static final HostAndPort sentinel1 = HostAndPorts.getSentinelServers().get(1);
2527
protected static final HostAndPort sentinel2 = HostAndPorts.getSentinelServers().get(3);
2628

27-
private static final Set<HostAndPort> sentinels = Arrays.asList(sentinel1, sentinel2).stream().collect(Collectors.toSet());
29+
private static final Set<HostAndPort> sentinels = new HashSet<>(Arrays.asList(sentinel1, sentinel2));
2830

2931
private static final JedisClientConfig masterClientConfig = DefaultJedisClientConfig.builder().resp3().password("foobared").build();
3032

3133
private static final JedisClientConfig sentinelClientConfig = DefaultJedisClientConfig.builder().resp3().build();
3234

35+
protected JedisSentineled control;
36+
37+
@Before
38+
public void setUp() throws Exception {
39+
control = new JedisSentineled(MASTER_NAME, masterClientConfig, sentinels, sentinelClientConfig);
40+
control.flushAll();
41+
}
42+
43+
@After
44+
public void tearDown() throws Exception {
45+
control.close();
46+
}
47+
3348
@Test
3449
public void simple() {
3550
try (JedisSentineled jedis = new JedisSentineled(MASTER_NAME, masterClientConfig, new MapClientSideCache(),
3651
sentinels, sentinelClientConfig)) {
37-
jedis.set("foo", "bar");
52+
control.set("foo", "bar");
3853
assertEquals("bar", jedis.get("foo"));
39-
jedis.del("foo");
54+
control.del("foo");
4055
assertThat(jedis.get("foo"), Matchers.oneOf("bar", null)); // ?
4156
}
4257
}
@@ -46,11 +61,11 @@ public void simpleWithSimpleMap() {
4661
HashMap<Long, Object> map = new HashMap<>();
4762
try (JedisSentineled jedis = new JedisSentineled(MASTER_NAME, masterClientConfig, new MapClientSideCache(map),
4863
sentinels, sentinelClientConfig)) {
49-
jedis.set("foo", "bar");
64+
control.set("foo", "bar");
5065
assertThat(map, Matchers.aMapWithSize(0));
5166
assertEquals("bar", jedis.get("foo"));
5267
assertThat(map, Matchers.aMapWithSize(1));
53-
jedis.del("foo");
68+
control.del("foo");
5469
assertThat(map, Matchers.aMapWithSize(1));
5570
assertEquals("bar", jedis.get("foo"));
5671
assertThat(map, Matchers.aMapWithSize(1));
@@ -65,9 +80,9 @@ public void simpleWithSimpleMap() {
6580
public void flushAll() {
6681
try (JedisSentineled jedis = new JedisSentineled(MASTER_NAME, masterClientConfig, new MapClientSideCache(),
6782
sentinels, sentinelClientConfig)) {
68-
jedis.set("foo", "bar");
83+
control.set("foo", "bar");
6984
assertEquals("bar", jedis.get("foo"));
70-
jedis.flushAll();
85+
control.flushAll();
7186
assertThat(jedis.get("foo"), Matchers.oneOf("bar", null)); // ?
7287
}
7388
}
@@ -77,11 +92,11 @@ public void flushAllWithSimpleMap() {
7792
HashMap<Long, Object> map = new HashMap<>();
7893
try (JedisSentineled jedis = new JedisSentineled(MASTER_NAME, masterClientConfig, new MapClientSideCache(map),
7994
sentinels, sentinelClientConfig)) {
80-
jedis.set("foo", "bar");
95+
control.set("foo", "bar");
8196
assertThat(map, Matchers.aMapWithSize(0));
8297
assertEquals("bar", jedis.get("foo"));
8398
assertThat(map, Matchers.aMapWithSize(1));
84-
jedis.flushAll();
99+
control.flushAll();
85100
assertThat(map, Matchers.aMapWithSize(1));
86101
assertEquals("bar", jedis.get("foo"));
87102
assertThat(map, Matchers.aMapWithSize(1));

0 commit comments

Comments
 (0)