use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class ChannelsTest method test_newReader_LReadableByteChannel_LString.
/**
* @tests java.nio.channels.Channels#newReader(ReadableByteChannel channel,
* String charsetName)
*/
public void test_newReader_LReadableByteChannel_LString() throws IOException {
InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1", Support_PortManager.getNextPort());
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(localAddr);
SocketChannel sc = SocketChannel.open();
sc.connect(localAddr);
sc.configureBlocking(false);
assertFalse(sc.isBlocking());
ssc.accept().close();
ssc.close();
assertFalse(sc.isBlocking());
Reader reader = Channels.newReader(sc, "UTF16");
try {
int i = reader.read();
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
try {
Channels.newInputStream(sc).read();
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
sc.close();
}
use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
the class ChannelsTest method test_newReader_LReadableByteChannel_LString.
/**
* @tests java.nio.channels.Channels#newReader(ReadableByteChannel channel,
* String charsetName)
*/
public void test_newReader_LReadableByteChannel_LString() throws IOException {
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(null);
SocketChannel sc = SocketChannel.open();
sc.connect(ssc.socket().getLocalSocketAddress());
sc.configureBlocking(false);
assertFalse(sc.isBlocking());
ssc.accept().close();
ssc.close();
assertFalse(sc.isBlocking());
Reader reader = Channels.newReader(sc, "UTF16");
try {
int i = reader.read();
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
try {
Channels.newInputStream(sc).read();
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
sc.close();
}
use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
the class AbstractSelectableChannelTest method test_register_LSelectorILObject_IllegalArgument.
/**
* @tests AbstractSelectableChannel#register(Selector, int, Object)
*/
public void test_register_LSelectorILObject_IllegalArgument() throws IOException {
Selector acceptSelector = SelectorProvider.provider().openSelector();
assertTrue(acceptSelector.isOpen());
MockSelectableChannel msc = new MockSelectableChannel(SelectorProvider.provider());
msc.configureBlocking(false);
// in nonblocking mode
try {
// different SelectionKey with validOps
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
msc.register(null, 0, null);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
// in nonblocking mode, if selector closed
acceptSelector.close();
try {
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
msc.register(null, 0, null);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
try {
msc.register(acceptSelector, 0, null);
fail("Should throw IllegalSelectorException");
} catch (IllegalSelectorException e) {
// expected
}
acceptSelector = SelectorProvider.provider().openSelector();
// test in blocking mode
msc.configureBlocking(true);
try {
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
msc.register(null, 0, null);
fail("Should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
acceptSelector.close();
// in blocking mode, if selector closed
try {
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
msc.register(null, 0, null);
fail("Should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
// register with an object
Object argObj = new Object();
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
try {
sc.register(null, SelectionKey.OP_READ, argObj);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
// if channel closed
msc.close();
try {
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw ClosedChannelException");
} catch (ClosedChannelException e) {
// expected
}
}
use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
the class AbstractSelectableChannelTest method test_configureBlocking_Z_IllegalBlockingMode.
/**
* @tests AbstractSelectableChannel#configureBlocking(boolean)
*/
public void test_configureBlocking_Z_IllegalBlockingMode() throws Exception {
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
Selector acceptSelector = SelectorProvider.provider().openSelector();
SelectionKey acceptKey = sc.register(acceptSelector, SelectionKey.OP_READ, null);
assertEquals(sc.keyFor(acceptSelector), acceptKey);
SelectableChannel getChannel = sc.configureBlocking(false);
assertEquals(getChannel, sc);
try {
sc.configureBlocking(true);
fail("Should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
}
use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
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 expected) {
}
serverChannel.close();
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
}
Aggregations