313 |
313 |
314 serverSocketAccept(socket, () -> new CustomSocketImpl(false), (ss, s) -> { |
314 serverSocketAccept(socket, () -> new CustomSocketImpl(false), (ss, s) -> { |
315 assertTrue(isPlatformSocketImpl(getSocketImpl(ss))); |
315 assertTrue(isPlatformSocketImpl(getSocketImpl(ss))); |
316 assertTrue(s == socket); |
316 assertTrue(s == socket); |
317 SocketImpl si = getSocketImpl(s); |
317 SocketImpl si = getSocketImpl(s); |
318 assertTrue(si instanceof CustomSocketImpl); |
318 assertTrue(isPlatformSocketImpl(si)); |
319 checkFields(si); |
319 checkFields(si); |
320 }); |
320 }); |
321 } |
321 } |
322 |
322 |
323 /** |
323 /** |
333 assertTrue(isPlatformSocketImpl(delegate)); |
333 assertTrue(isPlatformSocketImpl(delegate)); |
334 |
334 |
335 serverSocketAccept(socket, (ss, s) -> { |
335 serverSocketAccept(socket, (ss, s) -> { |
336 assertTrue(isPlatformSocketImpl(getSocketImpl(ss))); |
336 assertTrue(isPlatformSocketImpl(getSocketImpl(ss))); |
337 assertTrue(s == socket); |
337 assertTrue(s == socket); |
338 assertTrue(getSocketImpl(s) == si); |
338 SocketImpl psi = getSocketImpl(socket); |
339 assertTrue(getDelegate(si) == delegate); |
339 assertTrue(isPlatformSocketImpl(psi)); |
340 checkFields(delegate); |
340 checkFields(psi); |
341 }); |
341 }); |
342 } |
342 } |
343 |
343 |
344 /** |
344 /** |
345 * Test ServerSocket.accept. The ServerSocket uses a platform SocketImpl, |
345 * Test ServerSocket.accept. The ServerSocket uses a platform SocketImpl, |
348 public void testServerSocketAccept4a() throws IOException { |
348 public void testServerSocketAccept4a() throws IOException { |
349 SocketImpl clientImpl = new CustomSocketImpl(false); |
349 SocketImpl clientImpl = new CustomSocketImpl(false); |
350 Socket socket = new Socket(clientImpl) { }; |
350 Socket socket = new Socket(clientImpl) { }; |
351 assertTrue(getSocketImpl(socket) == clientImpl); |
351 assertTrue(getSocketImpl(socket) == clientImpl); |
352 |
352 |
353 serverSocketAccept(socket, (ss, s) -> { |
353 try (ServerSocket ss = serverSocketToAccept(socket)) { |
354 assertTrue(isPlatformSocketImpl(getSocketImpl(ss))); |
354 expectThrows(IOException.class, ss::accept); |
355 assertTrue(s == socket); |
355 } finally { |
356 assertTrue(getSocketImpl(s) == clientImpl); |
356 socket.close(); |
357 checkFields(clientImpl); |
357 } |
358 }); |
|
359 } |
358 } |
360 |
359 |
361 public void testServerSocketAccept4b() throws IOException { |
360 public void testServerSocketAccept4b() throws IOException { |
362 SocketImpl clientImpl = new CustomSocketImpl(false); |
361 SocketImpl clientImpl = new CustomSocketImpl(false); |
363 Socket socket = new Socket(clientImpl) { }; |
362 Socket socket = new Socket(clientImpl) { }; |
364 assertTrue(getSocketImpl(socket) == clientImpl); |
363 assertTrue(getSocketImpl(socket) == clientImpl); |
365 |
364 |
366 serverSocketAccept(socket, () -> new CustomSocketImpl(false), (ss, s) -> { |
365 setSocketSocketImplFactory(() -> new CustomSocketImpl(false)); |
367 assertTrue(isPlatformSocketImpl(getSocketImpl(ss))); |
366 try (ServerSocket ss = serverSocketToAccept(socket)) { |
368 assertTrue(s == socket); |
367 expectThrows(IOException.class, ss::accept); |
369 assertTrue(getSocketImpl(s) == clientImpl); |
368 } finally { |
370 checkFields(clientImpl); |
369 setSocketSocketImplFactory(null); |
371 }); |
370 socket.close(); |
|
371 } |
372 } |
372 } |
373 |
373 |
374 /** |
374 /** |
375 * Test ServerSocket.accept. The ServerSocket uses a custom SocketImpl, |
375 * Test ServerSocket.accept. The ServerSocket uses a custom SocketImpl, |
376 * the Socket to accept is created no SocketImpl. |
376 * the Socket to accept is created no SocketImpl. |