public void testAsyncConnectTimeout() throws IOException
{
ServerSocket serverSocket = new ServerSocket(0);
int port = serverSocket.getLocalPort();
final NiftyClient client = new NiftyClient();
try {
ListenableFuture<FramedClientChannel> future =
client.connectAsync(new FramedClientConnector(new InetSocketAddress(port)),
TEST_CONNECT_TIMEOUT,
TEST_READ_TIMEOUT,
TEST_WRITE_TIMEOUT,
TEST_MAX_FRAME_SIZE);
// Wait while NiftyClient attempts to connect the channel
future.get();
}
catch (Throwable throwable) {
if (isTimeoutException(throwable)) {
return;
}
Throwables.propagate(throwable);
}
finally {
client.close();
serverSocket.close();
}
// Should never get here
fail("Connection succeeded but failure was expected");