Skip to content

Commit

Permalink
Modify credentials provider test with JedisPooled
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed May 1, 2023
1 parent 2744fa8 commit 9ac8c52
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/test/java/redis/clients/jedis/JedisPooledTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package redis.clients.jedis;

import static org.hamcrest.MatcherAssert.assertThat;
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;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.Test;
Expand Down Expand Up @@ -196,9 +200,9 @@ public void testResetValidCredentials() {
public void testCredentialsProvider() {
final AtomicInteger prepareCount = new AtomicInteger();
final AtomicInteger cleanupCount = new AtomicInteger();
final AtomicBoolean validPassword = new AtomicBoolean(false);

RedisCredentialsProvider credentialsProvider = new RedisCredentialsProvider() {
boolean firstCall = true;

@Override
public void prepare() {
Expand All @@ -207,8 +211,7 @@ public void prepare() {

@Override
public RedisCredentials get() {
if (firstCall) {
firstCall = false;
if (!validPassword.get()) {
return new RedisCredentials() { };
}

Expand Down Expand Up @@ -244,12 +247,13 @@ public void cleanUp() {
} catch (JedisException e) {
}
assertEquals(0, pool.getPool().getNumActive() + pool.getPool().getNumIdle() + pool.getPool().getNumWaiters());
assertEquals(1, prepareCount.get());
assertEquals(1, cleanupCount.get());
assertThat(prepareCount.getAndSet(0), greaterThanOrEqualTo(1));
assertThat(cleanupCount.getAndSet(0), greaterThanOrEqualTo(1));

validPassword.set(true);
assertNull(pool.get("foo"));
assertEquals(2, prepareCount.get());
assertEquals(2, cleanupCount.get());
assertThat(prepareCount.get(), equalTo(1));
assertThat(cleanupCount.get(), equalTo(1));
}
}
}

0 comments on commit 9ac8c52

Please sign in to comment.