Skip to content

Commit

Permalink
Fix test with issue hidden due to optional client name (#3357)
Browse files Browse the repository at this point in the history
* Fix test with issue hidden due to optional client name

* Avoid keeping residue after test
  • Loading branch information
sazzad16 authored Apr 7, 2023
1 parent 3e8a584 commit 3b46620
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/test/java/redis/clients/jedis/JedisPooledTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redis.clients.jedis;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand Down Expand Up @@ -90,7 +91,8 @@ public void allowUrlWithNoDBAndNoPassword() throws URISyntaxException {

@Test
public void customClientName() {
try (JedisPooled pool = new JedisPooled(hnp, DefaultJedisClientConfig.builder().clientName("my_shiny_client_name").build());
try (JedisPooled pool = new JedisPooled(hnp, DefaultJedisClientConfig.builder()
.clientName("my_shiny_client_name").build());
Connection jedis = pool.getPool().getResource()) {
assertEquals("my_shiny_client_name", new Jedis(jedis).clientGetname());
}
Expand Down Expand Up @@ -167,8 +169,7 @@ public void testResetValidPassword() {
assertEquals(0, pool.getPool().getNumActive());

factory.setPassword("foobared");
pool.set("foo", "bar");
assertEquals("bar", pool.get("foo"));
assertNull(pool.get("foo"));
}
}

Expand All @@ -187,8 +188,7 @@ public void testResetValidCredentials() {
assertEquals(0, pool.getPool().getNumActive());

credentialsProvider.setCredentials(new DefaultRedisCredentials(null, "foobared"));
pool.set("foo", "bar");
assertEquals("bar", pool.get("foo"));
assertNull(pool.get("foo"));
}
}

Expand Down Expand Up @@ -231,20 +231,23 @@ public void cleanUp() {
}
};

// TODO: do it without the help of pool config; from Connection constructor? (configurable) force ping?
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
poolConfig.setMaxTotal(1);
poolConfig.setTestOnBorrow(true);
try (JedisPooled pool = new JedisPooled(HostAndPorts.getRedisServers().get(0),
DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider)
.clientName("my_shiny_client_name").build())) {
.build(), poolConfig)) {
try {
pool.get("foo");
fail("Should not get resource from pool");
} catch (JedisException e) {
}
assertEquals(0, pool.getPool().getNumActive());
assertEquals(0, pool.getPool().getNumActive() + pool.getPool().getNumIdle() + pool.getPool().getNumWaiters());
assertEquals(1, prepareCount.get());
assertEquals(1, cleanupCount.get());

pool.set("foo", "bar");
assertEquals("bar", pool.get("foo"));
assertNull(pool.get("foo"));
assertEquals(2, prepareCount.get());
assertEquals(2, cleanupCount.get());
}
Expand Down

0 comments on commit 3b46620

Please sign in to comment.