Search in sources :

Example 1 with ChannelBindException

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();
}
Also used : Connection(reactor.netty.Connection) ChannelBindException(reactor.netty.ChannelBindException) Test(org.junit.jupiter.api.Test)

Example 2 with ChannelBindException

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));
}
Also used : Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) MonoSink(reactor.core.publisher.MonoSink) IOException(java.io.IOException) Connection(reactor.netty.Connection) InetSocketAddress(java.net.InetSocketAddress) ChannelBindException(reactor.netty.ChannelBindException) InetSocketAddress(java.net.InetSocketAddress) Connection(reactor.netty.Connection) IOException(java.io.IOException) ChannelBindException(reactor.netty.ChannelBindException) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 ChannelBindException (reactor.netty.ChannelBindException)2 Connection (reactor.netty.Connection)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Mockito (org.mockito.Mockito)1 MonoSink (reactor.core.publisher.MonoSink)1