Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2058231
commit 69b5291
Showing
5 changed files
with
212 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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
47 changes: 47 additions & 0 deletions
47
src/test/java/redis/clients/jedis/tests/JedisSentinelTest.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,47 @@ | ||
package redis.clients.jedis.tests; | ||
|
||
import static junit.framework.Assert.*; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
|
||
import redis.clients.jedis.Jedis; | ||
|
||
public class JedisSentinelTest { | ||
|
||
private static final String MASTER_NAME = "mymaster"; | ||
|
||
/** | ||
* Based on redis/master/slave/sentinel configs from | ||
* https://github.com/noise/redis-sentinel-tests. | ||
*/ | ||
@Test | ||
public void sentinel() { | ||
Jedis j = new Jedis("localhost", 26379); | ||
List<Map<String, String>> masters = j.sentinelMasters(); | ||
final String masterName = masters.get(0).get("name"); | ||
|
||
assertEquals(MASTER_NAME, masterName); | ||
|
||
List<String> masterHostAndPort = j.sentinelGetMasterAddrByName(masterName); | ||
assertEquals("127.0.0.1", masterHostAndPort.get(0)); | ||
assertEquals("6379", masterHostAndPort.get(1)); | ||
|
||
List<Map<String, String>> slaves = j.sentinelSlaves(masterName); | ||
assertEquals("6379", slaves.get(0).get("master-port")); | ||
|
||
List<? extends Object> isMasterDownByAddr = j.sentinelIsMasterDownByAddr("127.0.0.1", 6379); | ||
assertEquals(Long.valueOf(0), (Long) isMasterDownByAddr.get(0)); | ||
assertFalse("?".equals(isMasterDownByAddr.get(1))); | ||
|
||
isMasterDownByAddr = j.sentinelIsMasterDownByAddr("127.0.0.1", 1); | ||
assertEquals(Long.valueOf(0), (Long) isMasterDownByAddr.get(0)); | ||
assertTrue("?".equals(isMasterDownByAddr.get(1))); | ||
|
||
// DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET | ||
assertEquals(Long.valueOf(1), j.sentinelReset(masterName)); | ||
assertEquals(Long.valueOf(0), j.sentinelReset("woof" + masterName)); | ||
} | ||
} |