Skip to content

Commit d2d39b7

Browse files
committed
IGNITE-28444: Fix deprecated Jedis pool usage in Redis tests
1 parent 92b7fb3 commit d2d39b7

File tree

6 files changed

+70
-54
lines changed

6 files changed

+70
-54
lines changed

modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisCommonAbstractTest.java

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import redis.clients.jedis.ClientSetInfoConfig;
2626
import redis.clients.jedis.DefaultJedisClientConfig;
2727
import redis.clients.jedis.HostAndPort;
28-
import redis.clients.jedis.JedisPool;
29-
import redis.clients.jedis.JedisPoolConfig;
28+
import redis.clients.jedis.Jedis;
3029

3130
/**
3231
* Common for all Redis tests.
@@ -41,8 +40,8 @@ public class RedisCommonAbstractTest extends GridCommonAbstractTest {
4140
/** Port. */
4241
protected static final int PORT = 6379;
4342

44-
/** Pool. */
45-
protected static JedisPool pool;
43+
/** Redis client factory. */
44+
protected static RedisClientFactory redisClientFactory;
4645

4746
/** Default Redis cache name. */
4847
private static final String DFLT_CACHE_NAME = "redis-ignite-internal-cache-0";
@@ -51,29 +50,19 @@ public class RedisCommonAbstractTest extends GridCommonAbstractTest {
5150
@Override protected void beforeTestsStarted() throws Exception {
5251
startGrids(gridCount());
5352

54-
JedisPoolConfig jedisPoolCfg = new JedisPoolConfig();
55-
56-
jedisPoolCfg.setMaxWaitMillis(20000);
57-
jedisPoolCfg.setMaxIdle(100);
58-
jedisPoolCfg.setMinIdle(1);
59-
jedisPoolCfg.setNumTestsPerEvictionRun(10);
60-
jedisPoolCfg.setTestOnBorrow(true);
61-
jedisPoolCfg.setTestOnReturn(true);
62-
jedisPoolCfg.setTestWhileIdle(true);
63-
jedisPoolCfg.setTimeBetweenEvictionRunsMillis(30000);
64-
65-
DefaultJedisClientConfig clientCfg = DefaultJedisClientConfig.builder()
66-
.connectionTimeoutMillis(10000)
67-
.socketTimeoutMillis(10000)
68-
.clientSetInfoConfig(ClientSetInfoConfig.DISABLED)
69-
.build();
70-
71-
pool = new JedisPool(jedisPoolCfg, new HostAndPort(HOST, PORT), clientCfg);
53+
redisClientFactory = new RedisClientFactory(
54+
new HostAndPort(HOST, PORT),
55+
DefaultJedisClientConfig.builder()
56+
.connectionTimeoutMillis(10000)
57+
.socketTimeoutMillis(10000)
58+
.clientSetInfoConfig(ClientSetInfoConfig.DISABLED)
59+
.build()
60+
);
7261
}
7362

7463
/** {@inheritDoc} */
7564
@Override protected void afterTestsStopped() throws Exception {
76-
pool.destroy();
65+
redisClientFactory = null;
7766
}
7867

7968
/** {@inheritDoc} */
@@ -91,7 +80,7 @@ public class RedisCommonAbstractTest extends GridCommonAbstractTest {
9180

9281
cfg.setConnectorConfiguration(redisCfg);
9382

94-
CacheConfiguration ccfg = defaultCacheConfiguration();
83+
CacheConfiguration<String, String> ccfg = defaultCacheConfiguration();
9584

9685
ccfg.setStatisticsEnabled(true);
9786
ccfg.setIndexedTypes(String.class, String.class);
@@ -125,4 +114,31 @@ protected int gridCount() {
125114

126115
assertTrue(jcache().localSize() == 0);
127116
}
117+
118+
/**
119+
* Lightweight Redis connection factory.
120+
*/
121+
protected static class RedisClientFactory {
122+
/** Redis address. */
123+
private final HostAndPort addr;
124+
125+
/** Client config. */
126+
private final DefaultJedisClientConfig cfg;
127+
128+
/**
129+
* @param addr Redis address.
130+
* @param cfg Client config.
131+
*/
132+
RedisClientFactory(HostAndPort addr, DefaultJedisClientConfig cfg) {
133+
this.addr = addr;
134+
this.cfg = cfg;
135+
}
136+
137+
/**
138+
* @return Redis client.
139+
*/
140+
Jedis getResource() {
141+
return new Jedis(addr, cfg);
142+
}
143+
}
128144
}

modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisProtocolConnectSelfTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class RedisProtocolConnectSelfTest extends RedisCommonAbstractTest {
3333
*/
3434
@Test
3535
public void testPing() throws Exception {
36-
try (Jedis jedis = pool.getResource()) {
36+
try (Jedis jedis = redisClientFactory.getResource()) {
3737
Assert.assertEquals("PONG", jedis.ping());
3838
}
3939
}
@@ -43,7 +43,7 @@ public void testPing() throws Exception {
4343
*/
4444
@Test
4545
public void testEcho() throws Exception {
46-
try (Jedis jedis = pool.getResource()) {
46+
try (Jedis jedis = redisClientFactory.getResource()) {
4747
Assert.assertEquals("Hello, grid!", jedis.echo("Hello, grid!"));
4848
}
4949
}
@@ -53,7 +53,7 @@ public void testEcho() throws Exception {
5353
*/
5454
@Test
5555
public void testSelect() throws Exception {
56-
try (Jedis jedis = pool.getResource()) {
56+
try (Jedis jedis = redisClientFactory.getResource()) {
5757
// connected to cache with index 0
5858
jedis.set("k0", "v0");
5959
Assert.assertEquals("v0", jedis.get("k0"));
@@ -64,7 +64,7 @@ public void testSelect() throws Exception {
6464
Assert.assertEquals("v1", jedis.get("k1"));
6565
Assert.assertNull(jedis.get("k0"));
6666

67-
try (Jedis jedis2 = pool.getResource()) {
67+
try (Jedis jedis2 = redisClientFactory.getResource()) {
6868
// connected to cache with index 0
6969
Assert.assertEquals("v0", jedis2.get("k0"));
7070
Assert.assertNull(jedis2.get("k1"));
@@ -81,7 +81,7 @@ public void testSelect() throws Exception {
8181
/** */
8282
@Test
8383
public void testSetGetLongString() {
84-
try (Jedis jedis = pool.getResource()) {
84+
try (Jedis jedis = redisClientFactory.getResource()) {
8585
for (int len : new int[] {8, 16, 32}) {
8686
String key = "b" + len;
8787
String val = RandomStringUtils.randomAscii((int)(len * KB));

modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisProtocolServerSelfTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class RedisProtocolServerSelfTest extends RedisCommonAbstractTest {
3131
*/
3232
@Test
3333
public void testDbSize() throws Exception {
34-
try (Jedis jedis = pool.getResource()) {
34+
try (Jedis jedis = redisClientFactory.getResource()) {
3535
Assert.assertEquals(0, (long)jedis.dbSize());
3636

3737
jcache().putAll(new HashMap<Integer, Integer>() {
@@ -50,7 +50,7 @@ public void testDbSize() throws Exception {
5050
*/
5151
@Test
5252
public void testFlushDb() throws Exception {
53-
try (Jedis jedis = pool.getResource()) {
53+
try (Jedis jedis = redisClientFactory.getResource()) {
5454
Assert.assertEquals(0, (long)jedis.dbSize());
5555

5656
jcache().putAll(new HashMap<Integer, Integer>() {
@@ -87,7 +87,7 @@ public void testFlushDb() throws Exception {
8787
*/
8888
@Test
8989
public void testFlushAll() throws Exception {
90-
try (Jedis jedis = pool.getResource()) {
90+
try (Jedis jedis = redisClientFactory.getResource()) {
9191
Assert.assertEquals(0, (long)jedis.dbSize());
9292

9393
for (int i = 0; i < 100; i++)

modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisProtocolStringAtomicDatastructuresSelfTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class RedisProtocolStringAtomicDatastructuresSelfTest extends RedisCommon
3131
*/
3232
@Test
3333
public void testAtomicCommandsTopologyChange() throws Exception {
34-
try (Jedis jedis = pool.getResource()) {
34+
try (Jedis jedis = redisClientFactory.getResource()) {
3535
int size = grid(0).cachesx().size();
3636

3737
jedis.incr("key1");

modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisProtocolStringSelfTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class RedisProtocolStringSelfTest extends RedisCommonAbstractTest {
3737
*/
3838
@Test
3939
public void testGet() throws Exception {
40-
try (Jedis jedis = pool.getResource()) {
40+
try (Jedis jedis = redisClientFactory.getResource()) {
4141
jcache().put("getKey1", "getVal1");
4242

4343
Assert.assertEquals("getVal1", jedis.get("getKey1"));
@@ -61,18 +61,18 @@ public void testGet() throws Exception {
6161
*/
6262
@Test
6363
public void testGetSet() throws Exception {
64-
try (Jedis jedis = pool.getResource()) {
64+
try (Jedis jedis = redisClientFactory.getResource()) {
6565
jcache().put("getSetKey1", "1");
6666

67-
Assert.assertEquals("1", jedis.getSet("getSetKey1", "0"));
67+
Assert.assertEquals("1", jedis.setGet("getSetKey1", "0"));
6868
Assert.assertNull(jedis.get("getSetNonExistingKey"));
6969

70-
jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
70+
jcache().put("setDataTypeKey", new HashSet<>(Arrays.asList("1", "2")));
7171

7272
try {
73-
jedis.getSet("setDataTypeKey", "0");
73+
jedis.setGet("setDataTypeKey", "0");
7474

75-
assert false : "Exception has to be thrown!";
75+
fail("Exception has to be thrown!");
7676
}
7777
catch (JedisDataException e) {
7878
assertTrue(e.getMessage().startsWith("WRONGTYPE"));
@@ -85,7 +85,7 @@ public void testGetSet() throws Exception {
8585
*/
8686
@Test
8787
public void testMGet() throws Exception {
88-
try (Jedis jedis = pool.getResource()) {
88+
try (Jedis jedis = redisClientFactory.getResource()) {
8989
jcache().put("getKey1", "getVal1");
9090
jcache().put("getKey2", 0);
9191

@@ -134,7 +134,7 @@ public void testMGetOrder(boolean directOrder) {
134134
values.add("getValue" + i);
135135
}
136136

137-
try (Jedis jedis = pool.getResource()) {
137+
try (Jedis jedis = redisClientFactory.getResource()) {
138138
for (int i = 0; i < keysCnt; ++i)
139139
jcache().put(keys.get(i), values.get(i));
140140

@@ -159,7 +159,7 @@ public void testMGetOrder(boolean directOrder) {
159159
*/
160160
@Test
161161
public void testMGetDuplicates() throws Exception {
162-
try (Jedis jedis = pool.getResource()) {
162+
try (Jedis jedis = redisClientFactory.getResource()) {
163163
jcache().put("key-A", "value-A");
164164
jcache().put("key-B", "value-B");
165165

@@ -181,7 +181,7 @@ public void testSet() throws Exception {
181181
long EXPIRE_MS = 1000L;
182182
int EXPIRE_SEC = 1;
183183

184-
try (Jedis jedis = pool.getResource()) {
184+
try (Jedis jedis = redisClientFactory.getResource()) {
185185
jedis.set("setKey1", "1");
186186
jedis.set("setKey2".getBytes(), "b0".getBytes());
187187

@@ -214,7 +214,7 @@ public void testSet() throws Exception {
214214
*/
215215
@Test
216216
public void testMSet() throws Exception {
217-
try (Jedis jedis = pool.getResource()) {
217+
try (Jedis jedis = redisClientFactory.getResource()) {
218218
jedis.mset("setKey1", "1", "setKey2", "2");
219219

220220
Assert.assertEquals("1", jcache().get("setKey1"));
@@ -227,7 +227,7 @@ public void testMSet() throws Exception {
227227
*/
228228
@Test
229229
public void testIncrDecr() throws Exception {
230-
try (Jedis jedis = pool.getResource()) {
230+
try (Jedis jedis = redisClientFactory.getResource()) {
231231
Assert.assertEquals(1, (long)jedis.incr("newKeyIncr"));
232232
Assert.assertEquals(-1, (long)jedis.decr("newKeyDecr"));
233233

@@ -311,7 +311,7 @@ public void testIncrDecr() throws Exception {
311311
*/
312312
@Test
313313
public void testIncrDecrBy() throws Exception {
314-
try (Jedis jedis = pool.getResource()) {
314+
try (Jedis jedis = redisClientFactory.getResource()) {
315315
Assert.assertEquals(2, (long)jedis.incrBy("newKeyIncrBy", 2));
316316
Assert.assertEquals(-2, (long)jedis.decrBy("newKeyDecrBy", 2));
317317

@@ -368,7 +368,7 @@ public void testIncrDecrBy() throws Exception {
368368
*/
369369
@Test
370370
public void testAppend() throws Exception {
371-
try (Jedis jedis = pool.getResource()) {
371+
try (Jedis jedis = redisClientFactory.getResource()) {
372372
Assert.assertEquals(5, (long)jedis.append("appendKey1", "Hello"));
373373
Assert.assertEquals(12, (long)jedis.append("appendKey1", " World!"));
374374

@@ -390,7 +390,7 @@ public void testAppend() throws Exception {
390390
*/
391391
@Test
392392
public void testStrlen() throws Exception {
393-
try (Jedis jedis = pool.getResource()) {
393+
try (Jedis jedis = redisClientFactory.getResource()) {
394394
Assert.assertEquals(0, (long)jedis.strlen("strlenKeyNonExisting"));
395395

396396
jcache().put("strlenKey", "abc");
@@ -415,7 +415,7 @@ public void testStrlen() throws Exception {
415415
*/
416416
@Test
417417
public void testSetRange() throws Exception {
418-
try (Jedis jedis = pool.getResource()) {
418+
try (Jedis jedis = redisClientFactory.getResource()) {
419419
Assert.assertEquals(0, (long)jedis.setrange("setRangeKey1", 0, ""));
420420

421421
jcache().put("setRangeKey2", "abc");
@@ -464,7 +464,7 @@ public void testSetRange() throws Exception {
464464
*/
465465
@Test
466466
public void testGetRange() throws Exception {
467-
try (Jedis jedis = pool.getResource()) {
467+
try (Jedis jedis = redisClientFactory.getResource()) {
468468
Assert.assertEquals("", jedis.getrange("getRangeKeyNonExisting", 0, 0));
469469

470470
jcache().put("getRangeKey", "This is a string");
@@ -494,7 +494,7 @@ public void testGetRange() throws Exception {
494494
public void testDel() throws Exception {
495495
jcache().put("delKey1", "abc");
496496
jcache().put("delKey2", "abcd");
497-
try (Jedis jedis = pool.getResource()) {
497+
try (Jedis jedis = redisClientFactory.getResource()) {
498498
// Should return the number of actually deleted entries.
499499
// Assert.assertEquals(0, (long)jedis.del("nonExistingDelKey"));
500500
Assert.assertEquals(2, (long)jedis.del("delKey1", "delKey2"));
@@ -508,7 +508,7 @@ public void testDel() throws Exception {
508508
public void testExists() throws Exception {
509509
jcache().put("existsKey1", "abc");
510510
jcache().put("existsKey2", "abcd");
511-
try (Jedis jedis = pool.getResource()) {
511+
try (Jedis jedis = redisClientFactory.getResource()) {
512512
Assert.assertFalse(jedis.exists("nonExistingDelKey"));
513513
Assert.assertEquals(2, (long)jedis.exists("existsKey1", "existsKey2"));
514514
}
@@ -540,7 +540,7 @@ public void testExpireMs() throws Exception {
540540

541541
/** */
542542
private void testExpire(Expiration exp) throws Exception {
543-
try (Jedis jedis = pool.getResource()) {
543+
try (Jedis jedis = redisClientFactory.getResource()) {
544544
jedis.set("k1", "v1");
545545

546546
Assert.assertTrue(jedis.exists("k1"));

modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSSLTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public void testCustomCiphersOnServer() throws Exception {
376376

377377
// Explicit cipher not supported by server.
378378
GridTestUtils.assertThrows(log, () -> DriverManager.getConnection(
379-
"jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
379+
"jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
380380
"&sslCipherSuites=" + cipher2 +
381381
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
382382
"&sslClientCertificateKeyStorePassword=123456" +

0 commit comments

Comments
 (0)