use of reactor.netty.ChannelBindException in project reactor-netty by reactor.
the class UdpServerTests method portBindingException.
@Test
void portBindingException() {
Connection conn = UdpServer.create().port(0).bindNow(Duration.ofSeconds(30));
try {
UdpServer.create().bindAddress(conn::address).bindNow(Duration.ofSeconds(30));
fail("illegal-success");
} catch (ChannelBindException e) {
assertThat(((InetSocketAddress) conn.address()).getPort()).isEqualTo(e.localPort());
e.printStackTrace();
}
conn.disposeNow();
}
use of reactor.netty.ChannelBindException in project reactor-netty by reactor.
the class NewConnectionProviderTest method testDisposableConnectBindException.
@Test
@SuppressWarnings("unchecked")
void testDisposableConnectBindException() {
MonoSink<Connection> sink = Mockito.mock(MonoSink.class);
NewConnectionProvider.DisposableConnect connect = new NewConnectionProvider.DisposableConnect(sink, () -> new InetSocketAddress("test1", 6956));
connect.onError(new UnsupportedOperationException());
Mockito.verify(sink).error(Mockito.argThat(a -> a instanceof UnsupportedOperationException));
connect = new NewConnectionProvider.DisposableConnect(sink, () -> new InetSocketAddress("test2", 4956));
// Not possible to mock io.netty.channel.unix.Errors.NativeIoException or create a new instance because of Jni
// error:
// java.lang.UnsatisfiedLinkError: 'int io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.errnoENOENT()'
connect.onError(new IOException("bind(..) failed: Address already in use"));
Mockito.verify(sink).error(Mockito.argThat(a -> a instanceof ChannelBindException && ((ChannelBindException) a).localHost().equals("test2") && ((ChannelBindException) a).localPort() == 4956));
// Issue-1668
connect = new NewConnectionProvider.DisposableConnect(sink, () -> new InetSocketAddress("test3", 7956));
connect.onError(new IOException("bind(..) failed: Die Adresse wird bereits verwendet"));
Mockito.verify(sink).error(Mockito.argThat(a -> a instanceof ChannelBindException && ((ChannelBindException) a).localHost().equals("test3") && ((ChannelBindException) a).localPort() == 7956));
}
Aggregations