Search in sources :

Example 1 with AbstractSelector

use of java.nio.channels.spi.AbstractSelector in project webpieces by deanhiller.

the class TestXEvaluateNIOBehavior method testNormalNio.

/**
	 * This test is interesting.  If a Socket is registered with a Selector, and
	 * you close the socket, the socket cannot be closed until the select statement.
	 * 
	 * NOTE: Appears to be fixed in 1.5.0_06 on windows, so we only run this on
	 * linux now!!!!!!!!!
	 * 
	 * @throws Exception
	 */
public void testNormalNio() throws Exception {
    SocketChannel channel1 = SocketChannel.open();
    channel1.configureBlocking(false);
    channel1.socket().setReuseAddress(true);
    InetAddress loopBack = InetAddress.getByName("127.0.0.1");
    InetSocketAddress addr1 = new InetSocketAddress(loopBack, 0);
    channel1.socket().bind(addr1);
    channel1.connect(svrAddr);
    channel1.finishConnect();
    mockServer.expect(MockNIOServer.CONNECTED);
    SelectorProvider prov = SelectorProvider.provider();
    AbstractSelector sel = prov.openSelector();
    log.info("about to register client");
    channel1.register(sel, SelectionKey.OP_READ);
    log.info("registered channel");
    log.info("about to close------------------");
    channel1.close();
    log.info("channel is now closed-----------");
    mockServer.expect(MockNIOServer.FAR_END_CLOSED);
}
Also used : SocketChannel(java.nio.channels.SocketChannel) SelectorProvider(java.nio.channels.spi.SelectorProvider) AbstractSelector(java.nio.channels.spi.AbstractSelector) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketChannel (java.nio.channels.SocketChannel)1 AbstractSelector (java.nio.channels.spi.AbstractSelector)1 SelectorProvider (java.nio.channels.spi.SelectorProvider)1