diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index fd651fa6a4..076b332d99 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -22,20 +22,21 @@ on: jobs: build: - name: Build and Test + name: Build and Test - Redis Stack ${{matrix.redis-stack-version}} runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + redis-stack-version: ['6.2.6-v12', '7.2.0-v8', 'edge'] + env: + REDIS_STACK_VERSION: ${{matrix.redis-stack-version}} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up publishing to maven central uses: actions/setup-java@v2 with: java-version: '8' distribution: 'temurin' - - name: System setup - run: | - sudo apt update - sudo apt install -y stunnel make - make system-setup - name: Cache dependencies uses: actions/cache@v2 with: @@ -51,28 +52,10 @@ jobs: mvn javadoc:jar - name: Run tests run: | - TEST="" make test + make test env: JVM_OPTS: -Xmx3200m TERM: dumb - - name: sleep 10s - run: sleep 10s - - name: Make - start - run: | - make start - sleep 2s - - name: Docker - mod or stack - run: docker run -p 52567:6379 -d redis/redis-stack-server:edge - - name: Test commands - default protocol - run: mvn -Dtest="redis.clients.jedis.commands.**" test - - name: Test commands - RESP3 protocol - run: mvn -DjedisProtocol=3 -Dtest="redis.clients.jedis.commands.**" test - - name: Test module commands - default protocol - run: mvn -DmodulesDocker="localhost:52567" -Dtest="redis.clients.jedis.modules.**" test - - name: Test module commands - RESP3 protocol - run: mvn -DjedisProtocol=3 -DmodulesDocker="localhost:52567" -Dtest="redis.clients.jedis.modules.**" test - - name: Make - stop - run: make stop - name: Codecov run: | bash <(curl -s https://codecov.io/bash) diff --git a/.gitignore b/.gitignore index 8cb08a2658..2e9666bba3 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ tags *.rdb redis-git appendonlydir/ +*.so diff --git a/Makefile b/Makefile index 6e63f1b6ce..29e9412559 100644 --- a/Makefile +++ b/Makefile @@ -1,476 +1,49 @@ -PATH := ./redis-git/src:${PATH} -STUNNEL_BIN := $(shell which stunnel) - -define REDIS1_CONF -daemonize yes -protected-mode no -port 6379 -requirepass foobared -user acljedis on allcommands allkeys >fizzbuzz -pidfile /tmp/redis1.pid -logfile /tmp/redis1.log -save "" -appendonly no -enable-module-command yes -client-output-buffer-limit pubsub 256k 128k 5 -endef - -define REDIS2_CONF -daemonize yes -protected-mode no -port 6380 -requirepass foobared -pidfile /tmp/redis2.pid -logfile /tmp/redis2.log -save "" -appendonly no -endef - -define REDIS3_CONF -daemonize yes -protected-mode no -port 6381 -requirepass foobared -masterauth foobared -pidfile /tmp/redis3.pid -logfile /tmp/redis3.log -save "" -appendonly no -endef - -define REDIS4_CONF -daemonize yes -protected-mode no -port 6382 -requirepass foobared -masterauth foobared -pidfile /tmp/redis4.pid -logfile /tmp/redis4.log -save "" -appendonly no -slaveof localhost 6381 -endef - -define REDIS5_CONF -daemonize yes -protected-mode no -port 6383 -requirepass foobared -masterauth foobared -pidfile /tmp/redis5.pid -logfile /tmp/redis5.log -save "" -appendonly no -slaveof localhost 6379 -endef - -define REDIS6_CONF -daemonize yes -protected-mode no -port 6384 -requirepass foobared -masterauth foobared -pidfile /tmp/redis6.pid -logfile /tmp/redis6.log -save "" -appendonly no -endef - -define REDIS7_CONF -daemonize yes -protected-mode no -port 6385 -requirepass foobared -masterauth foobared -pidfile /tmp/redis7.pid -logfile /tmp/redis7.log -save "" -appendonly no -slaveof localhost 6384 -endef - -define REDIS8_CONF -daemonize yes -protected-mode no -port 6386 -pidfile /tmp/redis8.pid -logfile /tmp/redis8.log -save "" -appendonly no -maxmemory-policy allkeys-lfu -endef - -define REDIS9_CONF -daemonize yes -protected-mode no -port 6387 -user default off -user acljedis on allcommands allkeys >fizzbuzz -pidfile /tmp/redis9.pid -logfile /tmp/redis9.log -save "" -appendonly no -client-output-buffer-limit pubsub 256k 128k 5 -endef - -define REDIS10_CONF -daemonize yes -protected-mode no -port 6388 -pidfile /tmp/redis10.pid -logfile /tmp/redis10.log -save "" -appendonly no -endef - -define REDIS11_CONF -daemonize yes -protected-mode no -port 6389 -pidfile /tmp/redis11.pid -logfile /tmp/redis11.log -save "" -appendonly no -replicaof localhost 6388 -endef - -# SENTINELS -define REDIS_SENTINEL1 -port 26379 -daemonize yes -protected-mode no -sentinel monitor mymaster 127.0.0.1 6379 1 -sentinel auth-pass mymaster foobared -sentinel down-after-milliseconds mymaster 2000 -sentinel failover-timeout mymaster 120000 -sentinel parallel-syncs mymaster 1 -pidfile /tmp/sentinel1.pid -logfile /tmp/sentinel1.log -endef - -define REDIS_SENTINEL2 -port 26380 -daemonize yes -protected-mode no -sentinel monitor mymaster 127.0.0.1 6381 1 -sentinel auth-pass mymaster foobared -sentinel down-after-milliseconds mymaster 2000 -sentinel parallel-syncs mymaster 1 -sentinel failover-timeout mymaster 120000 -pidfile /tmp/sentinel2.pid -logfile /tmp/sentinel2.log -endef - -define REDIS_SENTINEL3 -port 26381 -daemonize yes -protected-mode no -sentinel monitor mymasterfailover 127.0.0.1 6384 1 -sentinel auth-pass mymasterfailover foobared -sentinel down-after-milliseconds mymasterfailover 2000 -sentinel failover-timeout mymasterfailover 120000 -sentinel parallel-syncs mymasterfailover 1 -pidfile /tmp/sentinel3.pid -logfile /tmp/sentinel3.log -endef - -define REDIS_SENTINEL4 -port 26382 -daemonize yes -protected-mode no -sentinel monitor mymaster 127.0.0.1 6381 1 -sentinel auth-pass mymaster foobared -sentinel down-after-milliseconds mymaster 2000 -sentinel parallel-syncs mymaster 1 -sentinel failover-timeout mymaster 120000 -pidfile /tmp/sentinel4.pid -logfile /tmp/sentinel4.log -endef - -define REDIS_SENTINEL5 -port 26383 -daemonize yes -protected-mode no -user default off -user sentinel on allcommands allkeys allchannels >foobared -sentinel monitor aclmaster 127.0.0.1 6387 1 -sentinel auth-user aclmaster acljedis -sentinel auth-pass aclmaster fizzbuzz -sentinel down-after-milliseconds aclmaster 2000 -sentinel failover-timeout aclmaster 120000 -sentinel parallel-syncs aclmaster 1 -pidfile /tmp/sentinel5.pid -logfile /tmp/sentinel5.log -endef - -# CLUSTER REDIS NODES -define REDIS_CLUSTER_NODE1_CONF -daemonize yes -protected-mode no -requirepass cluster -port 7379 -cluster-node-timeout 15000 -pidfile /tmp/redis_cluster_node1.pid -logfile /tmp/redis_cluster_node1.log -save "" -appendonly no -cluster-enabled yes -cluster-config-file /tmp/redis_cluster_node1.conf -endef - -define REDIS_CLUSTER_NODE2_CONF -daemonize yes -protected-mode no -requirepass cluster -port 7380 -cluster-node-timeout 15000 -pidfile /tmp/redis_cluster_node2.pid -logfile /tmp/redis_cluster_node2.log -save "" -appendonly no -cluster-enabled yes -cluster-config-file /tmp/redis_cluster_node2.conf -endef - -define REDIS_CLUSTER_NODE3_CONF -daemonize yes -protected-mode no -requirepass cluster -port 7381 -cluster-node-timeout 15000 -pidfile /tmp/redis_cluster_node3.pid -logfile /tmp/redis_cluster_node3.log -save "" -appendonly no -cluster-enabled yes -cluster-config-file /tmp/redis_cluster_node3.conf -endef - -define REDIS_CLUSTER_NODE4_CONF -daemonize yes -protected-mode no -requirepass cluster -port 7382 -cluster-node-timeout 15000 -pidfile /tmp/redis_cluster_node4.pid -logfile /tmp/redis_cluster_node4.log -save "" -appendonly no -cluster-enabled yes -cluster-config-file /tmp/redis_cluster_node4.conf -endef - -define REDIS_CLUSTER_NODE5_CONF -daemonize yes -protected-mode no -requirepass cluster -port 7383 -cluster-node-timeout 15000 -pidfile /tmp/redis_cluster_node5.pid -logfile /tmp/redis_cluster_node5.log -save "" -appendonly no -cluster-enabled yes -cluster-config-file /tmp/redis_cluster_node5.conf -endef - -# UDS REDIS NODES -define REDIS_UDS -daemonize yes -protected-mode no -port 0 -pidfile /tmp/redis_uds.pid -logfile /tmp/redis_uds.log -unixsocket /tmp/redis_uds.sock -unixsocketperm 777 -save "" -appendonly no -endef - -# UNAVAILABLE REDIS NODES -define REDIS_UNAVAILABLE_CONF -daemonize yes -protected-mode no -port 6400 -pidfile /tmp/redis_unavailable.pid -logfile /tmp/redis_unavailable.log -save "" -appendonly no -endef - -#STUNNEL -define STUNNEL_CONF -cert = src/test/resources/private.pem -pid = /tmp/stunnel.pid -[redis_1] -accept = 127.0.0.1:6390 -connect = 127.0.0.1:6379 -[redis_3] -accept = 127.0.0.1:16381 -connect = 127.0.0.1:6381 -[redis_4] -accept = 127.0.0.1:16382 -connect = 127.0.0.1:6382 -[redis_9] -accept = 127.0.0.1:16387 -connect = 127.0.0.1:6387 -[redis_cluster_1] -accept = 127.0.0.1:8379 -connect = 127.0.0.1:7379 -[redis_cluster_2] -accept = 127.0.0.1:8380 -connect = 127.0.001:7380 -[redis_cluster_3] -accept = 127.0.0.1:8381 -connect = 127.0.001:7381 -[redis_cluster_4] -accept = 127.0.0.1:8382 -connect = 127.0.0.1:7382 -[redis_cluster_5] -accept = 127.0.0.1:8383 -connect = 127.0.0.1:7383 -[redis_sentinel_5] -accept = 127.0.0.1:36383 -connect = 127.0.0.1:26383 -endef - -export REDIS1_CONF -export REDIS2_CONF -export REDIS3_CONF -export REDIS4_CONF -export REDIS5_CONF -export REDIS6_CONF -export REDIS7_CONF -export REDIS8_CONF -export REDIS9_CONF -export REDIS10_CONF -export REDIS11_CONF -export REDIS_SENTINEL1 -export REDIS_SENTINEL2 -export REDIS_SENTINEL3 -export REDIS_SENTINEL4 -export REDIS_SENTINEL5 -export REDIS_CLUSTER_NODE1_CONF -export REDIS_CLUSTER_NODE2_CONF -export REDIS_CLUSTER_NODE3_CONF -export REDIS_CLUSTER_NODE4_CONF -export REDIS_CLUSTER_NODE5_CONF -export REDIS_UDS -export REDIS_UNAVAILABLE_CONF -export STUNNEL_CONF -export STUNNEL_BIN - - -ifndef STUNNEL_BIN - SKIP_SSL := !SSL*, -endif -export SKIP_SSL - -start: stunnel cleanup - echo "$$REDIS1_CONF" | redis-server - - echo "$$REDIS2_CONF" | redis-server - - echo "$$REDIS3_CONF" | redis-server - - echo "$$REDIS4_CONF" | redis-server - - echo "$$REDIS5_CONF" | redis-server - - echo "$$REDIS6_CONF" | redis-server - - echo "$$REDIS7_CONF" | redis-server - - echo "$$REDIS8_CONF" | redis-server - - echo "$$REDIS9_CONF" | redis-server - - echo "$$REDIS10_CONF" | redis-server - - echo "$$REDIS11_CONF" | redis-server - - echo "$$REDIS_SENTINEL1" > /tmp/sentinel1.conf && redis-server /tmp/sentinel1.conf --sentinel - @sleep 0.5 - echo "$$REDIS_SENTINEL2" > /tmp/sentinel2.conf && redis-server /tmp/sentinel2.conf --sentinel - @sleep 0.5 - echo "$$REDIS_SENTINEL3" > /tmp/sentinel3.conf && redis-server /tmp/sentinel3.conf --sentinel - @sleep 0.5 - echo "$$REDIS_SENTINEL4" > /tmp/sentinel4.conf && redis-server /tmp/sentinel4.conf --sentinel - @sleep 0.5 - echo "$$REDIS_SENTINEL5" > /tmp/sentinel5.conf && redis-server /tmp/sentinel5.conf --sentinel - @sleep 0.5 - echo "$$REDIS_CLUSTER_NODE1_CONF" | redis-server - - echo "$$REDIS_CLUSTER_NODE2_CONF" | redis-server - - echo "$$REDIS_CLUSTER_NODE3_CONF" | redis-server - - echo "$$REDIS_CLUSTER_NODE4_CONF" | redis-server - - echo "$$REDIS_CLUSTER_NODE5_CONF" | redis-server - - echo "$$REDIS_UDS" | redis-server - - echo "$$REDIS_UNAVAILABLE_CONF" | redis-server - +format: + mvn java-formatter:format -cleanup: - - rm -vf /tmp/redis_cluster_node*.conf 2>/dev/null - - rm dump.rdb appendonly.aof - 2>/dev/null +start: compile-module + cd test-infra/no-cluster; docker-compose up -d --build --remove-orphans + cd test-infra/oss-cluster; docker-compose up -d --remove-orphans -stunnel: - @if [ -e "$$STUNNEL_BIN" ]; then\ - echo "$$STUNNEL_CONF" | stunnel -fd 0;\ - fi stop: - kill `cat /tmp/redis1.pid` - kill `cat /tmp/redis2.pid` - kill `cat /tmp/redis3.pid` - kill `cat /tmp/redis4.pid` - kill `cat /tmp/redis5.pid` - kill `cat /tmp/redis6.pid` - kill `cat /tmp/redis7.pid` - kill `cat /tmp/redis8.pid` - kill `cat /tmp/redis9.pid` - kill `cat /tmp/redis10.pid` - kill `cat /tmp/redis11.pid` - kill `cat /tmp/sentinel1.pid` - kill `cat /tmp/sentinel2.pid` - kill `cat /tmp/sentinel3.pid` - kill `cat /tmp/sentinel4.pid` - kill `cat /tmp/sentinel5.pid` - kill `cat /tmp/redis_cluster_node1.pid` || true - kill `cat /tmp/redis_cluster_node2.pid` || true - 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_uds.pid` || true - kill `cat /tmp/stunnel.pid` || true - [ -f /tmp/redis_unavailable.pid ] && kill `cat /tmp/redis_unavailable.pid` || true - rm -f /tmp/sentinel1.conf - rm -f /tmp/sentinel2.conf - rm -f /tmp/sentinel3.conf - rm -f /tmp/sentinel4.conf - rm -f /tmp/sentinel5.conf - rm -f /tmp/redis_cluster_node1.conf - rm -f /tmp/redis_cluster_node2.conf - rm -f /tmp/redis_cluster_node3.conf - rm -f /tmp/redis_cluster_node4.conf - rm -f /tmp/redis_cluster_node5.conf - -test: compile-module start - sleep 2 - mvn -Dtest=${SKIP_SSL}${TEST} clean compile test - make stop - -package: start + cd test-infra/no-cluster; docker-compose down -v + cd test-infra/oss-cluster; docker-compose down -v + +mvn-test: + echo Base tests + mvn clean test + echo Test commands - default protocol + mvn -Dtest="redis.clients.jedis.commands.**" test + echo Test commands - RESP3 protocol + mvn -DjedisProtocol=3 -Dtest="redis.clients.jedis.commands.**" test + echo Test module commands - default protocol + mvn -DmodulesDocker="localhost:6379" -Dtest="redis.clients.jedis.modules.**" test + echo Test module commands - RESP3 protocol + mvn -DjedisProtocol=3 -DmodulesDocker="localhost:6379" -Dtest="redis.clients.jedis.modules.**" test + +test: | start mvn-test stop + +mvn-package: mvn clean package - make stop -deploy: start +package: | start mvn-package stop + +mvn-deploy: mvn clean deploy - make stop -format: - mvn java-formatter:format +deploy: | start mvn-deploy stop -release: - make start +mvn-release: mvn release:clean mvn release:prepare mvn release:perform -DskipTests - make stop + +release: | start mvn-release stop system-setup: sudo apt install -y gcc g++ - [ ! -e redis-git ] && git clone https://github.com/redis/redis.git --branch unstable --single-branch redis-git || true - $(MAKE) -C redis-git clean - $(MAKE) -C redis-git - -compile-module: - gcc -shared -o /tmp/testmodule.so -fPIC src/test/resources/testmodule.c +compile-module: system-setup + gcc -shared -o test-infra/no-cluster/testmodule.so -fPIC src/test/resources/testmodule.c .PHONY: test diff --git a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java index 3ed45bae63..e73c7c9bbf 100644 --- a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java +++ b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java @@ -26,8 +26,6 @@ public class ClusterPipeliningTest { - private static final String LOCAL_IP = "127.0.0.1"; - private static final DefaultJedisClientConfig DEFAULT_CLIENT_CONFIG = DefaultJedisClientConfig.builder().password("cluster").build(); @@ -55,8 +53,8 @@ public static void setUp() throws InterruptedException { node3.flushAll(); // add nodes to cluster - node1.clusterMeet(LOCAL_IP, nodeInfo2.getPort()); - node1.clusterMeet(LOCAL_IP, nodeInfo3.getPort()); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(2), 6379); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(3), 6379); // split available slots across the three nodes int slotsPerNode = CLUSTER_HASHSLOTS / 3; diff --git a/src/test/java/redis/clients/jedis/JedisClusterTest.java b/src/test/java/redis/clients/jedis/JedisClusterTest.java index 8297eb90c6..bc1f992924 100644 --- a/src/test/java/redis/clients/jedis/JedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/JedisClusterTest.java @@ -55,7 +55,7 @@ public void testMovedExceptionParameters() { node1.set("foo", "bar"); } catch (JedisMovedDataException jme) { assertEquals(12182, jme.getSlot()); - assertEquals(new HostAndPort("127.0.0.1", 7381), jme.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(3), 6379), jme.getTargetNode()); return; } fail(); @@ -170,7 +170,7 @@ public void testCalculateConnectionPerSlot() { @Test public void testReadonlyAndReadwrite() throws Exception { - node1.clusterMeet(LOCAL_IP, nodeInfoSlave2.getPort()); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(5), 6379); JedisClusterTestUtil.waitForClusterReady(node1, node2, node3, nodeSlave2); for (String nodeInfo : node2.clusterNodes().split("\n")) { @@ -216,14 +216,14 @@ public void testMigrate() { node2.set("e", "e"); } catch (JedisMovedDataException jme) { assertEquals(15363, jme.getSlot()); - assertEquals(new HostAndPort(LOCAL_IP, nodeInfo3.getPort()), jme.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(3), 6379), jme.getTargetNode()); } try { node3.set("e", "e"); } catch (JedisAskDataException jae) { assertEquals(15363, jae.getSlot()); - assertEquals(new HostAndPort(LOCAL_IP, nodeInfo2.getPort()), jae.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(2), 6379), jae.getTargetNode()); } jc.set("e", "e"); @@ -232,13 +232,13 @@ public void testMigrate() { node2.get("e"); } catch (JedisMovedDataException jme) { assertEquals(15363, jme.getSlot()); - assertEquals(new HostAndPort(LOCAL_IP, nodeInfo3.getPort()), jme.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(3), 6379), jme.getTargetNode()); } try { node3.get("e"); } catch (JedisAskDataException jae) { assertEquals(15363, jae.getSlot()); - assertEquals(new HostAndPort(LOCAL_IP, nodeInfo2.getPort()), jae.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(2), 6379), jae.getTargetNode()); } assertEquals("e", jc.get("e")); @@ -258,7 +258,7 @@ public void testMigrateToNewNode() throws InterruptedException { jedisClusterNode.add(nodeInfo1); try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { - node3.clusterMeet(LOCAL_IP, nodeInfo4.getPort()); + node3.clusterMeet(JedisClusterTestUtil.getClusterIp(4), 6379); String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes()); String node4Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes()); @@ -269,21 +269,21 @@ public void testMigrateToNewNode() throws InterruptedException { node4.set("e", "e"); } catch (JedisMovedDataException jme) { assertEquals(15363, jme.getSlot()); - assertEquals(new HostAndPort(LOCAL_IP, nodeInfo3.getPort()), jme.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(3), 6379), jme.getTargetNode()); } try { node3.set("e", "e"); } catch (JedisAskDataException jae) { assertEquals(15363, jae.getSlot()); - assertEquals(new HostAndPort(LOCAL_IP, nodeInfo4.getPort()), jae.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(4), 6379), jae.getTargetNode()); } try { node3.set("e", "e"); } catch (JedisAskDataException jae) { assertEquals(15363, jae.getSlot()); - assertEquals(new HostAndPort(LOCAL_IP, nodeInfo4.getPort()), jae.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(4), 6379), jae.getTargetNode()); } jc.set("e", "e"); @@ -292,13 +292,13 @@ public void testMigrateToNewNode() throws InterruptedException { node4.get("e"); } catch (JedisMovedDataException jme) { assertEquals(15363, jme.getSlot()); - assertEquals(new HostAndPort(LOCAL_IP, nodeInfo3.getPort()), jme.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(3), 6379), jme.getTargetNode()); } try { node3.get("e"); } catch (JedisAskDataException jae) { assertEquals(15363, jae.getSlot()); - assertEquals(new HostAndPort(LOCAL_IP, nodeInfo4.getPort()), jae.getTargetNode()); + assertEquals(new HostAndPort(JedisClusterTestUtil.getClusterIp(4), 6379), jae.getTargetNode()); } assertEquals("e", jc.get("e")); @@ -389,9 +389,9 @@ public void testRedisClusterMaxRedirectionsWithConfig() { @Test public void testClusterForgetNode() throws InterruptedException { // at first, join node4 to cluster - node1.clusterMeet("127.0.0.1", nodeInfo4.getPort()); - node2.clusterMeet("127.0.0.1", nodeInfo4.getPort()); - node3.clusterMeet("127.0.0.1", nodeInfo4.getPort()); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(4), 6379); + node2.clusterMeet(JedisClusterTestUtil.getClusterIp(4), 6379); + node3.clusterMeet(JedisClusterTestUtil.getClusterIp(4), 6379); String node4Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes()); @@ -610,7 +610,7 @@ public void testReturnConnectionOnJedisConnectionException() throws InterruptedE // ClientKillerUtil.tagClient(j, "DEAD"); // ClientKillerUtil.killClient(j, "DEAD"); // } - try (Connection c = jc.getClusterNodes().get("127.0.0.1:7380").getResource()) { + try (Connection c = jc.getClusterNodes().get(JedisClusterTestUtil.getClusterIpWithPort(2)).getResource()) { Jedis j = new Jedis(c); ClientKillerUtil.tagClient(j, "DEAD"); ClientKillerUtil.killClient(j, "DEAD"); @@ -698,9 +698,9 @@ public void clusterRefreshNodes() throws Exception { cleanUp(); // cleanup and add node4 // at first, join node4 to cluster - node1.clusterMeet(LOCAL_IP, nodeInfo2.getPort()); - node1.clusterMeet(LOCAL_IP, nodeInfo3.getPort()); - node1.clusterMeet(LOCAL_IP, nodeInfo4.getPort()); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(2), 6379); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(3), 6379); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(4), 6379); // split available slots across the three nodes int slotsPerNode = CLUSTER_HASHSLOTS / 4; int[] node1Slots = new int[slotsPerNode]; @@ -729,8 +729,7 @@ public void clusterRefreshNodes() throws Exception { cluster.set("key", "value"); assertEquals(4, cluster.getClusterNodes().size()); - String nodeKey4 = LOCAL_IP + ":" + nodeInfo4.getPort(); - assertTrue(cluster.getClusterNodes().keySet().contains(nodeKey4)); + assertTrue(cluster.getClusterNodes().keySet().contains(JedisClusterTestUtil.getClusterIpWithPort(4))); // make 4 nodes to 3 nodes cleanUp(); @@ -756,9 +755,9 @@ public void clusterPeriodTopologyRefreshTest() throws Exception { cleanUp(); // cleanup and add node4 // at first, join node4 to cluster - node1.clusterMeet(LOCAL_IP, nodeInfo2.getPort()); - node1.clusterMeet(LOCAL_IP, nodeInfo3.getPort()); - node1.clusterMeet(LOCAL_IP, nodeInfo4.getPort()); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(2), 6379); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(3), 6379); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(4), 6379); // split available slots across the three nodes int slotsPerNode = CLUSTER_HASHSLOTS / 4; int[] node1Slots = new int[slotsPerNode]; @@ -787,8 +786,7 @@ public void clusterPeriodTopologyRefreshTest() throws Exception { Thread.sleep(topologyRefreshPeriod.toMillis() * 3); assertEquals(4, cluster.getClusterNodes().size()); - String nodeKey4 = LOCAL_IP + ":" + nodeInfo4.getPort(); - assertTrue(cluster.getClusterNodes().keySet().contains(nodeKey4)); + assertTrue(cluster.getClusterNodes().keySet().contains(JedisClusterTestUtil.getClusterIpWithPort(4))); // make 4 nodes to 3 nodes cleanUp(); diff --git a/src/test/java/redis/clients/jedis/JedisClusterTestBase.java b/src/test/java/redis/clients/jedis/JedisClusterTestBase.java index 0746c2d37c..1ecd86ddcf 100644 --- a/src/test/java/redis/clients/jedis/JedisClusterTestBase.java +++ b/src/test/java/redis/clients/jedis/JedisClusterTestBase.java @@ -47,8 +47,8 @@ public void setUp() throws InterruptedException { // ---- configure cluster // add nodes to cluster - node1.clusterMeet(LOCAL_IP, nodeInfo2.getPort()); - node1.clusterMeet(LOCAL_IP, nodeInfo3.getPort()); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(2), 6379); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(3), 6379); // split available slots across the three nodes int slotsPerNode = CLUSTER_HASHSLOTS / 3; diff --git a/src/test/java/redis/clients/jedis/SSLACLJedisClusterTest.java b/src/test/java/redis/clients/jedis/SSLACLJedisClusterTest.java index c2f0e0ee3a..d45b6216d7 100644 --- a/src/test/java/redis/clients/jedis/SSLACLJedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/SSLACLJedisClusterTest.java @@ -2,6 +2,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static redis.clients.jedis.SSLJedisClusterTest.hostAndPortMap; +import static redis.clients.jedis.SSLJedisClusterTest.portMap; import java.util.Collections; import java.util.Map; @@ -16,6 +18,7 @@ import redis.clients.jedis.exceptions.JedisClusterOperationException; import redis.clients.jedis.SSLJedisTest.BasicHostnameVerifier; +import redis.clients.jedis.util.JedisClusterTestUtil; import redis.clients.jedis.util.RedisVersionUtil; public class SSLACLJedisClusterTest extends JedisClusterTestBase { @@ -23,24 +26,6 @@ public class SSLACLJedisClusterTest extends JedisClusterTestBase { private static final int DEFAULT_REDIRECTIONS = 5; private static final ConnectionPoolConfig DEFAULT_POOL_CONFIG = new ConnectionPoolConfig(); - private final HostAndPortMapper hostAndPortMap = (HostAndPort hostAndPort) -> { - String host = hostAndPort.getHost(); - int port = hostAndPort.getPort(); - if (host.equals("127.0.0.1")) { - host = "localhost"; - port = port + 1000; - } - return new HostAndPort(host, port); - }; - - // don't map IP addresses so that we try to connect with host 127.0.0.1 - private final HostAndPortMapper portMap = (HostAndPort hostAndPort) -> { - if ("localhost".equals(hostAndPort.getHost())) { - return hostAndPort; - } - return new HostAndPort(hostAndPort.getHost(), hostAndPort.getPort() + 1000); - }; - @BeforeClass public static void prepare() { org.junit.Assume.assumeTrue("Not running ACL test on this version of Redis", @@ -56,9 +41,9 @@ public void testSSLDiscoverNodesAutomatically() { .hostAndPortMapper(hostAndPortMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); - assertTrue(clusterNodes.containsKey("127.0.0.1:7379")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7380")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7381")); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(1))); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(2))); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(3))); jc.get("foo"); } @@ -67,9 +52,9 @@ public void testSSLDiscoverNodesAutomatically() { .hostAndPortMapper(hostAndPortMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { Map clusterNodes = jc2.getClusterNodes(); assertEquals(3, clusterNodes.size()); - assertTrue(clusterNodes.containsKey("127.0.0.1:7379")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7380")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7381")); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(1))); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(2))); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(3))); jc2.get("foo"); } } @@ -82,9 +67,9 @@ public void testSSLWithoutPortMap() { // Map clusterNodes = jc.getClusterNodes(); Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); - assertTrue(clusterNodes.containsKey("127.0.0.1:7379")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7380")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7381")); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(1))); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(2))); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(3))); } } @@ -151,7 +136,7 @@ public void connectByIpAddressFailsWithSSLParameters() { @Test public void connectWithCustomHostNameVerifier() { HostnameVerifier hostnameVerifier = new BasicHostnameVerifier(); - HostnameVerifier localhostVerifier = new LocalhostVerifier(); + HostnameVerifier localhostVerifier = new SSLJedisClusterTest.LocalhostVerifier(); try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) @@ -225,19 +210,9 @@ public void defaultHostAndPortUsedIfMapReturnsNull() { .hostAndPortMapper(nullHostAndPortMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); - assertTrue(clusterNodes.containsKey("127.0.0.1:7379")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7380")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7381")); - } - } - - public class LocalhostVerifier extends BasicHostnameVerifier { - @Override - public boolean verify(String hostname, SSLSession session) { - if (hostname.equals("127.0.0.1")) { - hostname = "localhost"; - } - return super.verify(hostname, session); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(1))); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(2))); + assertTrue(clusterNodes.containsKey(JedisClusterTestUtil.getClusterIpWithPort(3))); } } } diff --git a/src/test/java/redis/clients/jedis/SSLJedisClusterTest.java b/src/test/java/redis/clients/jedis/SSLJedisClusterTest.java index f4763fe875..0abdb5af76 100644 --- a/src/test/java/redis/clients/jedis/SSLJedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/SSLJedisClusterTest.java @@ -22,21 +22,37 @@ public class SSLJedisClusterTest extends JedisClusterTestBase { private static final int DEFAULT_REDIRECTIONS = 5; private static final ConnectionPoolConfig DEFAULT_POOL_CONFIG = new ConnectionPoolConfig(); - private final HostAndPortMapper hostAndPortMap = (HostAndPort hostAndPort) -> { + static final HostAndPortMapper hostAndPortMap = (HostAndPort hostAndPort) -> { String host = hostAndPort.getHost(); int port = hostAndPort.getPort(); if (host.equals("127.0.0.1")) { host = "localhost"; port = port + 1000; + } else if (host.startsWith("172")) { + host = "localhost"; + port = mapClusterPort(hostAndPort.getHost(), hostAndPort.getPort()); } return new HostAndPort(host, port); }; + private static int mapClusterPort(String host, int port) { + String[] segments = host.split("\\."); + if (segments.length == 4) { + int lastSegment = Integer.parseInt(segments[3]); + int delta = lastSegment - 31; // 172.20.0.31 is the first IP in the cluster + return 6379 + delta + 2000; // stunnel serves OSS cluster nodes on 8379... + } + return port; + } + // don't map IP addresses so that we try to connect with host 127.0.0.1 - private final HostAndPortMapper portMap = (HostAndPort hostAndPort) -> { + static final HostAndPortMapper portMap = (HostAndPort hostAndPort) -> { if ("localhost".equals(hostAndPort.getHost())) { return hostAndPort; } + if (hostAndPort.getHost().startsWith("172")) { + return new HostAndPort("127.0.0.1", mapClusterPort(hostAndPort.getHost(), hostAndPort.getPort())); + } return new HostAndPort(hostAndPort.getHost(), hostAndPort.getPort() + 1000); }; @@ -53,9 +69,9 @@ public void testSSLDiscoverNodesAutomatically() { // Map clusterNodes = jc.getClusterNodes(); Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); - assertTrue(clusterNodes.containsKey("127.0.0.1:7379")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7380")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7381")); + assertTrue(clusterNodes.containsKey("172.20.0.31:6379")); + assertTrue(clusterNodes.containsKey("172.20.0.32:6379")); + assertTrue(clusterNodes.containsKey("172.20.0.33:6379")); jc.get("foo"); } @@ -66,9 +82,9 @@ public void testSSLDiscoverNodesAutomatically() { // Map clusterNodes = jc2.getClusterNodes(); Map clusterNodes = jc2.getClusterNodes(); assertEquals(3, clusterNodes.size()); - assertTrue(clusterNodes.containsKey("127.0.0.1:7379")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7380")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7381")); + assertTrue(clusterNodes.containsKey("172.20.0.31:6379")); + assertTrue(clusterNodes.containsKey("172.20.0.32:6379")); + assertTrue(clusterNodes.containsKey("172.20.0.33:6379")); jc2.get("foo"); } } @@ -81,9 +97,9 @@ public void testSSLWithoutPortMap() { // Map clusterNodes = jc.getClusterNodes(); Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); - assertTrue(clusterNodes.containsKey("127.0.0.1:7379")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7380")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7381")); + assertTrue(clusterNodes.containsKey("172.20.0.31:6379")); + assertTrue(clusterNodes.containsKey("172.20.0.32:6379")); + assertTrue(clusterNodes.containsKey("172.20.0.33:6379")); } } @@ -226,16 +242,16 @@ public void defaultHostAndPortUsedIfMapReturnsNull() { // Map clusterNodes = jc.getClusterNodes(); Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); - assertTrue(clusterNodes.containsKey("127.0.0.1:7379")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7380")); - assertTrue(clusterNodes.containsKey("127.0.0.1:7381")); + assertTrue(clusterNodes.containsKey("172.20.0.31:6379")); + assertTrue(clusterNodes.containsKey("172.20.0.32:6379")); + assertTrue(clusterNodes.containsKey("172.20.0.33:6379")); } } - public class LocalhostVerifier extends BasicHostnameVerifier { + public static class LocalhostVerifier extends BasicHostnameVerifier { @Override public boolean verify(String hostname, SSLSession session) { - if (hostname.equals("127.0.0.1")) { + if (hostname.equals("127.0.0.1") || hostname.startsWith("172.")) { hostname = "localhost"; } return super.verify(hostname, session); diff --git a/src/test/java/redis/clients/jedis/SSLJedisSentinelPoolTest.java b/src/test/java/redis/clients/jedis/SSLJedisSentinelPoolTest.java index 7468c9abfa..9d4a7db022 100644 --- a/src/test/java/redis/clients/jedis/SSLJedisSentinelPoolTest.java +++ b/src/test/java/redis/clients/jedis/SSLJedisSentinelPoolTest.java @@ -12,11 +12,32 @@ public class SSLJedisSentinelPoolTest { private static Set sentinels = new HashSet<>(); - private static final HostAndPortMapper SSL_PORT_MAPPER = (HostAndPort hap) - -> new HostAndPort(hap.getHost(), hap.getPort() + 10000); - + // don't map IP addresses so that we try to connect with host 127.0.0.1 + private final HostAndPortMapper SSL_PORT_MAPPER = (HostAndPort hostAndPort) -> { + if (hostAndPort.getHost().startsWith("172")) { + return mapClusterAddress(hostAndPort.getHost(), hostAndPort.getPort()); + } + return new HostAndPort(hostAndPort.getHost(), hostAndPort.getPort() + 10000); + }; private static final GenericObjectPoolConfig POOL_CONFIG = new GenericObjectPoolConfig<>(); + private static HostAndPort mapClusterAddress(String host, int port) { + String[] segments = host.split("\\."); + if (segments.length == 4) { + int lastSegment = Integer.parseInt(segments[3]); + host = "127.0.0.1"; + if (lastSegment < 30) { + int delta = lastSegment - 10; // 172.21.0.10 is the first IP for non-sentinels + port = 6379 + delta + 10000; // stunnel serves non-sentinels on 16379... + } else { + int delta = lastSegment - 31; // 172.21.0.31 is the first IP for sentinels + port = 26379 + delta + 10000; // stunnel serves sentinels on 36379... + } + } + return new HostAndPort(host, port); + } + + @BeforeClass public static void prepare() { SSLJedisTest.setupTrustStore(); diff --git a/src/test/java/redis/clients/jedis/UdsTest.java b/src/test/java/redis/clients/jedis/UdsTest.java index e29c65dedd..ca88967d1f 100644 --- a/src/test/java/redis/clients/jedis/UdsTest.java +++ b/src/test/java/redis/clients/jedis/UdsTest.java @@ -44,7 +44,7 @@ public void unifiedJedisConnectsToUdsResp3() { private static class UdsJedisSocketFactory implements JedisSocketFactory { - private static final File UDS_SOCKET = new File("/tmp/redis_uds.sock"); + private static final File UDS_SOCKET = new File("/var/run/redis_uds.sock"); @Override public Socket createSocket() throws JedisConnectionException { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ClusterCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ClusterCommandsTest.java index 7e5c5db875..d2ee480486 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ClusterCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ClusterCommandsTest.java @@ -75,7 +75,7 @@ public static void removeSlots() { @Test public void testClusterSoftReset() { - node1.clusterMeet("127.0.0.1", nodeInfo2.getPort()); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(2), nodeInfo2.getPort()); assertTrue(node1.clusterNodes().split("\n").length > 1); node1.clusterReset(ClusterResetType.SOFT); assertEquals(1, node1.clusterNodes().split("\n").length); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ClusterJedisCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/jedis/ClusterJedisCommandsTestBase.java index 8cd4b8379d..af58922206 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ClusterJedisCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ClusterJedisCommandsTestBase.java @@ -14,6 +14,7 @@ import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.JedisCluster; import redis.clients.jedis.util.JedisClusterCRC16; +import redis.clients.jedis.util.JedisClusterTestUtil; public abstract class ClusterJedisCommandsTestBase { @@ -44,8 +45,8 @@ public void setUp() throws InterruptedException { // ---- configure cluster // add nodes to cluster - node1.clusterMeet("127.0.0.1", nodeInfo2.getPort()); - node1.clusterMeet("127.0.0.1", nodeInfo3.getPort()); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(2), 6379); + node1.clusterMeet(JedisClusterTestUtil.getClusterIp(3), 6379); // split available slots across the three nodes // int slotsPerNode = JedisCluster.HASHSLOTS / 3; diff --git a/src/test/java/redis/clients/jedis/commands/jedis/MigrateTest.java b/src/test/java/redis/clients/jedis/commands/jedis/MigrateTest.java index 1a0f7a0b6e..55bfbdc0bf 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/MigrateTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/MigrateTest.java @@ -30,7 +30,13 @@ public class MigrateTest extends JedisCommandsTestBase { private Jedis destAuth; private static final String host = hnp.getHost(); private static final int port = 6386; + private static final String dockerHost = "redis-8"; + private static final int dockerPort = 6379; private static final int portAuth = hnp.getPort() + 1; + private static final String dockerHostAuth = "redis-2"; + private static final int dockerPortAuth = 6379; + private static final String dockerHostAuth2 = "redis-1"; + private static final int dockerPortAuth2 = 6379; private static final int db = 2; private static final int dbAuth = 3; private static final int timeout = Protocol.DEFAULT_TIMEOUT; @@ -40,11 +46,11 @@ public class MigrateTest extends JedisCommandsTestBase { public void setUp() throws Exception { super.setUp(); - dest = new Jedis(host, port, 500); + dest = new Jedis(host, port, 1000); dest.flushAll(); dest.select(db); - destAuth = new Jedis(host, portAuth, 500); + destAuth = new Jedis(host, portAuth, 1000); destAuth.auth("foobared"); destAuth.flushAll(); destAuth.select(dbAuth); @@ -60,23 +66,23 @@ public void tearDown() throws Exception { @Test public void nokey() { - assertEquals("NOKEY", jedis.migrate(host, port, "foo", db, timeout)); - assertEquals("NOKEY", jedis.migrate(host, port, bfoo, db, timeout)); + assertEquals("NOKEY", jedis.migrate(dockerHost, dockerPort, "foo", db, timeout)); + assertEquals("NOKEY", jedis.migrate(dockerHost, dockerPort, bfoo, db, timeout)); assertEquals("NOKEY", - jedis.migrate(host, port, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3")); + jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3")); assertEquals("NOKEY", - jedis.migrate(host, port, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3)); + jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3)); } @Test public void migrate() { jedis.set("foo", "bar"); - assertEquals("OK", jedis.migrate(host, port, "foo", db, timeout)); + assertEquals("OK", jedis.migrate(dockerHost, dockerPort, "foo", db, timeout)); assertEquals("bar", dest.get("foo")); assertNull(jedis.get("foo")); jedis.set(bfoo, bbar); - assertEquals("OK", jedis.migrate(host, port, bfoo, db, timeout)); + assertEquals("OK", jedis.migrate(dockerHost, dockerPort, bfoo, db, timeout)); assertArrayEquals(bbar, dest.get(bfoo)); assertNull(jedis.get(bfoo)); } @@ -84,12 +90,12 @@ public void migrate() { @Test public void migrateEmptyParams() { jedis.set("foo", "bar"); - assertEquals("OK", jedis.migrate(host, port, db, timeout, new MigrateParams(), "foo")); + assertEquals("OK", jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams(), "foo")); assertEquals("bar", dest.get("foo")); assertNull(jedis.get("foo")); jedis.set(bfoo, bbar); - assertEquals("OK", jedis.migrate(host, port, db, timeout, new MigrateParams(), bfoo)); + assertEquals("OK", jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams(), bfoo)); assertArrayEquals(bbar, dest.get(bfoo)); assertNull(jedis.get(bfoo)); } @@ -97,12 +103,12 @@ public void migrateEmptyParams() { @Test public void migrateCopy() { jedis.set("foo", "bar"); - assertEquals("OK", jedis.migrate(host, port, db, timeout, new MigrateParams().copy(), "foo")); + assertEquals("OK", jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams().copy(), "foo")); assertEquals("bar", dest.get("foo")); assertEquals("bar", jedis.get("foo")); jedis.set(bfoo, bbar); - assertEquals("OK", jedis.migrate(host, port, db, timeout, new MigrateParams().copy(), bfoo)); + assertEquals("OK", jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams().copy(), bfoo)); assertArrayEquals(bbar, dest.get(bfoo)); assertArrayEquals(bbar, jedis.get(bfoo)); } @@ -111,13 +117,13 @@ public void migrateCopy() { public void migrateReplace() { jedis.set("foo", "bar1"); dest.set("foo", "bar2"); - assertEquals("OK", jedis.migrate(host, port, db, timeout, new MigrateParams().replace(), "foo")); + assertEquals("OK", jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams().replace(), "foo")); assertEquals("bar1", dest.get("foo")); assertNull(jedis.get("foo")); jedis.set(bfoo, bbar1); dest.set(bfoo, bbar2); - assertEquals("OK", jedis.migrate(host, port, db, timeout, new MigrateParams().replace(), bfoo)); + assertEquals("OK", jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams().replace(), bfoo)); assertArrayEquals(bbar1, dest.get(bfoo)); assertNull(jedis.get(bfoo)); } @@ -127,14 +133,14 @@ public void migrateCopyReplace() { jedis.set("foo", "bar1"); dest.set("foo", "bar2"); assertEquals("OK", - jedis.migrate(host, port, db, timeout, new MigrateParams().copy().replace(), "foo")); + jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams().copy().replace(), "foo")); assertEquals("bar1", dest.get("foo")); assertEquals("bar1", jedis.get("foo")); jedis.set(bfoo, bbar1); dest.set(bfoo, bbar2); assertEquals("OK", - jedis.migrate(host, port, db, timeout, new MigrateParams().copy().replace(), bfoo)); + jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams().copy().replace(), bfoo)); assertArrayEquals(bbar1, dest.get(bfoo)); assertArrayEquals(bbar1, jedis.get(bfoo)); } @@ -143,13 +149,13 @@ public void migrateCopyReplace() { public void migrateAuth() { jedis.set("foo", "bar"); assertEquals("OK", - jedis.migrate(host, portAuth, dbAuth, timeout, new MigrateParams().auth("foobared"), "foo")); + jedis.migrate(dockerHostAuth, dockerPortAuth, dbAuth, timeout, new MigrateParams().auth("foobared"), "foo")); assertEquals("bar", destAuth.get("foo")); assertNull(jedis.get("foo")); jedis.set(bfoo, bbar); assertEquals("OK", - jedis.migrate(host, portAuth, dbAuth, timeout, new MigrateParams().auth("foobared"), bfoo)); + jedis.migrate(dockerHostAuth, dockerPortAuth, dbAuth, timeout, new MigrateParams().auth("foobared"), bfoo)); assertArrayEquals(bbar, destAuth.get(bfoo)); assertNull(jedis.get(bfoo)); } @@ -157,14 +163,14 @@ public void migrateAuth() { @Test public void migrateAuth2() { destAuth.set("foo", "bar"); - assertEquals("OK", destAuth.migrate(host, hnp.getPort(), 0, timeout, + assertEquals("OK", destAuth.migrate(dockerHostAuth2, dockerPortAuth2, 0, timeout, new MigrateParams().auth2("acljedis", "fizzbuzz"), "foo")); assertEquals("bar", jedis.get("foo")); assertNull(destAuth.get("foo")); // binary dest.set(bfoo1, bbar1); - assertEquals("OK", dest.migrate(host, hnp.getPort(), 0, timeout, + assertEquals("OK", dest.migrate(dockerHostAuth2, dockerPortAuth2, 0, timeout, new MigrateParams().auth2("acljedis", "fizzbuzz"), bfoo1)); assertArrayEquals(bbar1, jedis.get(bfoo1)); assertNull(dest.get(bfoo1)); @@ -176,7 +182,7 @@ public void migrateCopyReplaceAuth() { destAuth.set("foo", "bar2"); assertEquals( "OK", - jedis.migrate(host, portAuth, dbAuth, timeout, + jedis.migrate(dockerHostAuth, dockerPortAuth, dbAuth, timeout, new MigrateParams().copy().replace().auth("foobared"), "foo")); assertEquals("bar1", destAuth.get("foo")); assertEquals("bar1", jedis.get("foo")); @@ -185,7 +191,7 @@ public void migrateCopyReplaceAuth() { destAuth.set(bfoo, bbar2); assertEquals( "OK", - jedis.migrate(host, portAuth, dbAuth, timeout, + jedis.migrate(dockerHostAuth, dockerPortAuth, dbAuth, timeout, new MigrateParams().copy().replace().auth("foobared"), bfoo)); assertArrayEquals(bbar1, destAuth.get(bfoo)); assertArrayEquals(bbar1, jedis.get(bfoo)); @@ -195,14 +201,14 @@ public void migrateCopyReplaceAuth() { public void migrateMulti() { jedis.mset("foo1", "bar1", "foo2", "bar2", "foo3", "bar3"); assertEquals("OK", - jedis.migrate(host, port, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3")); + jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3")); assertEquals("bar1", dest.get("foo1")); assertEquals("bar2", dest.get("foo2")); assertEquals("bar3", dest.get("foo3")); jedis.mset(bfoo1, bbar1, bfoo2, bbar2, bfoo3, bbar3); assertEquals("OK", - jedis.migrate(host, port, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3)); + jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3)); assertArrayEquals(bbar1, dest.get(bfoo1)); assertArrayEquals(bbar2, dest.get(bfoo2)); assertArrayEquals(bbar3, dest.get(bfoo3)); @@ -213,7 +219,7 @@ public void migrateConflict() { jedis.mset("foo1", "bar1", "foo2", "bar2", "foo3", "bar3"); dest.set("foo2", "bar"); try { - jedis.migrate(host, port, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3"); + jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3"); fail("Should get BUSYKEY error"); } catch (JedisDataException jde) { assertTrue(jde.getMessage().contains("BUSYKEY")); @@ -225,7 +231,7 @@ public void migrateConflict() { jedis.mset(bfoo1, bbar1, bfoo2, bbar2, bfoo3, bbar3); dest.set(bfoo2, bbar); try { - jedis.migrate(host, port, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3); + jedis.migrate(dockerHost, dockerPort, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3); fail("Should get BUSYKEY error"); } catch (JedisDataException jde) { assertTrue(jde.getMessage().contains("BUSYKEY")); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ModuleTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ModuleTest.java index 1d4a9d981b..cb2f3b577f 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ModuleTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ModuleTest.java @@ -1,10 +1,13 @@ package redis.clients.jedis.commands.jedis; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.util.Collections; +import java.util.Set; import java.util.List; +import java.util.stream.Collectors; + import org.junit.Test; import redis.clients.jedis.Module; @@ -35,8 +38,9 @@ public void testModules() { assertEquals("OK", jedis.moduleLoad("/tmp/testmodule.so")); List modules = jedis.moduleList(); + Set moduleNames = modules.stream().map(Module::getName).collect(Collectors.toSet()); - assertEquals("testmodule", modules.get(0).getName()); + assertTrue(moduleNames.contains("testmodule")); Object output = jedis.sendCommand(ModuleCommand.SIMPLE); assertTrue((Long) output > 0); @@ -44,7 +48,11 @@ public void testModules() { } finally { assertEquals("OK", jedis.moduleUnload("testmodule")); - assertEquals(Collections.emptyList(), jedis.moduleList()); + + List modules = jedis.moduleList(); + Set moduleNames = modules.stream().map(Module::getName).collect(Collectors.toSet()); + + assertFalse(moduleNames.contains("testmodule")); } } } diff --git a/src/test/java/redis/clients/jedis/commands/jedis/SentinelCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/SentinelCommandsTest.java index babaf28a10..5346dab488 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SentinelCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SentinelCommandsTest.java @@ -25,40 +25,45 @@ public class SentinelCommandsTest { Arrays.asList(HostAndPorts.getRedisServers().get(2), HostAndPorts.getRedisServers().get(3)); protected static final Set nodesPorts = nodes.stream() .map(HostAndPort::getPort).map(String::valueOf).collect(Collectors.toSet()); + protected static final Set dockerNodeIps = nodesPorts.stream() + .map(port -> String.format("172.21.0.%d", 10 + Integer.parseInt(port) - 6379)).collect(Collectors.toSet()); protected static final List sentinels2 = Arrays.asList(HostAndPorts.getSentinelServers().get(1), HostAndPorts.getSentinelServers().get(3)); @Test public void myIdAndSentinels() { - Map idToPort = new HashMap<>(); + Map idToDockerIp = new HashMap<>(); sentinels2.forEach((hap) -> { try (Jedis sentinel = new Jedis(hap)) { String id = sentinel.sentinelMyId(); assertThat(id, Matchers.not(Matchers.emptyOrNullString())); - idToPort.put(id, hap.getPort()); + idToDockerIp.put(id, String.format("172.21.0.%d", 31 + hap.getPort() - 26379)); } }); - assertEquals(2, idToPort.size()); + assertEquals(2, idToDockerIp.size()); try (Jedis sentinel = new Jedis(sentinels2.stream().findAny().get())) { List> detailsList = sentinel.sentinelSentinels(MASTER_NAME); assertThat(detailsList, Matchers.not(Matchers.empty())); - detailsList.forEach((details) - -> assertEquals(idToPort.get(details.get("runid")), - Integer.valueOf(details.get("port")))); + detailsList.forEach((details) -> { + assertEquals("26379", details.get("port")); + assertEquals(idToDockerIp.get(details.get("runid")), details.get("ip")); + }); } } @Test public void masterAndMasters() { - String runId, port; + String runId, port, ip; try (Jedis sentinel = new Jedis(sentinels2.get(0))) { Map details = sentinel.sentinelMaster(MASTER_NAME); assertEquals(MASTER_NAME, details.get("name")); runId = details.get("runid"); port = details.get("port"); - assertThat(port, Matchers.in(nodesPorts)); + ip = details.get("ip"); + assertThat(ip, Matchers.in(dockerNodeIps)); + assertEquals("6379", port); } try (Jedis sentinel2 = new Jedis(sentinels2.get(1))) { @@ -75,7 +80,9 @@ public void replicas() { List> detailsList = sentinel.sentinelReplicas(MASTER_NAME); assertThat(detailsList, Matchers.not(Matchers.empty())); detailsList.forEach((details) - -> assertThat(details.get("port"), Matchers.in(nodesPorts))); + -> assertThat(details.get("ip"), Matchers.in(dockerNodeIps))); + detailsList.forEach((details) + -> assertThat(details.get("port"), Matchers.equalTo("6379"))); } } } diff --git a/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java index 66806b933a..7901e05fcc 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java @@ -18,7 +18,7 @@ public class SlowlogCommandsTest extends JedisCommandsTestBase { - private static final List LOCAL_IPS = Arrays.asList("127.0.0.1", "[::1]"); + private static final List DOCKER_GATEWAY_IPS = Arrays.asList("172.20.0.254", "172.21.0.254"); private static final String SLOWLOG_TIME_PARAM = "slowlog-log-slower-than"; private static final String ZERO_STRING = "0"; @@ -90,7 +90,7 @@ public void slowlogObjectDetails() { assertEquals(SafeEncoder.encode(Protocol.Keyword.SET.getRaw()), log.getArgs().get(1)); assertEquals(SLOWLOG_TIME_PARAM, log.getArgs().get(2)); assertEquals(ZERO_STRING, log.getArgs().get(3)); - assertThat(log.getClientIpPort().getHost(), Matchers.in(LOCAL_IPS)); + assertThat(log.getClientIpPort().getHost(), Matchers.in(DOCKER_GATEWAY_IPS)); assertThat(log.getClientIpPort().getPort(), Matchers.greaterThan(0)); assertEquals(clientName, log.getClientName()); } diff --git a/src/test/java/redis/clients/jedis/util/JedisClusterTestUtil.java b/src/test/java/redis/clients/jedis/util/JedisClusterTestUtil.java index 75aaba1613..21e2afff75 100644 --- a/src/test/java/redis/clients/jedis/util/JedisClusterTestUtil.java +++ b/src/test/java/redis/clients/jedis/util/JedisClusterTestUtil.java @@ -7,7 +7,8 @@ public class JedisClusterTestUtil { public static void waitForClusterReady(Jedis... nodes) throws InterruptedException { boolean clusterOk = false; - while (!clusterOk) { + int retries = 0; + while (!clusterOk && retries < 1000) { boolean isOk = true; for (Jedis node : nodes) { if (!node.clusterInfo().split("\n")[0].contains("ok")) { @@ -20,10 +21,20 @@ public static void waitForClusterReady(Jedis... nodes) throws InterruptedExcepti clusterOk = true; } + retries += 1; Thread.sleep(50); } } + public static String getClusterIp(int index) { + // 172.20.0.31 is the first IP in the cluster, with index 1 + return String.format("172.20.0.%d", 30 + index); + } + + public static String getClusterIpWithPort(int index) { + return String.format("%s:6379", getClusterIp(index)); + } + public static String getNodeId(String infoOutput) { for (String infoLine : infoOutput.split("\n")) { if (infoLine.contains("myself")) { diff --git a/test-infra/no-cluster/docker-compose.yml b/test-infra/no-cluster/docker-compose.yml new file mode 100644 index 0000000000..94fd481762 --- /dev/null +++ b/test-infra/no-cluster/docker-compose.yml @@ -0,0 +1,296 @@ +--- + +version: "3.8" + +services: + + redis-1: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass foobared --user acljedis on allcommands allkeys >fizzbuzz --enable-module-command yes --client-output-buffer-limit pubsub 256k 128k 5 --save ''" + ports: + - "6379:6379" + volumes: + - ./testmodule.so:/tmp/testmodule.so:ro + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.10 + + redis-2: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass foobared --save ''" + ports: + - "6380:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.11 + + redis-3: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass foobared --masterauth foobared --save ''" + ports: + - "6381:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.12 + + redis-4: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass foobared --masterauth foobared --slaveof redis-3 6379 --save ''" + ports: + - "6382:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.13 + + redis-5: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass foobared --masterauth foobared --slaveof redis-1 6379 --save ''" + ports: + - "6383:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.14 + + redis-6: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass foobared --masterauth foobared --save ''" + ports: + - "6384:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.15 + + redis-7: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass foobared --masterauth foobared --slaveof redis-6 6379 --save ''" + ports: + - "6385:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.16 + + redis-8: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--maxmemory-policy allkeys-lfu --save ''" + ports: + - "6386:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.17 + + redis-9: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--user default off --user acljedis on allcommands allkeys >fizzbuzz --client-output-buffer-limit pubsub 256k 128k 5 --save ''" + ports: + - "6387:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.18 + + redis-10: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--save ''" + ports: + - "6388:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.19 + + redis-11: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--replicaof redis-10 6379 --save ''" + ports: + - "6389:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.20 + + redis-uds: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--port 0 --unixsocket /var/run/redis_uds.sock --unixsocketperm 777 --save ''" + volumes: + - /var/run/:/var/run/:rw + healthcheck: + test: redis-cli -s /var/run/redis_uds.sock ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.21 + + redis-unavailable: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--port 6400" + ports: + - "6400:6400" + healthcheck: + test: redis-cli -p 6400 ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.22 + + redis-sentinel-1: + build: + context: sentinel + args: + MASTER_HOST: redis-1 + depends_on: + - redis-1 + ports: + - "26379:26379" + healthcheck: + test: redis-cli -p 26379 ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.31 + + redis-sentinel-2: + build: + context: sentinel + args: + MASTER_HOST: redis-3 + depends_on: + - redis-3 + ports: + - "26380:26379" + healthcheck: + test: redis-cli -p 26379 ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.32 + + redis-sentinel-3: + build: + context: sentinel + args: + MASTER_NAME: mymasterfailover + MASTER_HOST: redis-6 + depends_on: + - redis-6 + ports: + - "26381:26379" + healthcheck: + test: redis-cli -p 26379 ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.33 + + redis-sentinel-4: + build: + context: sentinel + args: + MASTER_HOST: redis-3 + depends_on: + - redis-3 + ports: + - "26382:26379" + healthcheck: + test: redis-cli -p 26379 ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.34 + + redis-sentinel-5: + build: + context: sentinel + args: + CONFIG_FILE: sentinel-acl.conf + MASTER_NAME: aclmaster + MASTER_HOST: redis-9 + MASTER_AUTH_USER: acljedis + MASTER_AUTH_PASS: fizzbuzz + depends_on: + - redis-9 + ports: + - "26383:26379" + healthcheck: + test: redis-cli -p 26379 ping + interval: 5s + networks: + no-cluster: + ipv4_address: 172.21.0.35 + + stunnel: + image: redisfab/stunnel + ports: + - "6390:6390" + - "16381:16381" + - "16382:16382" + - "16387:16387" + - "36383:36383" + volumes: + - "./stunnel/stunnel.conf:/etc/stunnel/conf.d/sentinel.conf:ro" + - "./stunnel/pki:/etc/stunnel/keys:ro" + depends_on: + redis-1: + condition: service_healthy + redis-3: + condition: service_healthy + redis-4: + condition: service_healthy + redis-9: + condition: service_healthy + redis-sentinel-5: + condition: service_healthy + networks: + no-cluster: + ipv4_address: 172.21.0.40 + +networks: + no-cluster: + ipam: + driver: default + config: + - subnet: 172.21.0.0/16 + ip_range: 172.21.0.0/24 + gateway: 172.21.0.254 diff --git a/test-infra/no-cluster/sentinel/Dockerfile b/test-infra/no-cluster/sentinel/Dockerfile new file mode 100644 index 0000000000..56a7bb8940 --- /dev/null +++ b/test-infra/no-cluster/sentinel/Dockerfile @@ -0,0 +1,20 @@ +FROM redis + +ARG CONFIG_FILE=sentinel.conf +ARG MASTER_NAME=mymaster +ARG MASTER_HOST +ARG MASTER_PORT=6379 +ARG MASTER_AUTH_USER=default +ARG MASTER_AUTH_PASS=foobared +ARG QUORUM=1 + +COPY $CONFIG_FILE /sentinel.conf +RUN sed -i "s/mymaster/${MASTER_NAME}/g" /sentinel.conf && \ + sed -i "s/^sentinel monitor .*$/sentinel monitor ${MASTER_NAME} ${MASTER_HOST} ${MASTER_PORT} ${QUORUM}/g" /sentinel.conf && \ + sed -i "s/^sentinel auth-user .*$/sentinel auth-user ${MASTER_NAME} ${MASTER_AUTH_USER}/g" /sentinel.conf && \ + sed -i "s/^sentinel auth-pass .*$/sentinel auth-pass ${MASTER_NAME} ${MASTER_AUTH_PASS}/g" /sentinel.conf && \ + chown redis:redis /sentinel.conf + +EXPOSE 26379 + +ENTRYPOINT [ "redis-server" , "/sentinel.conf", "--sentinel" ] diff --git a/test-infra/no-cluster/sentinel/sentinel-acl.conf b/test-infra/no-cluster/sentinel/sentinel-acl.conf new file mode 100644 index 0000000000..a2f0301bfc --- /dev/null +++ b/test-infra/no-cluster/sentinel/sentinel-acl.conf @@ -0,0 +1,11 @@ +port 26379 +dir /tmp +sentinel resolve-hostnames yes +user default off +user sentinel on allcommands allkeys allchannels >foobared +sentinel monitor mymaster 127.0.0.1 6379 1 +sentinel auth-user mymaster acljedis +sentinel auth-pass mymaster fizzbuzz +sentinel down-after-milliseconds mymaster 2000 +sentinel parallel-syncs mymaster 1 +sentinel failover-timeout mymaster 120000 diff --git a/test-infra/no-cluster/sentinel/sentinel.conf b/test-infra/no-cluster/sentinel/sentinel.conf new file mode 100644 index 0000000000..d59f41f271 --- /dev/null +++ b/test-infra/no-cluster/sentinel/sentinel.conf @@ -0,0 +1,9 @@ +port 26379 +dir /tmp +sentinel resolve-hostnames yes +sentinel monitor mymaster 127.0.0.1 6379 1 +sentinel auth-user mymaster default +sentinel auth-pass mymaster foobared +sentinel down-after-milliseconds mymaster 2000 +sentinel parallel-syncs mymaster 1 +sentinel failover-timeout mymaster 120000 diff --git a/test-infra/no-cluster/stunnel/pki/private.pem b/test-infra/no-cluster/stunnel/pki/private.pem new file mode 100644 index 0000000000..0341290094 --- /dev/null +++ b/test-infra/no-cluster/stunnel/pki/private.pem @@ -0,0 +1,48 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpgIBAAKCAQEA4nb/9hXI5iFXIHh34gpvQMGTqTCf2im/FCvXYoDer/FTLKxd +r3Bw0Cj9NarMpVZOfBRykVdKir8v1+Gv0mUVwHkEJ2Mouxo6mqDQEKRt9G/gbzcC ++AoMEUsnV4tKaptXdWDLcZU9oer6wLic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BP5XQjIJyjyjTS +iOSy+qQM8Yk0CjJ/zfysChApCefP1/kOiIeStuE8jkmkVW6atprb9Vr+E5jnHKeh +SmZmXq9BRjF2OyUMG8m4DwIDAQABo1AwTjAdBgNVHQ4EFgQUSg+P0noapK2yuFoH +v9xe5HNYNiYwHwYDVR0jBBgwFoAUSg+P0noapK2yuFoHv9xe5HNYNiYwDAYDVR0T +BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAakaOSczmzRoPg3etzWiKTYht+CbA +/UtOdRxwTTHLauDUtGo6YTT+HG4tItwNxI9n3CZvcX68fNTi99fxzrHddiAwnCPv +DqEv2ASxed95/6QZIzPVFT7GZZDOUrwFkC01vawaVyl0f8UbeOWCly7eetu3mV2r +VFNPxPPT622cGn8uSqnpN1cQ4LdsDpVUR+YDAxIB8YbsWgtl79evwcnTWINy3CSc +QjAYQe1aC/kAs3VfIymdu9xEv2Er9NOidUx23RD54jrFCXNUYEBnSc2yi7YSTTzT +4cKnp7wuVdacd1noQRZFEEsVd6tmtiJKZhdllJ21Rb5g1q50dBlbq25hnw== +-----END CERTIFICATE----- diff --git a/test-infra/no-cluster/stunnel/stunnel.conf b/test-infra/no-cluster/stunnel/stunnel.conf new file mode 100644 index 0000000000..f462a6d430 --- /dev/null +++ b/test-infra/no-cluster/stunnel/stunnel.conf @@ -0,0 +1,18 @@ +cert = /etc/stunnel/keys/private.pem +verify = 0 +debug = 7 +[redis_1] +accept = 6390 +connect = redis-1:6379 +[redis_3] +accept = 16381 +connect = redis-3:6379 +[redis_4] +accept = 16382 +connect = redis-4:6379 +[redis_9] +accept = 16387 +connect = redis-9:6379 +[redis_sentinel_5] +accept = 36383 +connect = redis-sentinel-5:26379 diff --git a/test-infra/oss-cluster/docker-compose.yml b/test-infra/oss-cluster/docker-compose.yml new file mode 100644 index 0000000000..2d19484718 --- /dev/null +++ b/test-infra/oss-cluster/docker-compose.yml @@ -0,0 +1,118 @@ +--- + +version: '3.8' + +services: + redis-oss-cluster-node-1: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass cluster --cluster-enabled yes --cluster-node-timeout 15000" + ports: + - "7379:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + cluster: + ipv4_address: 172.20.0.31 + + redis-oss-cluster-node-2: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass cluster --cluster-enabled yes --cluster-node-timeout 15000" + ports: + - "7380:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + cluster: + ipv4_address: 172.20.0.32 + + redis-oss-cluster-node-3: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass cluster --cluster-enabled yes --cluster-node-timeout 15000" + ports: + - "7381:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + cluster: + ipv4_address: 172.20.0.33 + + redis-oss-cluster-node-4: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass cluster --cluster-enabled yes --cluster-node-timeout 15000" + ports: + - "7382:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + cluster: + ipv4_address: 172.20.0.34 + + redis-oss-cluster-node-5: + image: redis/redis-stack-server:${REDIS_VERSION:-edge} + environment: + - "REDIS_ARGS=--requirepass cluster --cluster-enabled yes --cluster-node-timeout 15000" + ports: + - "7383:6379" + healthcheck: + test: redis-cli ping + interval: 5s + networks: + cluster: + ipv4_address: 172.20.0.35 + +# redis-oss-cluster-starter: +# image: redis/redis-stack-server:${REDIS_VERSION:-edge} +# depends_on: +# redis-oss-cluster-node-1: +# condition: service_healthy +# redis-oss-cluster-node-2: +# condition: service_healthy +# redis-oss-cluster-node-3: +# condition: service_healthy +# redis-oss-cluster-node-4: +# condition: service_healthy +# redis-oss-cluster-node-5: +# condition: service_healthy +# command: redis-cli -a cluster --cluster create 172.20.0.31:6379 172.20.0.32:6379 172.20.0.33:6379 172.20.0.34:6379 172.20.0.35:6379 --cluster-yes +# networks: +# cluster: +# ipv4_address: 172.20.0.30 + + stunnel: + image: redisfab/stunnel + ports: + - "8379-8383:8379-8383" + volumes: + - "./stunnel/stunnel.conf:/etc/stunnel/conf.d/oss-cluster.conf:ro" + - "./stunnel/pki:/etc/stunnel/keys:ro" + depends_on: + redis-oss-cluster-node-1: + condition: service_healthy + redis-oss-cluster-node-2: + condition: service_healthy + redis-oss-cluster-node-3: + condition: service_healthy + redis-oss-cluster-node-4: + condition: service_healthy + redis-oss-cluster-node-5: + condition: service_healthy + networks: + cluster: + ipv4_address: 172.20.0.29 + +networks: + cluster: + ipam: + driver: default + config: + - subnet: 172.20.0.0/16 + ip_range: 172.20.0.0/24 + gateway: 172.20.0.254 diff --git a/test-infra/oss-cluster/stunnel/pki/private.pem b/test-infra/oss-cluster/stunnel/pki/private.pem new file mode 100644 index 0000000000..0341290094 --- /dev/null +++ b/test-infra/oss-cluster/stunnel/pki/private.pem @@ -0,0 +1,48 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpgIBAAKCAQEA4nb/9hXI5iFXIHh34gpvQMGTqTCf2im/FCvXYoDer/FTLKxd +r3Bw0Cj9NarMpVZOfBRykVdKir8v1+Gv0mUVwHkEJ2Mouxo6mqDQEKRt9G/gbzcC ++AoMEUsnV4tKaptXdWDLcZU9oer6wLicmAyV+4vlUJn+j6ADXBk4pJT+wbG/oawJ +0op4vQNeVcJPr7BcfMLG60UOTABEPBM6YWqVe2pLPX4a4ec84kcFDLjRfU9ZTy+f +D+BP5XQjIJyjyjTSiOSy+qQM8Yk0CjJ/zfysChApCefP1/kOiIeStuE8jkmkVW6a +tprb9Vr+E5jnHKehSmZmXq9BRjF2OyUMG8m4DwIDAQABAoIBAQDRDzHzpuCzMYwQ ++aUSErfpe8oooi6vY2J16JMI6BarLYiu8N/7mT1LrMszw9zvtOD3QpkQ+xhhRWWR +UVLSU2blK9Jd2fg74VbAcDwjYOfwg2cYxBwFhqDlRg+njXrBN25heV3WGQOwe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PVFT7GZZDOUrwFkC01vawaVyl0f8UbeOWCly7eetu3mV2r +VFNPxPPT622cGn8uSqnpN1cQ4LdsDpVUR+YDAxIB8YbsWgtl79evwcnTWINy3CSc +QjAYQe1aC/kAs3VfIymdu9xEv2Er9NOidUx23RD54jrFCXNUYEBnSc2yi7YSTTzT +4cKnp7wuVdacd1noQRZFEEsVd6tmtiJKZhdllJ21Rb5g1q50dBlbq25hnw== +-----END CERTIFICATE----- diff --git a/test-infra/oss-cluster/stunnel/stunnel.conf b/test-infra/oss-cluster/stunnel/stunnel.conf new file mode 100644 index 0000000000..ad1d0ad506 --- /dev/null +++ b/test-infra/oss-cluster/stunnel/stunnel.conf @@ -0,0 +1,18 @@ +cert = /etc/stunnel/keys/private.pem +verify = 0 +debug = 7 +[redis_cluster_1] +accept = 8379 +connect = redis-oss-cluster-node-1:6379 +[redis_cluster_2] +accept = 8380 +connect = redis-oss-cluster-node-2:6379 +[redis_cluster_3] +accept = 8381 +connect = redis-oss-cluster-node-3:6379 +[redis_cluster_4] +accept = 8382 +connect = redis-oss-cluster-node-4:6379 +[redis_cluster_5] +accept = 8383 +connect = redis-oss-cluster-node-5:6379