Search in sources :

Example 11 with UnsupportedAddressTypeException

use of java.nio.channels.UnsupportedAddressTypeException in project robovm by robovm.

the class DatagramChannelTest method testConnect_UnsupportedType.

/**
     * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
     *
     * @throws IOException
     */
public void testConnect_UnsupportedType() throws IOException {
    assertFalse(this.channel1.isConnected());
    class SubSocketAddress extends SocketAddress {

        private static final long serialVersionUID = 1L;

        public SubSocketAddress() {
            super();
        }
    }
    SocketAddress newTypeAddress = new SubSocketAddress();
    try {
        this.channel1.connect(newTypeAddress);
        fail("Should throw an UnsupportedAddressTypeException here.");
    } catch (UnsupportedAddressTypeException e) {
    // OK.
    }
}
Also used : UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 12 with UnsupportedAddressTypeException

use of java.nio.channels.UnsupportedAddressTypeException in project jdk8u_jdk by JetBrains.

the class Bind method testBind.

void testBind() {
    SctpChannel channel = null;
    try {
        channel = SctpChannel.open();
        /* TEST 1: empty set if channel is not bound */
        check(channel.getAllLocalAddresses().isEmpty(), "getAllLocalAddresses returned non empty set for unbound channel");
        /* TEST 2: null to bind the channel to an automatically assigned
             *         socket address */
        channel.bind(null);
        /* TEST 3: non empty set if the channel is bound */
        check(!channel.getAllLocalAddresses().isEmpty(), "getAllLocalAddresses returned empty set for bound channel");
        debug("getAllLocalAddresses on channel bound to the wildcard:\n" + channel.getAllLocalAddresses());
        /* TEST 4: AlreadyBoundException if this channel is already bound */
        try {
            channel.bind(null);
        } catch (AlreadyBoundException unused) {
            pass();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
        /* TEST 5: UnsupportedAddressTypeException */
        try {
            channel.close();
            /* open a new unbound channel for test */
            channel = SctpChannel.open();
            channel.bind(new UnsupportedSocketAddress());
            fail("UnsupportedSocketAddress expected");
        } catch (UnsupportedAddressTypeException unused) {
            pass();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
        /* TEST 6: AlreadyConnectedException */
        try {
            channel.close();
            /* open a new unbound channel for test */
            channel = SctpChannel.open();
            connectChannel(channel);
            channel.bind(null);
            fail("AlreadyConnectedException expected");
        } catch (AlreadyConnectedException unused) {
            pass();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
        /* TEST 7: ClosedChannelException - If this channel is closed */
        try {
            channel.close();
            /* open a new unbound channel for test */
            channel = SctpChannel.open();
            channel.close();
            channel.bind(null);
            fail("ClosedChannelException expected");
        } catch (ClosedChannelException unused) {
            pass();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
        /* TEST 8: ClosedChannelException if channel is closed */
        try {
            channel.getAllLocalAddresses();
            fail("should have thrown ClosedChannelException");
        } catch (ClosedChannelException cce) {
            pass();
        } catch (Exception ioe) {
            unexpected(ioe);
        }
    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        try {
            channel.close();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
    }
}
Also used : SctpChannel(com.sun.nio.sctp.SctpChannel) UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) ClosedChannelException(java.nio.channels.ClosedChannelException) AlreadyBoundException(java.nio.channels.AlreadyBoundException) AlreadyConnectedException(java.nio.channels.AlreadyConnectedException) ClosedChannelException(java.nio.channels.ClosedChannelException) AlreadyConnectedException(java.nio.channels.AlreadyConnectedException) UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) AlreadyBoundException(java.nio.channels.AlreadyBoundException) IllegalUnbindException(com.sun.nio.sctp.IllegalUnbindException)

Aggregations

UnsupportedAddressTypeException (java.nio.channels.UnsupportedAddressTypeException)12 InetSocketAddress (java.net.InetSocketAddress)6 SocketAddress (java.net.SocketAddress)4 AlreadyBoundException (java.nio.channels.AlreadyBoundException)3 SctpChannel (com.sun.nio.sctp.SctpChannel)2 AlreadyConnectedException (java.nio.channels.AlreadyConnectedException)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)2 IllegalUnbindException (com.sun.nio.sctp.IllegalUnbindException)1 SctpServerChannel (com.sun.nio.sctp.SctpServerChannel)1 IOException (java.io.IOException)1 ConnectionPendingException (java.nio.channels.ConnectionPendingException)1 NoConnectionPendingException (java.nio.channels.NoConnectionPendingException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 List (java.util.List)1