57 public class Timeouts {
58
59 /**
60 * Test timed connect where connection is established
61 */
62 public void testTimedConnect1() throws IOException {
63 try (ServerSocket ss = boundServerSocket()) {
64 try (Socket s = new Socket()) {
65 s.connect(ss.getLocalSocketAddress(), 2000);
66 }
67 }
68 }
69
70 /**
71 * Test timed connect where connection is refused
72 */
73 public void testTimedConnect2() throws IOException {
74 try (Socket s = new Socket()) {
75 SocketAddress remote = Utils.refusingEndpoint();
76 try {
77 s.connect(remote, 2000);
78 } catch (ConnectException expected) { }
79 }
80 }
81
82 /**
83 * Test connect with a timeout of Integer.MAX_VALUE
84 */
85 public void testTimedConnect3() throws IOException {
86 try (ServerSocket ss = boundServerSocket()) {
87 try (Socket s = new Socket()) {
88 s.connect(ss.getLocalSocketAddress(), Integer.MAX_VALUE);
89 }
90 }
91 }
92
93 /**
94 * Test connect with a negative timeout.
95 */
96 public void testTimedConnect4() throws IOException {
97 try (ServerSocket ss = boundServerSocket()) {
|
57 public class Timeouts {
58
59 /**
60 * Test timed connect where connection is established
61 */
62 public void testTimedConnect1() throws IOException {
63 try (ServerSocket ss = boundServerSocket()) {
64 try (Socket s = new Socket()) {
65 s.connect(ss.getLocalSocketAddress(), 2000);
66 }
67 }
68 }
69
70 /**
71 * Test timed connect where connection is refused
72 */
73 public void testTimedConnect2() throws IOException {
74 try (Socket s = new Socket()) {
75 SocketAddress remote = Utils.refusingEndpoint();
76 try {
77 s.connect(remote, 3000);
78 } catch (ConnectException expected) { }
79 }
80 }
81
82 /**
83 * Test connect with a timeout of Integer.MAX_VALUE
84 */
85 public void testTimedConnect3() throws IOException {
86 try (ServerSocket ss = boundServerSocket()) {
87 try (Socket s = new Socket()) {
88 s.connect(ss.getLocalSocketAddress(), Integer.MAX_VALUE);
89 }
90 }
91 }
92
93 /**
94 * Test connect with a negative timeout.
95 */
96 public void testTimedConnect4() throws IOException {
97 try (ServerSocket ss = boundServerSocket()) {
|