corda/sgx-jvm/avian/test/Sockets.java
Andras Slemmer 9bb3d6b972 Add 'sgx-jvm/avian/' from commit '09e4fe60d01f4f4bfb6b2976973bb4913ef61edc'
git-subtree-dir: sgx-jvm/avian
git-subtree-mainline: f978eab8d1
git-subtree-split: 09e4fe60d0
2017-03-13 12:18:24 +00:00

34 lines
918 B
Java

import java.net.SocketAddress;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.io.IOException;
public class Sockets {
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
public static void testFailedBind() throws Exception {
final String Hostname = "localhost";
final int Port = 22046; // hopefully this port is unused
final SocketAddress Address = new InetSocketAddress(Hostname, Port);
final byte[] Message = "hello, world!".getBytes();
SocketChannel out = SocketChannel.open();
try {
try {
out.connect(Address);
expect(false);
} catch(IOException e) {
// We're good. This previously triggered a vm assert, rather than an exception
}
} finally {
out.close();
}
}
public static void main(String[] args) throws Exception {
testFailedBind();
}
}