use of java.nio.channels.ClosedChannelException in project robovm by robovm.
the class SinkChannelTest method test_write_$LByteBuffer_SinkClosed.
/**
* @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[])
*/
public void test_write_$LByteBuffer_SinkClosed() throws IOException {
ByteBuffer[] bufArray = { buffer };
sink.close();
try {
sink.write(bufArray);
fail("should throw ClosedChannelException");
} catch (ClosedChannelException e) {
// expected
}
ByteBuffer[] nullBufArrayRef = null;
try {
sink.write(nullBufArrayRef);
fail("should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
ByteBuffer nullBuf = null;
ByteBuffer[] nullBufArray = { nullBuf };
// write ByteBuffer[] contains null element
try {
sink.write(nullBufArray);
fail("should throw ClosedChannelException");
} catch (ClosedChannelException e) {
// expected
}
}
use of java.nio.channels.ClosedChannelException in project robovm by robovm.
the class SelectorTest method assert_select_OP_CONNECT.
private void assert_select_OP_CONNECT(SelectType type, int timeout) throws IOException, ClosedChannelException {
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
sc.register(selector, SelectionKey.OP_CONNECT);
try {
sc.connect(localAddress);
int count = blockingSelect(type, timeout);
assertEquals(1, count);
Set<SelectionKey> selectedKeys = selector.selectedKeys();
assertEquals(1, selectedKeys.size());
SelectionKey key = selectedKeys.iterator().next();
assertEquals(sc.keyFor(selector), key);
assertEquals(SelectionKey.OP_CONNECT, key.readyOps());
// select again, it should return 0
count = selectOnce(type, timeout);
assertEquals(0, count);
// but selectedKeys remains the same as previous
assertSame(selectedKeys, selector.selectedKeys());
sc.finishConnect();
selectedKeys.clear();
} finally {
try {
ssc.accept().close();
} catch (Exception e) {
// do nothing
}
try {
sc.close();
} catch (IOException e) {
// do nothing
}
}
}
use of java.nio.channels.ClosedChannelException 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
}
}
use of java.nio.channels.ClosedChannelException in project robovm by robovm.
the class SocketChannelTest method test_56684.
public void test_56684() throws Exception {
mockOs.enqueueFault("connect", ENETUNREACH);
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
Selector selector = Selector.open();
SelectionKey selectionKey = sc.register(selector, SelectionKey.OP_CONNECT);
try {
sc.connect(new InetSocketAddress(InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 }), 0));
fail();
} catch (ConnectException ex) {
}
try {
sc.finishConnect();
} catch (ClosedChannelException expected) {
}
}
use of java.nio.channels.ClosedChannelException in project vert.x by eclipse.
the class Http2ServerTest method testIdleTimeout.
@Test
public void testIdleTimeout() throws Exception {
waitFor(5);
server.close();
server = vertx.createHttpServer(serverOptions.setIdleTimeout(2));
server.requestHandler(req -> {
req.exceptionHandler(err -> {
assertTrue(err instanceof ClosedChannelException);
complete();
});
req.response().closeHandler(v -> {
complete();
});
req.response().endHandler(v -> {
complete();
});
req.connection().closeHandler(v -> {
complete();
});
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.decoder.frameListener(new Http2EventAdapter() {
});
request.encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
request.context.flush();
});
fut.sync();
fut.channel().closeFuture().addListener(v1 -> {
vertx.runOnContext(v2 -> {
complete();
});
});
await();
}
Aggregations