Skip to content

Commit

Permalink
Use 2 endpoints for different users
Browse files Browse the repository at this point in the history
  • Loading branch information
uglide committed May 7, 2024
1 parent b2e0c9d commit 7e09e16
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/test/java/redis/clients/jedis/ACLJedisPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/redis/clients/jedis/ACLJedisTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,12 +48,7 @@ public static Collection<Object[]> 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.
Expand All @@ -70,21 +61,21 @@ public static Collection<Object[]> 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);
}

@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);

Expand Down
14 changes: 14 additions & 0 deletions src/test/resources/endpoints.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"standalone0": {
"username": "default",
"password": "foobared",
"tls": false,
"endpoints": [
"redis://localhost:6379"
]
},
"standalone0-acl": {
"username": "acljedis",
"password": "fizzbuzz",
"tls": false,
Expand Down Expand Up @@ -74,5 +82,11 @@
"endpoints": [
"redis://localhost:6389"
]
},
"modules-docker": {
"tls": false,
"endpoints": [
"redis://localhost:6479"
]
}
}

0 comments on commit 7e09e16

Please sign in to comment.