use of java.nio.channels.AlreadyConnectedException in project robovm by robovm.
the class SocketChannelTest method testCFII_Data_FinishConnect_Blocking.
public void testCFII_Data_FinishConnect_Blocking() throws IOException {
ensureServerOpen();
java.nio.ByteBuffer writeBuf = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
java.nio.ByteBuffer[] writeBufArr = new java.nio.ByteBuffer[1];
writeBufArr[0] = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
this.channel1.configureBlocking(true);
try {
this.channel1.finishConnect();
fail("Should throw NoConnectionPendingException");
} catch (NoConnectionPendingException e) {
// correct
}
this.channel1.connect(localAddr1);
assertTrue(this.channel1.isConnected());
assertFalse(this.channel1.isConnectionPending());
assertTrue(this.channel1.isOpen());
if (tryFinish()) {
assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBufArr, 0, 1));
try {
this.channel1.connect(localAddr1);
fail("Should throw AlreadyConnectedException");
} catch (AlreadyConnectedException e) {
// correct
}
}
assertFalse(this.channel1.isRegistered());
tryFinish();
}
use of java.nio.channels.AlreadyConnectedException in project robovm by robovm.
the class SocketChannelTest method testCFII_Data_FinishConnect_nonBlocking.
/*
* Test method for 'SocketChannelImpl.finishConnect()'
*/
public void testCFII_Data_FinishConnect_nonBlocking() throws IOException {
ensureServerOpen();
java.nio.ByteBuffer writeBuf = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
java.nio.ByteBuffer[] writeBufArr = new java.nio.ByteBuffer[1];
writeBufArr[0] = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
this.channel1.configureBlocking(false);
try {
this.channel1.finishConnect();
fail("Should throw NoConnectionPendingException");
} catch (NoConnectionPendingException e) {
// correct
}
boolean connected = channel1.connect(localAddr1);
if (!connected) {
assertFalse(this.channel1.isBlocking());
assertFalse(this.channel1.isConnected());
assertTrue(this.channel1.isConnectionPending());
assertTrue(this.channel1.isOpen());
}
this.server1.accept();
if (tryFinish()) {
assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBufArr, 0, 1));
try {
this.channel1.connect(localAddr1);
fail("Should throw AlreadyConnectedException");
} catch (AlreadyConnectedException e) {
// correct
}
}
assertFalse(this.channel1.isRegistered());
tryFinish();
}
use of java.nio.channels.AlreadyConnectedException in project robovm by robovm.
the class SocketChannelTest method assertSocketAction_Block_BeforeConnect.
private void assertSocketAction_Block_BeforeConnect(Socket s) throws IOException {
assertFalse(this.channel1.isConnected());
this.server2 = new ServerSocket(localAddr2.getPort());
s.connect(localAddr2);
assertTrue(this.channel1.isConnected());
assertTrue(s.isConnected());
assertSocketAfterConnect(s, localAddr2);
try {
s.bind(localAddr2);
fail("Should throw AlreadyConnectedException");
} catch (AlreadyConnectedException e) {
// OK.
}
s.close();
assertTrue(s.isClosed());
assertFalse(this.channel1.isOpen());
}
use of java.nio.channels.AlreadyConnectedException in project robovm by robovm.
the class AlreadyConnectedExceptionTest method test_Constructor.
/**
* @tests {@link java.nio.channels.AlreadyConnectedException#AlreadyConnectedException()}
*/
public void test_Constructor() {
AlreadyConnectedException e = new AlreadyConnectedException();
assertNull(e.getMessage());
assertNull(e.getLocalizedMessage());
assertNull(e.getCause());
}
use of java.nio.channels.AlreadyConnectedException in project jdk8u_jdk by JetBrains.
the class Connect method doTest.
void doTest() {
SctpChannel channel = null;
SctpServerChannel ssc = null;
try {
/* Create a server channel to connect to */
ssc = SctpServerChannel.open().bind(null);
Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
if (addrs.isEmpty())
debug("addrs should not be empty");
final SocketAddress peerAddress = (InetSocketAddress) addrs.iterator().next();
channel = SctpChannel.open();
/* TEST 0.5 Verify default values for new/unconnected channel */
check(channel.getRemoteAddresses().isEmpty(), "non empty set for unconnected channel");
check(channel.association() == null, "non-null association for unconnected channel");
check(!channel.isConnectionPending(), "should not have a connection pending");
/* TEST 1: non-blocking connect */
channel.configureBlocking(false);
if (channel.connect(peerAddress) != true) {
debug("non-blocking connect did not immediately succeed");
check(channel.isConnectionPending(), "should return true for isConnectionPending");
try {
channel.connect(peerAddress);
fail("should have thrown ConnectionPendingException");
} catch (ConnectionPendingException cpe) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
channel.configureBlocking(true);
check(channel.finishConnect(), "finishConnect should have returned true");
}
ssc.accept();
ssc.close();
/* TEST 1.5 Verify after connect */
check(!channel.getRemoteAddresses().isEmpty(), "empty set for connected channel");
check(channel.association() != null, "null association for connected channel");
check(!channel.isConnectionPending(), "pending connection for connected channel");
/* TEST 2: Verify AlreadyConnectedException thrown */
try {
channel.connect(peerAddress);
fail("should have thrown AlreadyConnectedException");
} catch (AlreadyConnectedException unused) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 2.5: Verify AlreadyConnectedException thrown */
try {
channel.connect(peerAddress, 5, 5);
fail("should have thrown AlreadyConnectedException");
} catch (AlreadyConnectedException unused) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 3: UnresolvedAddressException */
channel.close();
channel = SctpChannel.open();
InetSocketAddress unresolved = InetSocketAddress.createUnresolved("xxyyzzabc", 4567);
try {
channel.connect(unresolved);
fail("should have thrown UnresolvedAddressException");
} catch (UnresolvedAddressException unused) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 4: UnsupportedAddressTypeException */
SocketAddress unsupported = new UnsupportedSocketAddress();
try {
channel.connect(unsupported);
fail("should have thrown UnsupportedAddressTypeException");
} catch (UnsupportedAddressTypeException unused) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 5: ClosedChannelException */
channel.close();
final SctpChannel closedChannel = channel;
testCCE(new Callable<Void>() {
public Void call() throws IOException {
closedChannel.connect(peerAddress);
return null;
}
});
/* TEST 5.5 getRemoteAddresses */
testCCE(new Callable<Void>() {
public Void call() throws IOException {
closedChannel.getRemoteAddresses();
return null;
}
});
testCCE(new Callable<Void>() {
public Void call() throws IOException {
closedChannel.association();
return null;
}
});
check(!channel.isConnectionPending(), "pending connection for closed channel");
/* Run some more finishConnect tests */
/* TEST 6: NoConnectionPendingException */
channel = SctpChannel.open();
try {
channel.finishConnect();
fail("should have thrown NoConnectionPendingException");
} catch (NoConnectionPendingException unused) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 7: ClosedChannelException */
channel.close();
final SctpChannel cceChannel = channel;
testCCE(new Callable<Void>() {
public Void call() throws IOException {
cceChannel.finishConnect();
return null;
}
});
/* TEST 8: IOException: Connection refused. Exercises handleSocketError.
* Assumption: no sctp socket listening on 3456 */
SocketAddress addr = new InetSocketAddress("localhost", 3456);
channel = SctpChannel.open();
try {
channel.connect(addr);
fail("should have thrown ConnectException: Connection refused");
} catch (IOException ioe) {
pass();
}
} catch (IOException ioe) {
unexpected(ioe);
} finally {
try {
if (channel != null)
channel.close();
} catch (IOException unused) {
}
try {
if (ssc != null)
ssc.close();
} catch (IOException unused) {
}
}
}
Aggregations