Skip to content

Commit

Permalink
Merge branch 'master' into 5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Jun 6, 2024
2 parents 27e1553 + 327215a commit e45e4a7
Show file tree
Hide file tree
Showing 47 changed files with 758 additions and 516 deletions.
90 changes: 49 additions & 41 deletions src/test/java/redis/clients/jedis/ACLJedisPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@
* This test is only executed when the server/cluster is Redis 6. or more.
*/
public class ACLJedisPoolTest {
private static final HostAndPort hnp = HostAndPorts.getRedisServers().get(0);
private static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0-acl");

private static final EndpointConfig endpointWithDefaultUser = HostAndPorts.getRedisEndpoint("standalone0");

@BeforeClass
public static void prepare() throws Exception {
// Use to check if the ACL test should be ran. ACL are available only in 6.0 and later
org.junit.Assume.assumeTrue("Not running ACL test on this version of Redis",
RedisVersionUtil.checkRedisMajorVersionNumber(6));
RedisVersionUtil.checkRedisMajorVersionNumber(6, endpoint));
}

@Test
public void checkConnections() {
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), "acljedis",
"fizzbuzz");
JedisPool pool = new JedisPool(new JedisPoolConfig(), endpoint.getHost(), endpoint.getPort(),
endpoint.getUsername(), endpoint.getPassword());
try (Jedis jedis = pool.getResource()) {
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
Expand All @@ -44,7 +46,8 @@ public void checkConnections() {

@Test
public void checkCloseableConnections() throws Exception {
JedisPool pool = new JedisPool(hnp.getHost(), hnp.getPort(), "acljedis", "fizzbuzz");
JedisPool pool = new JedisPool(endpoint.getHost(), endpoint.getPort(), endpoint.getUsername(),
endpoint.getPassword());
try (Jedis jedis = pool.getResource()) {
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
Expand All @@ -58,9 +61,9 @@ public void checkResourceIsClosableAndReusable() {
GenericObjectPoolConfig<Jedis> config = new GenericObjectPoolConfig<>();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
try (JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(),
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, 0 /* infinite */, "acljedis",
"fizzbuzz", Protocol.DEFAULT_DATABASE, "closable-reusable-pool", false, null, null, null)) {
try (JedisPool pool = new JedisPool(config, endpoint.getHost(), endpoint.getPort(),
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, 0 /* infinite */, endpoint.getUsername(),
endpoint.getPassword(), Protocol.DEFAULT_DATABASE, "closable-reusable-pool", false, null, null, null)) {

Jedis jedis = pool.getResource();
jedis.set("hello", "jedis");
Expand All @@ -78,8 +81,8 @@ public void checkResourceWithConfigIsClosableAndReusable() {
GenericObjectPoolConfig<Jedis> config = new GenericObjectPoolConfig<>();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
try (JedisPool pool = new JedisPool(config, hnp, DefaultJedisClientConfig.builder()
.user("acljedis").password("fizzbuzz").clientName("closable-reusable-pool")
try (JedisPool pool = new JedisPool(config, endpoint.getHostAndPort(),
endpoint.getClientConfigBuilder().clientName("closable-reusable-pool")
.build())) {

Jedis jedis = pool.getResource();
Expand All @@ -96,9 +99,9 @@ public void checkResourceWithConfigIsClosableAndReusable() {

@Test
public void checkPoolRepairedWhenJedisIsBroken() {
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(),
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, 0 /* infinite */, "acljedis",
"fizzbuzz", Protocol.DEFAULT_DATABASE, "repairable-pool");
JedisPool pool = new JedisPool(new JedisPoolConfig(), endpoint.getHost(), endpoint.getPort(),
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, 0 /* infinite */, endpoint.getUsername(),
endpoint.getPassword(), Protocol.DEFAULT_DATABASE, "repairable-pool");
try (Jedis jedis = pool.getResource()) {
jedis.set("foo", "0");
jedis.disconnect();
Expand All @@ -116,12 +119,12 @@ public void checkPoolOverflow() {
GenericObjectPoolConfig<Jedis> config = new GenericObjectPoolConfig<>();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
try (JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort());
try (JedisPool pool = new JedisPool(config, endpoint.getHost(), endpoint.getPort());
Jedis jedis = pool.getResource()) {
jedis.auth("acljedis", "fizzbuzz");
jedis.auth(endpoint.getUsername(), endpoint.getPassword());

try (Jedis jedis2 = pool.getResource()) {
jedis2.auth("acljedis", "fizzbuzz");
jedis2.auth(endpoint.getUsername(), endpoint.getPassword());
}
}
}
Expand All @@ -130,8 +133,8 @@ public void checkPoolOverflow() {
public void securePool() {
JedisPoolConfig config = new JedisPoolConfig();
config.setTestOnBorrow(true);
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "acljedis",
"fizzbuzz");
JedisPool pool = new JedisPool(config, endpoint.getHost(), endpoint.getPort(), 2000, endpoint.getUsername(),
endpoint.getPassword());
try (Jedis jedis = pool.getResource()) {
jedis.set("foo", "bar");
}
Expand All @@ -143,8 +146,8 @@ public void securePool() {
public void securePoolNonSSL() {
JedisPoolConfig config = new JedisPoolConfig();
config.setTestOnBorrow(true);
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "acljedis",
"fizzbuzz", false);
JedisPool pool = new JedisPool(config, endpoint.getHost(), endpoint.getPort(), 2000, endpoint.getUsername(),
endpoint.getPassword(), false);
try (Jedis jedis = pool.getResource()) {
jedis.set("foo", "bar");
}
Expand All @@ -154,46 +157,49 @@ public void securePoolNonSSL() {

@Test
public void nonDefaultDatabase() {
try (JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
"acljedis", "fizzbuzz"); Jedis jedis0 = pool0.getResource()) {
try (JedisPool pool0 = new JedisPool(new JedisPoolConfig(), endpoint.getHost(), endpoint.getPort(), 2000,
endpoint.getUsername(), endpoint.getPassword()); Jedis jedis0 = pool0.getResource()) {
jedis0.set("foo", "bar");
assertEquals("bar", jedis0.get("foo"));
}

try (JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
"acljedis", "fizzbuzz", 1); Jedis jedis1 = pool1.getResource()) {
try (JedisPool pool1 = new JedisPool(new JedisPoolConfig(), endpoint.getHost(), endpoint.getPort(), 2000,
endpoint.getUsername(), endpoint.getPassword(), 1); Jedis jedis1 = pool1.getResource()) {
assertNull(jedis1.get("foo"));
}
}

@Test
public void startWithUrlString() {
try (Jedis j = new Jedis("localhost", 6379)) {
j.auth("acljedis", "fizzbuzz");
try (Jedis j = new Jedis(endpoint.getHost(), endpoint.getPort())) {
j.auth(endpoint.getUsername(), endpoint.getPassword());
j.select(2);
j.set("foo", "bar");
}

try (JedisPool pool = new JedisPool("redis://acljedis:fizzbuzz@localhost:6379/2");
try (JedisPool pool = new JedisPool(
endpoint.getURIBuilder().defaultCredentials().path("/2").build());
Jedis jedis = pool.getResource()) {
assertEquals("bar", jedis.get("foo"));
}
}

@Test
public void startWithUrl() throws URISyntaxException {
try (Jedis j = new Jedis("localhost", 6379)) {
j.auth("acljedis", "fizzbuzz");
try (Jedis j = new Jedis(endpoint.getHost(), endpoint.getPort())) {
j.auth(endpoint.getUsername(), endpoint.getPassword());
j.select(2);
j.set("foo", "bar");
}

try (JedisPool pool = new JedisPool(new URI("redis://acljedis:fizzbuzz@localhost:6379/2"));
try (JedisPool pool = new JedisPool(
endpoint.getURIBuilder().defaultCredentials().path("/2").build());
Jedis jedis = pool.getResource()) {
assertEquals("bar", jedis.get("foo"));
}

try (JedisPool pool = new JedisPool(new URI("redis://default:foobared@localhost:6379/2"));
try (JedisPool pool = new JedisPool(
endpointWithDefaultUser.getURIBuilder().defaultCredentials().path("/2").build());
Jedis jedis = pool.getResource()) {
assertEquals("bar", jedis.get("foo"));
}
Expand All @@ -206,14 +212,14 @@ public void shouldThrowInvalidURIExceptionForInvalidURI() throws URISyntaxExcept

@Test
public void allowUrlWithNoDBAndNoPassword() throws URISyntaxException {
new JedisPool("redis://localhost:6379").close();
new JedisPool(new URI("redis://localhost:6379")).close();
new JedisPool(endpoint.getURI().toString()).close();
new JedisPool(endpoint.getURI()).close();
}

@Test
public void selectDatabaseOnActivation() {
try (JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
"acljedis", "fizzbuzz")) {
try (JedisPool pool = new JedisPool(new JedisPoolConfig(), endpoint.getHost(), endpoint.getPort(), 2000,
endpoint.getUsername(), endpoint.getPassword())) {

Jedis jedis0 = pool.getResource();
assertEquals(0, jedis0.getDB());
Expand All @@ -233,17 +239,17 @@ public void selectDatabaseOnActivation() {

@Test
public void customClientName() {
try (JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
"acljedis", "fizzbuzz", 0, "my_shiny_client_name"); Jedis jedis = pool.getResource()) {
try (JedisPool pool = new JedisPool(new JedisPoolConfig(), endpoint.getHost(), endpoint.getPort(), 2000,
endpoint.getUsername(), endpoint.getPassword(), 0, "my_shiny_client_name"); Jedis jedis = pool.getResource()) {

assertEquals("my_shiny_client_name", jedis.clientGetname());
}
}

@Test
public void customClientNameNoSSL() {
try (JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
"acljedis", "fizzbuzz", 0, "my_shiny_client_name_no_ssl", false);
try (JedisPool pool0 = new JedisPool(new JedisPoolConfig(), endpoint.getHost(), endpoint.getPort(), 2000,
endpoint.getUsername(), endpoint.getPassword(), 0, "my_shiny_client_name_no_ssl", false);
Jedis jedis = pool0.getResource()) {

assertEquals("my_shiny_client_name_no_ssl", jedis.clientGetname());
Expand All @@ -254,8 +260,10 @@ public void customClientNameNoSSL() {
public void testCloseConnectionOnMakeObject() {
JedisPoolConfig config = new JedisPoolConfig();
config.setTestOnBorrow(true);
try (JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
"acljedis", "foobared"); Jedis jedis = new Jedis("redis://:foobared@localhost:6379/")) {
try (JedisPool pool = new JedisPool(new JedisPoolConfig(), endpoint.getHost(),
endpoint.getPort(), 2000, endpoint.getUsername(), "wrongpassword");
Jedis jedis = new Jedis(endpointWithDefaultUser.getURIBuilder()
.credentials("", endpointWithDefaultUser.getPassword()).build())) {
int currentClientCount = getClientCount(jedis.clientList());
try {
pool.getResource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public class ACLJedisSentinelPoolTest {

private static final String MASTER_NAME = "aclmaster";

//protected static HostAndPort master = HostAndPortUtil.getRedisServers().get(8);
protected static HostAndPort sentinel1 = HostAndPorts.getSentinelServers().get(4);

protected Set<HostAndPort> sentinels = new HashSet<>();

@BeforeClass
public static void prepare() throws Exception {
EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone2-primary");
org.junit.Assume.assumeTrue("Not running ACL test on this version of Redis",
RedisVersionUtil.checkRedisMajorVersionNumber(6));
RedisVersionUtil.checkRedisMajorVersionNumber(6, endpoint));
}

@Before
Expand Down
39 changes: 20 additions & 19 deletions src/test/java/redis/clients/jedis/ACLJedisTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.junit.Assert.assertEquals;

import java.net.URI;
import java.net.URISyntaxException;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -20,14 +19,16 @@
@RunWith(Parameterized.class)
public class ACLJedisTest extends JedisCommandsTestBase {

protected static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0-acl");

/**
* Use to check if the ACL test should be ran. ACL are available only in 6.0 and later
* @throws Exception
*/
@BeforeClass
public static void prepare() throws Exception {
org.junit.Assume.assumeTrue("Not running ACL test on this version of Redis",
RedisVersionUtil.checkRedisMajorVersionNumber(6));
RedisVersionUtil.checkRedisMajorVersionNumber(6, endpoint));
}

public ACLJedisTest(RedisProtocol redisProtocol) {
Expand All @@ -37,39 +38,38 @@ public ACLJedisTest(RedisProtocol redisProtocol) {
@Test
public void useWithoutConnecting() {
try (Jedis j = new Jedis()) {
assertEquals("OK", j.auth("acljedis", "fizzbuzz"));
assertEquals("OK", j.auth(endpoint.getUsername(), endpoint.getPassword()));
j.dbSize();
}
}

@Test
public void connectWithConfig() {
try (Jedis jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().build())) {
jedis.auth("acljedis", "fizzbuzz");
try (Jedis jedis = new Jedis(endpoint.getHostAndPort(), DefaultJedisClientConfig.builder().build())) {
jedis.auth(endpoint.getUsername(), endpoint.getPassword());
assertEquals("PONG", jedis.ping());
}
try (Jedis jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().user("acljedis")
.password("fizzbuzz").build())) {
try (Jedis jedis = new Jedis(endpoint.getHostAndPort(), endpoint.getClientConfigBuilder().build())) {
assertEquals("PONG", jedis.ping());
}
}

@Test
public void connectWithConfigInterface() {
try (Jedis jedis = new Jedis(hnp, new JedisClientConfig() {
try (Jedis jedis = new Jedis(endpoint.getHostAndPort(), new JedisClientConfig() {
})) {
jedis.auth("acljedis", "fizzbuzz");
jedis.auth(endpoint.getUsername(), endpoint.getPassword());
assertEquals("PONG", jedis.ping());
}
try (Jedis jedis = new Jedis(hnp, new JedisClientConfig() {
try (Jedis jedis = new Jedis(endpoint.getHostAndPort(), new JedisClientConfig() {
@Override
public String getUser() {
return "acljedis";
return endpoint.getUsername();
}

@Override
public String getPassword() {
return "fizzbuzz";
return endpoint.getPassword();
}
})) {
assertEquals("PONG", jedis.ping());
Expand All @@ -78,29 +78,30 @@ public String getPassword() {

@Test
public void startWithUrl() {
try (Jedis j = new Jedis("localhost", 6379)) {
assertEquals("OK", j.auth("acljedis", "fizzbuzz"));
try (Jedis j = new Jedis(endpoint.getHostAndPort())) {
assertEquals("OK", j.auth(endpoint.getUsername(), endpoint.getPassword()));
assertEquals("OK", j.select(2));
j.set("foo", "bar");
}
try (Jedis j2 = new Jedis("redis://acljedis:fizzbuzz@localhost:6379/2")) {
try (Jedis j2 = new Jedis(
endpoint.getURIBuilder().defaultCredentials().path("/2").build().toString())) {
assertEquals("PONG", j2.ping());
assertEquals("bar", j2.get("foo"));
}
}

@Test
public void startWithUri() throws URISyntaxException {
try (Jedis j = new Jedis("localhost", 6379)) {
assertEquals("OK", j.auth("acljedis", "fizzbuzz"));
try (Jedis j = new Jedis(endpoint.getHostAndPort())) {
assertEquals("OK", j.auth(endpoint.getUsername(), endpoint.getPassword()));
assertEquals("OK", j.select(2));
j.set("foo", "bar");
}
try (Jedis j1 = new Jedis(new URI("redis://acljedis:fizzbuzz@localhost:6379/2"))) {
try (Jedis j1 = new Jedis(endpoint.getURIBuilder().defaultCredentials().path("/2").build())) {
assertEquals("PONG", j1.ping());
assertEquals("bar", j1.get("foo"));
}
try (Jedis j2 = new Jedis(new URI("redis://acljedis:fizzbuzz@localhost:6379/2"))) {
try (Jedis j2 = new Jedis(endpoint.getURIBuilder().defaultCredentials().path("/2").build())) {
assertEquals("PONG", j2.ping());
assertEquals("bar", j2.get("foo"));
}
Expand Down
Loading

0 comments on commit e45e4a7

Please sign in to comment.