Merge branch 'sentinel_config_err_handling' of https://github.com/wizwjw/jedis into wizwjw-sentinel_config_err_handling
Conflicts: src/main/java/redis/clients/jedis/JedisSentinelPool.java src/test/java/redis/clients/jedis/tests/JedisSentinelPoolTest.java
This commit is contained in:
@@ -130,8 +130,15 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
|||||||
jedis = new Jedis(hap.getHost(), hap.getPort());
|
jedis = new Jedis(hap.getHost(), hap.getPort());
|
||||||
|
|
||||||
if (master == null) {
|
if (master == null) {
|
||||||
master = toHostAndPort(jedis
|
List<String> masterAddr = jedis
|
||||||
.sentinelGetMasterAddrByName(masterName));
|
.sentinelGetMasterAddrByName(masterName);
|
||||||
|
if (masterAddr == null || masterAddr.size() != 2) {
|
||||||
|
log.warning("Can not get master addr, master name: "
|
||||||
|
+ masterName + ". Sentinel: " + hap + ".");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
master = toHostAndPort(masterAddr);
|
||||||
log.fine("Found Redis master at " + master);
|
log.fine("Found Redis master at " + master);
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
@@ -140,7 +147,7 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
|||||||
+ ". Trying next one.");
|
+ ". Trying next one.");
|
||||||
} finally {
|
} finally {
|
||||||
if (jedis != null) {
|
if (jedis != null) {
|
||||||
jedis.close();
|
jedis.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package redis.clients.jedis.tests;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -41,6 +42,30 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
|||||||
sentinelJedis2 = new Jedis(sentinel2.getHost(), sentinel2.getPort());
|
sentinelJedis2 = new Jedis(sentinel2.getHost(), sentinel2.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void errorMasterNameNotThrowException() throws InterruptedException {
|
||||||
|
final String wrongMasterName = "wrongMasterName";
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(3);
|
||||||
|
sentinelJedis1.sentinelMonitor(wrongMasterName,
|
||||||
|
"127.0.0.1", master.getPort(), 2);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
JedisSentinelPool pool = new JedisSentinelPool(wrongMasterName,
|
||||||
|
sentinels);
|
||||||
|
pool.destroy();
|
||||||
|
sentinelJedis1.sentinelRemove(wrongMasterName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkCloseableConnections() throws Exception {
|
public void checkCloseableConnections() throws Exception {
|
||||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||||
|
|||||||
Reference in New Issue
Block a user