Skip to content

Commit

Permalink
test case for testSentinelMasterListener
Browse files Browse the repository at this point in the history
Signed-off-by: c00603587 <chenshi35@huawei.com>
  • Loading branch information
c00603587 committed Oct 20, 2023
1 parent f19c663 commit 23813a2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 61 deletions.
37 changes: 36 additions & 1 deletion src/test/java/redis/clients/jedis/JedisSentinelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import static org.junit.Assert.fail;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.After;
import org.junit.Before;
Expand All @@ -31,8 +33,12 @@ public class JedisSentinelTest {
protected static HostAndPort sentinelForFailover = HostAndPorts.getSentinelServers().get(2);
protected static HostAndPort masterForFailover = HostAndPorts.getRedisServers().get(5);

public final Set<String> sentinels = new HashSet<>();

@Before
public void setup() throws InterruptedException {
public void setUp() throws Exception {
sentinels.clear();
sentinels.add(sentinelForFailover.toString());
}

@After
Expand Down Expand Up @@ -100,6 +106,35 @@ public void sentinelFailover() throws InterruptedException {
}
}

@Test
public void testSentinelMasterListener() throws InterruptedException {
Jedis j = new Jedis(sentinelForFailover);
Jedis j2 = new Jedis(sentinelForFailover);

SentinelPoolConfig config = new SentinelPoolConfig();
config.setEnableActiveDetectListener(true);
config.setEnableDefaultSubscribeListener(true);
config.setActiveDetectIntervalTimeMillis(5 * 1000);
config.setSubscribeRetryWaitTimeMillis(5 * 1000);

JedisSentinelPool pool = new JedisSentinelPool(FAILOVER_MASTER_NAME, sentinels, config, 1000,
"foobared", 2);

try {
HostAndPort masterGetFromPoolBefore = pool.getResource().connection.getHostAndPort();

JedisSentinelTestUtil.waitForNewPromotedMaster(FAILOVER_MASTER_NAME, j, j2);

HostAndPort masterGetFromPoolCurrent = pool.getResource().connection.getHostAndPort();

assertNotEquals(masterGetFromPoolBefore, masterGetFromPoolCurrent);
} finally {
j.close();
j2.close();
pool.destroy();
}
}

@Test
public void sentinelMonitor() {
Jedis j = new Jedis(sentinel);
Expand Down
60 changes: 0 additions & 60 deletions src/test/java/redis/clients/jedis/SentinelMasterListenerTest.java

This file was deleted.

0 comments on commit 23813a2

Please sign in to comment.