Skip to content

Commit 4407b18

Browse files
committed
IGNITE-28444: Fix deprecated Jedis pool usage in Redis tests
1 parent 5a62956 commit 4407b18

3 files changed

Lines changed: 44 additions & 28 deletions

File tree

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

Lines changed: 39 additions & 23 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.
@@ -42,7 +41,7 @@ public class RedisCommonAbstractTest extends GridCommonAbstractTest {
4241
protected static final int PORT = 6379;
4342

4443
/** Pool. */
45-
protected static JedisPool pool;
44+
protected static RedisPool pool;
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+
pool = new RedisPool(
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+
pool = 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 RedisPool {
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+
RedisPool(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/RedisProtocolStringSelfTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ public void testGetSet() throws Exception {
6464
try (Jedis jedis = pool.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"));

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)