Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flakyness of JedisPooledTest #3506

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/test/java/redis/clients/jedis/JedisPooledTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package redis.clients.jedis;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
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 All @@ -22,6 +22,7 @@
public class JedisPooledTest {

private static final HostAndPort hnp = HostAndPorts.getRedisServers().get(7);
private static final HostAndPort pwp = HostAndPorts.getRedisServers().get(1); // password protected

@Test
public void checkCloseableConnections() {
Expand Down Expand Up @@ -177,17 +178,16 @@ public void testResetValidCredentials() {
DefaultRedisCredentialsProvider credentialsProvider =
new DefaultRedisCredentialsProvider(new DefaultRedisCredentials(null, "bad password"));

try (JedisPooled pool = new JedisPooled(HostAndPorts.getRedisServers().get(0),
DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider)
.clientName("my_shiny_client_name").build())) {
try (JedisPooled pool = new JedisPooled(pwp, DefaultJedisClientConfig.builder()
.credentialsProvider(credentialsProvider).build())) {
try {
pool.get("foo");
fail("Should not get resource from pool");
} catch (JedisException e) { }
assertEquals(0, pool.getPool().getNumActive());

credentialsProvider.setCredentials(new DefaultRedisCredentials(null, "foobared"));
assertNull(pool.get("foo"));
assertThat(pool.get("foo"), anything());
}
}

Expand Down Expand Up @@ -238,9 +238,8 @@ public void cleanUp() {
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
poolConfig.setMaxTotal(1);
poolConfig.setTestOnBorrow(true);
try (JedisPooled pool = new JedisPooled(HostAndPorts.getRedisServers().get(0),
DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider)
.build(), poolConfig)) {
try (JedisPooled pool = new JedisPooled(pwp, DefaultJedisClientConfig.builder()
.credentialsProvider(credentialsProvider).build(), poolConfig)) {
try {
pool.get("foo");
fail("Should not get resource from pool");
Expand All @@ -251,7 +250,7 @@ public void cleanUp() {
assertThat(cleanupCount.getAndSet(0), greaterThanOrEqualTo(1));

validPassword.set(true);
assertNull(pool.get("foo"));
assertThat(pool.get("foo"), anything());
assertThat(prepareCount.get(), equalTo(1));
assertThat(cleanupCount.get(), equalTo(1));
}
Expand Down
Loading