Use ConnectException when connection failed for LocalChannel

Motivation:

To be more consistent we should use ConnectException when we fail the connect attempt because no LocalServerChannel exists with the given address.

Modifications:

Use correct exception.

Result:

More consistent handling of connection refused between different transports.
This commit is contained in:
Norman Maurer 2016-05-12 14:10:04 +02:00
parent 775dd139ea
commit c1827114e9
2 changed files with 12 additions and 1 deletions

View File

@ -34,6 +34,7 @@ import io.netty.util.internal.InternalThreadLocalMap;
import io.netty.util.internal.OneTimeTask;
import io.netty.util.internal.PlatformDependent;
import java.net.ConnectException;
import java.net.SocketAddress;
import java.nio.channels.AlreadyConnectedException;
import java.nio.channels.ClosedChannelException;
@ -481,7 +482,7 @@ public class LocalChannel extends AbstractChannel {
Channel boundChannel = LocalChannelRegistry.get(remoteAddress);
if (!(boundChannel instanceof LocalServerChannel)) {
Exception cause = new ChannelException("connection refused");
Exception cause = new ConnectException("connection refused: " + remoteAddress);
safeSetFailure(promise, cause);
close(voidPromise());
return;

View File

@ -42,6 +42,7 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.net.ConnectException;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
@ -863,6 +864,15 @@ public class LocalChannelTest {
}
}
@Test(expected = ConnectException.class)
public void testConnectionRefused() {
Bootstrap sb = new Bootstrap();
sb.group(group1)
.channel(LocalChannel.class)
.handler(new TestHandler())
.connect(LocalAddress.ANY).syncUninterruptibly();
}
private static final class LatchChannelFutureListener extends CountDownLatch implements ChannelFutureListener {
public LatchChannelFutureListener(int count) {
super(count);