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

Reenable clustering tests #3764

Merged
merged 7 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,50 @@ cluster-enabled yes
cluster-config-file /tmp/redis_cluster_node5.conf
endef

# STABLE CLUSTER REDIS NODES
# The structure of this cluster is not changed by the tests!
define REDIS_STABLE_CLUSTER_NODE1_CONF
daemonize yes
protected-mode no
requirepass cluster
port 10379
cluster-node-timeout 15000
pidfile /tmp/redis_stable_cluster_node1.pid
logfile /tmp/redis_stable_cluster_node1.log
save ""
appendonly no
cluster-enabled yes
cluster-config-file /tmp/redis_stable_cluster_node1.conf
endef

define REDIS_STABLE_CLUSTER_NODE2_CONF
daemonize yes
protected-mode no
requirepass cluster
port 10380
cluster-node-timeout 15000
pidfile /tmp/redis_stable_cluster_node2.pid
logfile /tmp/redis_stable_cluster_node2.log
save ""
appendonly no
cluster-enabled yes
cluster-config-file /tmp/redis_stable_cluster_node2.conf
endef

define REDIS_STABLE_CLUSTER_NODE3_CONF
daemonize yes
protected-mode no
requirepass cluster
port 10381
cluster-node-timeout 15000
pidfile /tmp/redis_stable_cluster_node3.pid
logfile /tmp/redis_stable_cluster_node3.log
save ""
appendonly no
cluster-enabled yes
cluster-config-file /tmp/redis_stable_cluster_node3.conf
endef

# UDS REDIS NODES
define REDIS_UDS
daemonize yes
Expand Down Expand Up @@ -329,6 +373,15 @@ connect = 127.0.0.1:7382
[redis_cluster_5]
accept = 127.0.0.1:8383
connect = 127.0.0.1:7383
[redis_stable_cluster_1]
accept = 127.0.0.1:11379
connect = 127.0.0.1:10379
[redis_stable_cluster_2]
accept = 127.0.0.1:11380
connect = 127.0.001:10380
[redis_stable_cluster_3]
accept = 127.0.0.1:11381
connect = 127.0.001:10381
gerzse marked this conversation as resolved.
Show resolved Hide resolved
[redis_sentinel_5]
accept = 127.0.0.1:36383
connect = 127.0.0.1:26383
Expand All @@ -355,6 +408,9 @@ export REDIS_CLUSTER_NODE2_CONF
export REDIS_CLUSTER_NODE3_CONF
export REDIS_CLUSTER_NODE4_CONF
export REDIS_CLUSTER_NODE5_CONF
export REDIS_STABLE_CLUSTER_NODE1_CONF
export REDIS_STABLE_CLUSTER_NODE2_CONF
export REDIS_STABLE_CLUSTER_NODE3_CONF
export REDIS_UDS
export REDIS_UNAVAILABLE_CONF
export STUNNEL_CONF
Expand Down Expand Up @@ -393,8 +449,12 @@ start: stunnel cleanup
echo "$$REDIS_CLUSTER_NODE3_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE4_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE5_CONF" | redis-server -
echo "$$REDIS_STABLE_CLUSTER_NODE1_CONF" | redis-server -
echo "$$REDIS_STABLE_CLUSTER_NODE2_CONF" | redis-server -
echo "$$REDIS_STABLE_CLUSTER_NODE3_CONF" | redis-server -
echo "$$REDIS_UDS" | redis-server -
echo "$$REDIS_UNAVAILABLE_CONF" | redis-server -
redis-cli -a cluster --cluster create 127.0.0.1:10379 127.0.0.1:10380 127.0.0.1:10381 --cluster-yes

cleanup:
- rm -vf /tmp/redis_cluster_node*.conf 2>/dev/null
Expand Down Expand Up @@ -426,6 +486,9 @@ stop:
kill `cat /tmp/redis_cluster_node3.pid` || true
kill `cat /tmp/redis_cluster_node4.pid` || true
kill `cat /tmp/redis_cluster_node5.pid` || true
kill `cat /tmp/redis_stable_cluster_node1.pid`
kill `cat /tmp/redis_stable_cluster_node2.pid`
kill `cat /tmp/redis_stable_cluster_node3.pid`
kill `cat /tmp/redis_uds.pid` || true
kill `cat /tmp/stunnel.pid` || true
[ -f /tmp/redis_unavailable.pid ] && kill `cat /tmp/redis_unavailable.pid` || true
Expand All @@ -439,6 +502,9 @@ stop:
rm -f /tmp/redis_cluster_node3.conf
rm -f /tmp/redis_cluster_node4.conf
rm -f /tmp/redis_cluster_node5.conf
rm -f /tmp/redis_stable_cluster_node1.conf
rm -f /tmp/redis_stable_cluster_node2.conf
rm -f /tmp/redis_stable_cluster_node3.conf

test: compile-module start
sleep 2
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/redis/clients/jedis/HostAndPorts.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public final class HostAndPorts {
private static List<HostAndPort> redisHostAndPortList = new ArrayList<>();
private static List<HostAndPort> sentinelHostAndPortList = new ArrayList<>();
private static List<HostAndPort> clusterHostAndPortList = new ArrayList<>();
private static List<HostAndPort> stableClusterHostAndPortList = new ArrayList<>();

static {
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT));
Expand All @@ -34,6 +35,10 @@ public final class HostAndPorts {
clusterHostAndPortList.add(new HostAndPort("localhost", 7382));
clusterHostAndPortList.add(new HostAndPort("localhost", 7383));
clusterHostAndPortList.add(new HostAndPort("localhost", 7384));

stableClusterHostAndPortList.add(new HostAndPort("localhost", 10379));
stableClusterHostAndPortList.add(new HostAndPort("localhost", 10380));
stableClusterHostAndPortList.add(new HostAndPort("localhost", 10381));
gerzse marked this conversation as resolved.
Show resolved Hide resolved
}

public static List<HostAndPort> parseHosts(String envHosts,
Expand Down Expand Up @@ -71,6 +76,10 @@ public static List<HostAndPort> getClusterServers() {
return clusterHostAndPortList;
}

public static List<HostAndPort> getStableClusterServers() {
return stableClusterHostAndPortList;
}

private HostAndPorts() {
throw new InstantiationError("Must not instantiate this class");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.args.ListPosition;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.args.ListPosition;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.params.LPosParams;
import redis.clients.jedis.util.KeyValue;
Expand Down Expand Up @@ -123,7 +122,7 @@ public void lrange() {
assertEquals(expected, range);

range = jedis.lrange("foo", 2, 1);
assertEquals(Collections.<String> emptyList(), range);
assertEquals(Collections.<String>emptyList(), range);

// Binary
jedis.rpush(bfoo, bA);
Expand All @@ -149,7 +148,7 @@ public void lrange() {
assertByteArrayListEquals(bexpected, brange);

brange = jedis.lrange(bfoo, 2, 1);
assertByteArrayListEquals(Collections.<byte[]> emptyList(), brange);
assertByteArrayListEquals(Collections.<byte[]>emptyList(), brange);
}

@Test
Expand Down Expand Up @@ -500,7 +499,7 @@ public void blpopDoubleWithSleep() {
new Thread(() -> {
try {
Thread.sleep(30);
} catch(InterruptedException e) {
} catch (InterruptedException e) {
logger.error("", e);
}
jedis.lpush("foo", "bar");
Expand Down Expand Up @@ -620,7 +619,7 @@ public void brpopDoubleWithSleep() {
new Thread(() -> {
try {
Thread.sleep(30);
} catch(InterruptedException e) {
} catch (InterruptedException e) {
logger.error("", e);
}
jedis.lpush("foo", "bar");
Expand Down Expand Up @@ -861,8 +860,8 @@ public void blmove() {

@Test
public void lmpop() {
String mylist1 = "mylist1";
String mylist2 = "mylist2";
String mylist1 = "mylist1{.}";
String mylist2 = "mylist2{.}";

// add elements to list
jedis.lpush(mylist1, "one", "two", "three", "four", "five");
Expand All @@ -886,8 +885,8 @@ public void lmpop() {

@Test
public void blmpopSimple() {
String mylist1 = "mylist1";
String mylist2 = "mylist2";
String mylist1 = "mylist1{.}";
String mylist2 = "mylist2{.}";

// add elements to list
jedis.lpush(mylist1, "one", "two", "three", "four", "five");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START;
import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START_BINARY;
import static redis.clients.jedis.util.AssertUtil.assertByteArrayCollectionContainsAll;
Expand All @@ -20,12 +19,12 @@
import java.util.Set;

import org.junit.Test;

import redis.clients.jedis.params.ScanParams;
import redis.clients.jedis.resps.ScanResult;

public abstract class SetCommandsTestBase extends UnifiedJedisCommandsTestBase {
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
final byte[] bfoo_same_hashslot = { 0x01, 0x02, 0x03, 0x04, 0x03, 0x00, 0x03, 0x1b };
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
final byte[] ba = { 0x0A };
Expand Down Expand Up @@ -357,29 +356,29 @@ public void sinterstore() {

@Test
public void sintercard() {
jedis.sadd("foo", "a");
jedis.sadd("foo", "b");
jedis.sadd("foo{.}", "a");
jedis.sadd("foo{.}", "b");

jedis.sadd("bar", "a");
jedis.sadd("bar", "b");
jedis.sadd("bar", "c");
jedis.sadd("bar{.}", "a");
jedis.sadd("bar{.}", "b");
jedis.sadd("bar{.}", "c");

long card = jedis.sintercard("foo", "bar");
long card = jedis.sintercard("foo{.}", "bar{.}");
assertEquals(2, card);
long limitedCard = jedis.sintercard(1, "foo", "bar");
long limitedCard = jedis.sintercard(1, "foo{.}", "bar{.}");
assertEquals(1, limitedCard);

// Binary
jedis.sadd(bfoo, ba);
jedis.sadd(bfoo, bb);

jedis.sadd(bbar, ba);
jedis.sadd(bbar, bb);
jedis.sadd(bbar, bc);
jedis.sadd(bfoo_same_hashslot, ba);
jedis.sadd(bfoo_same_hashslot, bb);
jedis.sadd(bfoo_same_hashslot, bc);

long bcard = jedis.sintercard(bfoo, bbar);
long bcard = jedis.sintercard(bfoo, bfoo_same_hashslot);
assertEquals(2, bcard);
long blimitedCard = jedis.sintercard(1, bfoo, bbar);
long blimitedCard = jedis.sintercard(1, bfoo, bfoo_same_hashslot);
assertEquals(1, blimitedCard);
}

Expand Down Expand Up @@ -545,11 +544,11 @@ public void srandmember() {

List<String> members = jedis.srandmember("foo", 2);
members.sort(Comparator.naturalOrder());
assertEquals( Arrays.asList("a", "b"), members);
assertEquals(Arrays.asList("a", "b"), members);

member = jedis.srandmember("bar");
assertNull(member);

members = jedis.srandmember("bar", 2);
assertEquals(0, members.size());

Expand All @@ -561,13 +560,13 @@ public void srandmember() {

assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember));
assertEquals(2, jedis.smembers(bfoo).size());

List<byte[]> bmembers = jedis.srandmember(bfoo, 2);
assertEquals(2, bmembers.size());

bmember = jedis.srandmember(bbar);
assertNull(bmember);

members = jedis.srandmember("bbar", 2);
assertEquals(0, members.size());
}
Expand Down
Loading
Loading