Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jjz921024 committed Aug 8, 2024
1 parent 2d33705 commit 170758a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/test/java/redis/clients/jedis/JedisClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,32 @@ public void testReadonlyAndReadwrite() throws Exception {
nodeSlave2.flushDB();
}

@Test
public void testReadFromReplicas() throws Exception {
node1.clusterMeet(LOCAL_IP, nodeInfoSlave2.getPort());
JedisClusterTestUtil.waitForClusterReady(node1, node2, node3, nodeSlave2);

for (String nodeInfo : node2.clusterNodes().split("\n")) {
if (nodeInfo.contains("myself")) {
nodeSlave2.clusterReplicate(nodeInfo.split(" ")[0]);
break;
}
}

DefaultJedisClientConfig READ_REPLICAS_CLIENT_CONFIG
= DefaultJedisClientConfig.builder().password("wb6Cluster").readOnlyForReplicas().build();
try (JedisCluster jedisCluster = new JedisCluster(nodeInfo1, READ_REPLICAS_CLIENT_CONFIG,
DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
assertEquals("OK", jedisCluster.set("test", "read-from-replicas"));

ClusterCommandObjects commandObjects = new ClusterCommandObjects();
assertEquals("read-from-replicas", jedisCluster.executeCommandToReplica(commandObjects.get("test")));
}

nodeSlave2.clusterReset(ClusterResetType.SOFT);
nodeSlave2.flushDB();
}

/**
* slot->nodes 15363 node3 e
*/
Expand Down

0 comments on commit 170758a

Please sign in to comment.