From 7e09e16f5d49240facbc54378df46c0bb328b516 Mon Sep 17 00:00:00 2001 From: Igor Malinovskyi Date: Tue, 7 May 2024 18:47:20 +0200 Subject: [PATCH] Use 2 endpoints for different users --- .../redis/clients/jedis/ACLJedisPoolTest.java | 2 +- .../redis/clients/jedis/ACLJedisTest.java | 2 ++ .../CommandObjectsGenericCommandsTest.java | 4 +-- .../CommandObjectsModulesTestBase.java | 6 ++--- .../CommandObjectsStandaloneTestBase.java | 3 +-- .../CommandObjectsTestBase.java | 25 ++++++------------- src/test/resources/endpoints.json | 14 +++++++++++ 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/test/java/redis/clients/jedis/ACLJedisPoolTest.java b/src/test/java/redis/clients/jedis/ACLJedisPoolTest.java index efefe27d48..1661ecf726 100644 --- a/src/test/java/redis/clients/jedis/ACLJedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/ACLJedisPoolTest.java @@ -20,7 +20,7 @@ * This test is only executed when the server/cluster is Redis 6. or more. */ public class ACLJedisPoolTest { - private static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0"); + private static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0-acl"); @BeforeClass public static void prepare() throws Exception { diff --git a/src/test/java/redis/clients/jedis/ACLJedisTest.java b/src/test/java/redis/clients/jedis/ACLJedisTest.java index c8c7fb032c..89e0426ce1 100644 --- a/src/test/java/redis/clients/jedis/ACLJedisTest.java +++ b/src/test/java/redis/clients/jedis/ACLJedisTest.java @@ -19,6 +19,8 @@ @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 diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java index 1849d26687..f558a4f686 100644 --- a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java @@ -1082,8 +1082,8 @@ public void testCopyToDbBinary() { private void assertKeyExists(int dstDb, String key, Object expectedValue) { // Cheat and use Jedis, it gives us access to any db. - try (Jedis jedis = new Jedis(nodeInfo)) { - jedis.auth("foobared"); + try (Jedis jedis = new Jedis(endpoint.getHostAndPort())) { + jedis.auth(endpoint.getPassword()); jedis.select(dstDb); assertThat(jedis.get(key), equalTo(expectedValue)); } diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsModulesTestBase.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsModulesTestBase.java index 3bac716fa4..37c6500aeb 100644 --- a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsModulesTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsModulesTestBase.java @@ -1,6 +1,7 @@ package redis.clients.jedis.commands.commandobjects; import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.Protocol; import redis.clients.jedis.RedisProtocol; @@ -9,11 +10,8 @@ */ public abstract class CommandObjectsModulesTestBase extends CommandObjectsTestBase { - private static final String address = - System.getProperty("modulesDocker", Protocol.DEFAULT_HOST + ':' + 6479); - public CommandObjectsModulesTestBase(RedisProtocol protocol) { - super(protocol, HostAndPort.from(address), null); + super(protocol, HostAndPorts.getRedisEndpoint("modules-docker")); } } diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStandaloneTestBase.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStandaloneTestBase.java index f1ff1b6911..128642d2a7 100644 --- a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStandaloneTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStandaloneTestBase.java @@ -9,8 +9,7 @@ public abstract class CommandObjectsStandaloneTestBase extends CommandObjectsTestBase { public CommandObjectsStandaloneTestBase(RedisProtocol protocol) { - super(protocol, HostAndPorts.getRedisEndpoint("standalone0").getHostAndPort(), - HostAndPorts.getRedisEndpoint("standalone0").getPassword()); + super(protocol, HostAndPorts.getRedisEndpoint("standalone0")); } } diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTestBase.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTestBase.java index 5fde288839..45e0c71ad4 100644 --- a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTestBase.java @@ -8,11 +8,7 @@ import org.junit.Before; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import redis.clients.jedis.CommandObject; -import redis.clients.jedis.CommandObjects; -import redis.clients.jedis.DefaultJedisClientConfig; -import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.*; import redis.clients.jedis.args.FlushMode; import redis.clients.jedis.commands.CommandsTestsParameters; import redis.clients.jedis.executors.CommandExecutor; @@ -52,12 +48,7 @@ public static Collection data() { /** * Host and port of the Redis server to connect to. Injected from subclasses. */ - protected final HostAndPort nodeInfo; - - /** - * Password to use when connecting to the Redis server, if needed. Injected from subclasses. - */ - private final String authPassword; + protected final EndpointConfig endpoint; /** * The {@link CommandObjects} to use for the tests. This is the subject-under-test. @@ -70,10 +61,9 @@ public static Collection data() { */ private CommandExecutor commandExecutor; - public CommandObjectsTestBase(RedisProtocol protocol, HostAndPort nodeInfo, String authPassword) { + public CommandObjectsTestBase(RedisProtocol protocol, EndpointConfig endpoint) { this.protocol = protocol; - this.nodeInfo = nodeInfo; - this.authPassword = authPassword; + this.endpoint = endpoint; commandObjects = new CommandObjects(); commandObjects.setProtocol(protocol); } @@ -81,10 +71,11 @@ public CommandObjectsTestBase(RedisProtocol protocol, HostAndPort nodeInfo, Stri @Before public void setUp() { // Configure a default command executor. - DefaultJedisClientConfig clientConfig = DefaultJedisClientConfig.builder() - .protocol(protocol).password(authPassword).build(); + DefaultJedisClientConfig clientConfig = endpoint.getClientConfigBuilder().protocol(protocol) + .build(); - ConnectionProvider connectionProvider = new PooledConnectionProvider(nodeInfo, clientConfig); + ConnectionProvider connectionProvider = new PooledConnectionProvider(endpoint.getHostAndPort(), + clientConfig); commandExecutor = new DefaultCommandExecutor(connectionProvider); diff --git a/src/test/resources/endpoints.json b/src/test/resources/endpoints.json index 9829a81923..a3dbb64e0b 100644 --- a/src/test/resources/endpoints.json +++ b/src/test/resources/endpoints.json @@ -1,5 +1,13 @@ { "standalone0": { + "username": "default", + "password": "foobared", + "tls": false, + "endpoints": [ + "redis://localhost:6379" + ] + }, + "standalone0-acl": { "username": "acljedis", "password": "fizzbuzz", "tls": false, @@ -74,5 +82,11 @@ "endpoints": [ "redis://localhost:6389" ] + }, + "modules-docker": { + "tls": false, + "endpoints": [ + "redis://localhost:6479" + ] } } \ No newline at end of file