/** master1 集群1个,master2 集群3个 */ @Test public void testInitPool_1_3() { MatrixRedisPool pool = (MatrixRedisPool) matrixRedisClient.getRedisPool(); Assert.assertNotNull(pool.getMasterShardedJedisPool()); Assert.assertTrue(pool.getSlaveShardedJedisPools().size() == 0); }
@Test public void testSdown() throws InterruptedException { MatrixRedisPool pool = (MatrixRedisPool) matrixRedisClient.getRedisPool(); int slaveSize = pool.getSlaveShardedJedisPools().size(); System.out.println("请下线一台slave......"); Thread.currentThread().sleep(30000); int newSlaveSize = pool.getSlaveShardedJedisPools().size(); Assert.assertTrue(newSlaveSize == (slaveSize - 1)); }
@Test public void testHashDiff() { MatrixRedisPool pool = (MatrixRedisPool) matrixRedisClient.getRedisPool(); ShardedJedis masterShardedJedis = pool.getMasterResource(); ShardedJedis slaveShardedJedis = pool.getSlaveResource(); Map<String, JedisShardInfo> masterShards = pool.getMasterShards(); Map<String, List<JedisShardInfo>> slaveShards = pool.getMultiSlaveShards(); Map<String, String> masterSearchMap = new HashMap<>(); Map<String, String> slaveSearchMap = new HashMap<>(); for (String masterName : masterShards.keySet()) { JedisShardInfo shardInfo = masterShards.get(masterName); masterSearchMap.put(shardInfo.getHost() + ":" + shardInfo.getHost(), masterName); } for (String masterName : slaveShards.keySet()) { List<JedisShardInfo> slaveshardInfo = slaveShards.get(masterName); for (JedisShardInfo shardInfo : slaveshardInfo) { slaveSearchMap.put(shardInfo.getHost() + ":" + shardInfo.getHost(), masterName); } } for (int i = 0; i < 10; i++) { String randomKey = String.valueOf(new Random().nextInt(100000)); JedisShardInfo masterShardInfo = masterShardedJedis.getShardInfo(randomKey); JedisShardInfo slaveShardInfo = slaveShardedJedis.getShardInfo(randomKey); String masterMasterName = masterSearchMap.get(masterShardInfo.getHost() + ":" + masterShardInfo.getPort()); String slaveMasterName = slaveSearchMap.get(slaveShardInfo.getHost() + ":" + slaveShardInfo.getPort()); Assert.assertEquals(masterMasterName, slaveMasterName); } }