use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
the class ServerSocketChannelTest method test_socket_accept_Nonblocking_NotBound.
/**
* @tests ServerSocket#socket().accept()
*/
public void test_socket_accept_Nonblocking_NotBound() throws IOException {
// regression test for Harmony-748
ServerSocket gotSocket = serverChannel.socket();
serverChannel.configureBlocking(false);
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
serverChannel.close();
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
}
use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
the class ServerSocketChannelTest method test_socket_accept_Nonblocking_Bound.
/**
* @tests ServerSocket#socket().accept()
*/
public void test_socket_accept_Nonblocking_Bound() throws IOException {
// regression test for Harmony-748
serverChannel.configureBlocking(false);
serverChannel.socket().bind(null);
ServerSocket gotSocket = serverChannel.socket();
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
serverChannel.close();
try {
gotSocket.accept();
fail("Should throw a ClosedChannelException");
} catch (ClosedChannelException expected) {
}
}
use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
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 j2objc by google.
the class IllegalBlockingModeExceptionTest method test_Constructor.
/**
* @tests {@link java.nio.channels.IllegalBlockingModeException#IllegalBlockingModeException()}
*/
public void test_Constructor() {
IllegalBlockingModeException e = new IllegalBlockingModeException();
assertNull(e.getMessage());
assertNull(e.getLocalizedMessage());
assertNull(e.getCause());
}
use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
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 ClosedSelectorException");
} catch (ClosedSelectorException 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());
}
Aggregations