Search in sources :

Example 6 with NotYetConnectedException

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

the class NotYetConnectedExceptionTest method test_Constructor.

/**
     * @tests {@link java.nio.channels.NotYetConnectedException#NotYetConnectedException()}
     */
public void test_Constructor() {
    NotYetConnectedException e = new NotYetConnectedException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
Also used : NotYetConnectedException(java.nio.channels.NotYetConnectedException)

Example 7 with NotYetConnectedException

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

the class SocketChannelTest method testWriteByteBuffer_Direct.

public void testWriteByteBuffer_Direct() throws IOException {
    assertTrue(this.server1.isBound());
    java.nio.ByteBuffer writeBuf = java.nio.ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    assertFalse(this.channel1.isRegistered());
    assertTrue(this.channel1.isBlocking());
    assertFalse(this.channel1.isConnected());
    assertFalse(this.channel1.isConnectionPending());
    assertTrue(this.channel1.isOpen());
    try {
        channel1.write(writeBuf);
        fail("Should throw NotYetConnectedException");
    } catch (NotYetConnectedException e) {
    // correct
    }
    this.channel1.connect(localAddr1);
    assertTrue(this.channel1.isBlocking());
    assertTrue(this.channel1.isConnected());
    assertFalse(this.channel1.isConnectionPending());
    assertTrue(this.channel1.isOpen());
    assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
    this.channel1.close();
    try {
        channel1.write(writeBuf);
        fail("Should throw ClosedChannelException");
    } catch (ClosedChannelException e) {
    // correct
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) NotYetConnectedException(java.nio.channels.NotYetConnectedException) ByteBuffer(java.nio.ByteBuffer)

Example 8 with NotYetConnectedException

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

the class SocketChannelTest method testReadByteBufferArray.

/*
     * Test method for 'java.nio.channels.SocketChannel.read(ByteBuffer[])'
     */
public void testReadByteBufferArray() throws IOException {
    java.nio.ByteBuffer[] byteBuf = null;
    MockSocketChannel testMSChannelnull = new MockSocketChannel(null);
    MockSocketChannel testMSChannel = new MockSocketChannel(SelectorProvider.provider());
    ServerSocket testServer = new ServerSocket(Support_PortManager.getNextPort());
    try {
        try {
            this.channel1.read(byteBuf);
            fail("Should throw NPE");
        } catch (NullPointerException e) {
        // correct
        }
        byteBuf = new java.nio.ByteBuffer[CAPACITY_NORMAL];
        try {
            this.channel1.read(byteBuf);
            fail("Should throw NotYetConnectedException");
        } catch (NotYetConnectedException e) {
        // correct
        }
        long readNum = CAPACITY_NORMAL;
        readNum = testMSChannel.read(byteBuf);
        assertEquals(0, readNum);
        readNum = CAPACITY_NORMAL;
        readNum = testMSChannelnull.read(byteBuf);
        assertEquals(0, readNum);
    } finally {
        testServer.close();
    }
}
Also used : ServerSocket(java.net.ServerSocket) NotYetConnectedException(java.nio.channels.NotYetConnectedException) ByteBuffer(java.nio.ByteBuffer)

Example 9 with NotYetConnectedException

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

the class DatagramChannelTest method testWriteByteBufferArrayIntInt_NonBlock.

public void testWriteByteBufferArrayIntInt_NonBlock() throws IOException {
    ByteBuffer[] writeBuf = new ByteBuffer[2];
    writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    InetSocketAddress ipAddr = localAddr1;
    // non-block mode
    this.channel1.configureBlocking(false);
    try {
        this.channel1.write(writeBuf, 0, 2);
        fail("Should throw NotYetConnectedException.");
    } catch (NotYetConnectedException e) {
    // correct
    }
    this.channel1.connect(ipAddr);
    assertTrue(this.channel1.isConnected());
    assertEquals(CAPACITY_NORMAL * 2, this.channel1.write(writeBuf, 0, 2));
    // cannot be buffered again!
    assertEquals(0, this.channel1.write(writeBuf, 0, 1));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NotYetConnectedException(java.nio.channels.NotYetConnectedException) ByteBuffer(java.nio.ByteBuffer)

Example 10 with NotYetConnectedException

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

the class DatagramChannelTest method testReadByteBuffer.

// -------------------------------------------------------------------
// Test for read()
// -------------------------------------------------------------------
/*
     * Test method for 'DatagramChannelImpl.read(ByteBuffer)'
     */
public void testReadByteBuffer() throws IOException {
    ByteBuffer readBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    try {
        this.channel1.read(readBuf);
        fail("should throw NotYetConnectedException");
    } catch (NotYetConnectedException e) {
    // correct
    }
    this.channel1.connect(localAddr1);
    assertTrue(this.channel1.isConnected());
    this.channel1.configureBlocking(false);
    // note : blocking-mode will make the read process endless!
    assertEquals(0, this.channel1.read(readBuf));
    this.channel1.close();
    try {
        this.channel1.read(readBuf);
        fail("Should throw ClosedChannelException");
    } catch (ClosedChannelException e) {
    // OK.
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) NotYetConnectedException(java.nio.channels.NotYetConnectedException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

NotYetConnectedException (java.nio.channels.NotYetConnectedException)23 ByteBuffer (java.nio.ByteBuffer)18 InetSocketAddress (java.net.InetSocketAddress)9 ClosedChannelException (java.nio.channels.ClosedChannelException)9 IOException (java.io.IOException)7 OutputStream (java.io.OutputStream)3 SocketChannel (java.nio.channels.SocketChannel)3 MessageInfo (com.sun.nio.sctp.MessageInfo)2 SctpChannel (com.sun.nio.sctp.SctpChannel)2 ByteBuf (io.netty.buffer.ByteBuf)2 AddressedEnvelope (io.netty.channel.AddressedEnvelope)2 ServerSocket (java.net.ServerSocket)2 SocketAddress (java.net.SocketAddress)2 DatagramChannel (java.nio.channels.DatagramChannel)2 SelectionKey (java.nio.channels.SelectionKey)2 ServerSocketChannel (java.nio.channels.ServerSocketChannel)2 ArrayList (java.util.ArrayList)2 Command (org.openhab.core.types.Command)2 JobDataMap (org.quartz.JobDataMap)2 JobDetail (org.quartz.JobDetail)2