use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class AbstractSelectorTest method test_register_LSelectorI_error.
/**
* @tests AbstractSelector#register(Selector,int)
*/
public void test_register_LSelectorI_error() throws IOException {
Selector acceptSelector = SelectorProvider.provider().openSelector();
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.configureBlocking(false);
acceptSelector.close();
assertFalse(acceptSelector.isOpen());
try {
ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
fail("should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
assertFalse(ssc.isRegistered());
acceptSelector = Selector.open();
ssc.configureBlocking(true);
try {
ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
assertFalse(ssc.isRegistered());
ssc.configureBlocking(false);
SelectionKey acceptKey = ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
assertNotNull(acceptKey);
assertTrue(acceptSelector.keys().contains(acceptKey));
assertTrue(ssc.isRegistered());
}
use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class SocketChannelTest method test_socket_getOutputStream_nonBlocking_read_Exception.
public void test_socket_getOutputStream_nonBlocking_read_Exception() throws IOException {
byte[] buf = new byte[1];
channel1.connect(this.localAddr1);
InputStream is = channel1.socket().getInputStream();
channel1.configureBlocking(false);
try {
is.read();
fail();
} catch (IllegalBlockingModeException expected) {
}
try {
is.read(null);
fail();
} catch (NullPointerException expected) {
}
try {
is.read(buf, -1, 1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
is.read(buf, 0, -1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
is.read(buf, 0, 2);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
is.read(buf, 2, 0);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
is.read(null, 0, 0);
fail();
} catch (NullPointerException expected) {
}
is.close();
try {
is.read();
fail();
} catch (IllegalBlockingModeException expected) {
}
try {
is.read(null);
fail();
} catch (NullPointerException expected) {
}
try {
is.read(buf, -1, 1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
is.read(buf, 0, -1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
is.read(buf, 0, 2);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
is.read(buf, 2, 0);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
is.read(null, 0, 0);
fail();
} catch (NullPointerException expected) {
}
}
use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class ServerSocketChannelTest method test_socket_accept_Blocking_NotBound.
/**
* @tests ServerSocket#socket().accept()
*/
public void test_socket_accept_Blocking_NotBound() throws IOException {
// regression test for Harmony-748
ServerSocket gotSocket = serverChannel.socket();
serverChannel.configureBlocking(true);
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
serverChannel.close();
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
}
use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class SocketChannelTest method testSocket_configureblocking.
public void testSocket_configureblocking() throws IOException {
byte[] serverWBuf = new byte[CAPACITY_NORMAL];
for (int i = 0; i < serverWBuf.length; i++) {
serverWBuf[i] = (byte) i;
}
java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL + 1);
channel1.connect(localAddr1);
server1.accept();
Socket sock = this.channel1.socket();
channel1.configureBlocking(false);
assertFalse(channel1.isBlocking());
OutputStream channelSocketOut = sock.getOutputStream();
try {
// write operation is not allowed in non-blocking mode
channelSocketOut.write(buf.array());
fail("Non-Blocking mode should cause IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// correct
}
channel1.configureBlocking(true);
assertTrue(channel1.isBlocking());
// write operation is allowed in blocking mode
channelSocketOut.write(buf.array());
}
use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class SocketChannelTest method test_socket_getOutputStream_nonBlocking_write_Exception.
public void test_socket_getOutputStream_nonBlocking_write_Exception() throws IOException {
byte[] buf = new byte[1];
channel1.connect(this.localAddr1);
OutputStream os = channel1.socket().getOutputStream();
channel1.configureBlocking(false);
try {
os.write(1);
fail();
} catch (IllegalBlockingModeException expected) {
}
try {
os.write(null);
fail();
} catch (NullPointerException expected) {
}
try {
os.write(buf, -1, 1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
os.write(buf, 0, -1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
os.write(buf, 0, 2);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
os.write(buf, 2, 0);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
os.write(null, 0, 0);
fail();
} catch (NullPointerException expected) {
}
os.close();
try {
os.write(1);
fail();
} catch (IllegalBlockingModeException expected) {
}
try {
os.write(null);
fail();
} catch (NullPointerException expected) {
}
try {
os.write(buf, -1, 1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
os.write(buf, 0, -1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
os.write(buf, 0, 2);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
os.write(buf, 2, 0);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
os.write(null, 0, 0);
fail();
} catch (NullPointerException expected) {
}
}
Aggregations