-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test case for sentinel master listener
Signed-off-by: c00603587 <[email protected]>
- Loading branch information
c00603587
committed
Oct 20, 2023
1 parent
dc6ece2
commit f19c663
Showing
2 changed files
with
60 additions
and
96 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/test/java/redis/clients/jedis/SentinelMasterListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package redis.clients.jedis; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import redis.clients.jedis.util.JedisSentinelTestUtil; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static org.junit.Assert.assertNotEquals; | ||
|
||
/** | ||
* In order to simulate the scenario of active/standby switching. this test case will effect all the | ||
* sentinel test case, you can run this test case separately ZSentinelMasterListenerTest start with | ||
* "Z" to ensure this test case should be run as last one | ||
*/ | ||
public class SentinelMasterListenerTest { | ||
|
||
private static final String FAILOVER_MASTER_NAME = "mymasterfailover"; | ||
|
||
public final Set<String> sentinels = new HashSet<>(); | ||
protected static HostAndPort sentinelForFailover = HostAndPorts.getSentinelServers().get(2); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
sentinels.clear(); | ||
sentinels.add(sentinelForFailover.toString()); | ||
} | ||
|
||
@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(); | ||
} | ||
} | ||
|
||
} |
96 changes: 0 additions & 96 deletions
96
src/test/java/redis/clients/jedis/ZSentinelMasterListenerTest.java
This file was deleted.
Oops, something went wrong.