Fixed - MasterSlaveConnectionManager throws ClassCastException if host unknown #4246

pull/4272/head
Nikita Koksharov 3 years ago
parent 86c49d5a89
commit c1a7fb84ca

@ -186,7 +186,7 @@ public final class RedisClient {
Future<InetSocketAddress> resolveFuture = resolver.resolve(InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort())); Future<InetSocketAddress> resolveFuture = resolver.resolve(InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort()));
resolveFuture.addListener((FutureListener<InetSocketAddress>) future -> { resolveFuture.addListener((FutureListener<InetSocketAddress>) future -> {
if (!future.isSuccess()) { if (!future.isSuccess()) {
promise.completeExceptionally(future.cause()); promise.completeExceptionally(new RedisConnectionException(future.cause()));
return; return;
} }
@ -207,7 +207,7 @@ public final class RedisClient {
@Override @Override
public void operationComplete(final ChannelFuture future) throws Exception { public void operationComplete(final ChannelFuture future) throws Exception {
if (bootstrap.config().group().isShuttingDown()) { if (bootstrap.config().group().isShuttingDown()) {
IllegalStateException cause = new IllegalStateException("RedisClient is shutdown"); RedisConnectionException cause = new RedisConnectionException("RedisClient is shutdown");
r.completeExceptionally(cause); r.completeExceptionally(cause);
return; return;
} }
@ -264,7 +264,7 @@ public final class RedisClient {
@Override @Override
public void operationComplete(final ChannelFuture future) throws Exception { public void operationComplete(final ChannelFuture future) throws Exception {
if (bootstrap.config().group().isShuttingDown()) { if (bootstrap.config().group().isShuttingDown()) {
IllegalStateException cause = new IllegalStateException("RedisClient is shutdown"); RedisConnectionException cause = new RedisConnectionException("RedisClient is shutdown");
r.completeExceptionally(cause); r.completeExceptionally(cause);
return; return;
} }

@ -24,6 +24,10 @@ public class RedisConnectionException extends RedisException {
private static final long serialVersionUID = -4756928186967834601L; private static final long serialVersionUID = -4756928186967834601L;
public RedisConnectionException(Throwable cause) {
super(cause);
}
public RedisConnectionException(String msg) { public RedisConnectionException(String msg) {
super(msg); super(msg);
} }

@ -339,7 +339,10 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
} catch (Exception e) { } catch (Exception e) {
stopThreads(); stopThreads();
if (e instanceof CompletionException) { if (e instanceof CompletionException) {
throw (RuntimeException) e.getCause(); if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RedisConnectionException(e.getCause());
} }
throw e; throw e;
} }

@ -1140,6 +1140,19 @@ public class RedissonTest extends BaseTest {
}); });
} }
@Test
public void testMasterSlaveConnectionFail2() {
Assertions.assertThrows(RedisConnectionException.class, () -> {
Config config = new Config();
config.useMasterSlaveServers()
.setMasterAddress("redis://gadfgdfgdsfg:1111")
.addSlaveAddress("redis://asdfasdfsdfaasdf:1111");
Redisson.create(config);
Thread.sleep(1500);
});
}
@Test @Test
public void testSentinelConnectionFail() { public void testSentinelConnectionFail() {
Assertions.assertThrows(RedisConnectionException.class, () -> { Assertions.assertThrows(RedisConnectionException.class, () -> {

Loading…
Cancel
Save