use of java.net.ServerSocket in project robovm by robovm.
the class ServerSocketChannelTest method testAccept_Block_NoConnect.
public void testAccept_Block_NoConnect() throws IOException {
assertTrue(this.serverChannel.isBlocking());
ServerSocket gotSocket = this.serverChannel.socket();
gotSocket.bind(localAddr1);
// blocking mode , will block and wait for ever...
// so must close the server channel with another thread.
new Thread() {
public void run() {
try {
Thread.sleep(TIME_UNIT);
ServerSocketChannelTest.this.serverChannel.close();
} catch (Exception e) {
fail("Fail to close the server channel because of" + e.getClass().getName());
}
}
}.start();
try {
this.serverChannel.accept();
fail("Should throw a AsynchronousCloseException");
} catch (AsynchronousCloseException e) {
// OK.
}
}
use of java.net.ServerSocket in project robovm by robovm.
the class ServerSocketChannelTest method testAccept_NonBlock_NoConnect.
public void testAccept_NonBlock_NoConnect() throws IOException {
ServerSocket gotSocket = this.serverChannel.socket();
gotSocket.bind(localAddr1);
this.serverChannel.configureBlocking(false);
// non-blocking mode , will immediately return
assertNull(this.serverChannel.accept());
}
use of java.net.ServerSocket in project robovm by robovm.
the class ServerSocketChannelTest method testSocket_Block_BeforeClose.
// -------------------------------------------------------------------
// Test for socket()
// -------------------------------------------------------------------
/*
* Test method for 'java.nio.channels.ServerSocketChannel.socket()'
*/
public void testSocket_Block_BeforeClose() throws Exception {
assertTrue(this.serverChannel.isOpen());
assertTrue(this.serverChannel.isBlocking());
ServerSocket s1 = this.serverChannel.socket();
assertFalse(s1.isClosed());
assertSocketNotAccepted(s1);
ServerSocket s2 = this.serverChannel.socket();
// same
assertSame(s1, s2);
// socket close makes the channel close
s1.close();
assertFalse(this.serverChannel.isOpen());
}
use of java.net.ServerSocket in project robovm by robovm.
the class SelectionKeyTest method test_readyOps.
/**
* @tests java.nio.channels.SelectionKey#readyOps()
*/
public void test_readyOps() throws IOException {
int port = Support_PortManager.getNextPort();
ServerSocket ss = new ServerSocket(port);
try {
sc.connect(new InetSocketAddress(LOCAL_ADDR, port));
assertEquals(0, selectionKey.readyOps());
assertFalse(selectionKey.isConnectable());
selector.select();
assertEquals(SelectionKey.OP_CONNECT, selectionKey.readyOps());
} finally {
ss.close();
ss = null;
}
}
use of java.net.ServerSocket in project robovm by robovm.
the class SocketChannelTest method test_finishConnect.
/**
* Regression test for Harmony-1947.
*/
public void test_finishConnect() throws Exception {
SocketAddress address = new InetSocketAddress("localhost", 0);
ServerSocketChannel theServerChannel = ServerSocketChannel.open();
ServerSocket serversocket = theServerChannel.socket();
serversocket.setReuseAddress(true);
// Bind the socket
serversocket.bind(address);
boolean doneNonBlockingConnect = false;
// Loop so that we make sure we're definitely testing finishConnect()
while (!doneNonBlockingConnect) {
channel1 = SocketChannel.open();
// Set the SocketChannel to non-blocking so that connect(..) does
// not block
channel1.configureBlocking(false);
boolean connected = channel1.connect(new InetSocketAddress("localhost", serversocket.getLocalPort()));
if (!connected) {
// Now set the SocketChannel back to blocking so that
// finishConnect() blocks.
channel1.configureBlocking(true);
doneNonBlockingConnect = channel1.finishConnect();
}
if (doneNonBlockingConnect) {
tryFinish();
}
channel1.close();
}
if (!serversocket.isClosed()) {
serversocket.close();
}
}
Aggregations