# HG changeset patch # User alanb # Date 1551452733 0 # Node ID 510cfa1184087c9c588a33e72d9ba9bc846002b3 # Parent aebe3e4fd2d15156c9003585221a1a9ca265be4e Expand and clean-up test coverage diff -r aebe3e4fd2d1 -r 510cfa118408 test/jdk/java/net/SocketImpl/SocketImplCombinations.java --- a/test/jdk/java/net/SocketImpl/SocketImplCombinations.java Thu Feb 28 17:41:16 2019 +0000 +++ b/test/jdk/java/net/SocketImpl/SocketImplCombinations.java Fri Mar 01 15:05:33 2019 +0000 @@ -213,7 +213,7 @@ * Test creating a Socket with a "null" SocketImpl when there is a * SocketImplFactory set. */ - public void testNewSocket20() throws IOException { + public void testNewSocket12() throws IOException { setSocketSocketImplFactory(() -> new CustomSocketImpl(false)); try { Socket s = new Socket((SocketImpl) null) { }; @@ -398,6 +398,94 @@ } /** + * Test ServerSocket.accept using a custom SocketImpl. The client Socket + * has a platform SocketImpl so IOException should be thrown. + */ + public void testServerSocketAccept7() throws IOException { + SocketImpl impl = new CustomSocketImpl(true); + var socket = new Socket(); + try (ServerSocket ss = serverSocketToAccept(impl, socket)) { + expectThrows(IOException.class, ss::accept); + } finally { + socket.close(); + } + } + + /** + * Test ServerSocket.accept using a custom SocketImpl. The client Socket + * has no SocketImpl so a platform SocketImpl will be created and IOException + * should be thrown. + */ + public void testServerSocketAccept8() throws IOException { + SocketImpl impl = new CustomSocketImpl(true); + var socket = new Socket((SocketImpl) null) { }; + try (ServerSocket ss = serverSocketToAccept(impl, socket)) { + expectThrows(IOException.class, ss::accept); + } finally { + socket.close(); + } + } + + /** + * Test ServerSocket.accept using a custom SocketImpl. The client Socket + * has no SocketImpl so a platform SocketImpl will be created and IOException + * should be thrown. + */ + public void testServerSocketAccept9() throws IOException { + SocketImpl impl = new CustomSocketImpl(true); + try (ServerSocket ss = new ServerSocket(impl) { }) { + ss.bind(new InetSocketAddress(0)); + expectThrows(IOException.class, ss::accept); + } + } + + /** + * Test ServerSocket.accept where there is a custom server SocketImplFactory + * set. The client Socket has a platform SocketImpl so IOException should be + * thrown. + */ + public void testServerSocketAccept10() throws IOException { + var socket = new Socket(); + setServerSocketImplFactory(() -> new CustomSocketImpl(true)); + try (ServerSocket ss = serverSocketToAccept(socket)) { + expectThrows(IOException.class, ss::accept); + } finally { + setServerSocketImplFactory(null); + socket.close(); + } + } + + /** + * Test ServerSocket.accept where there is a custom server SocketImplFactory + * set. The client Socket has no SocketImpl so a platform SocketImpl will be + * created and IOException should be thrown. + */ + public void testServerSocketAccept11() throws IOException { + var socket = new Socket((SocketImpl) null) { }; + setServerSocketImplFactory(() -> new CustomSocketImpl(true)); + try (ServerSocket ss = serverSocketToAccept(socket)) { + expectThrows(IOException.class, ss::accept); + } finally { + setServerSocketImplFactory(null); + socket.close(); + } + } + + /** + * Test ServerSocket.accept where there is a custom server SocketImplFactory + * set. The client Socket has no SocketImpl so a platform SocketImpl will be + * created and IOException should be thrown. + */ + public void testServerSocketAccept12() throws IOException { + setServerSocketImplFactory(() -> new CustomSocketImpl(true)); + try (ServerSocket ss = new ServerSocket(0)) { + expectThrows(IOException.class, ss::accept); + } finally { + setServerSocketImplFactory(null); + } + } + + /** * Creates a ServerSocket that returns the given Socket from accept. * The consumer is invoked with the server socket and the accepted socket. */ @@ -445,28 +533,6 @@ } /** - * Creates a ServerSocket with a SocketImpl that returns the given Socket - * from accept. The consumer is invoked with the server socket and the - * accepted socket. - */ - static void serverSocketAccept(SocketImpl impl, - Socket socket, - BiConsumer consumer) - throws IOException - { - Socket s1 = null; - Socket s2 = null; - try (ServerSocket ss = serverSocketToAccept(impl, socket)) { - s1 = new Socket(ss.getInetAddress(), ss.getLocalPort()); - s2 = ss.accept(); - consumer.accept(ss, s2); - } finally { - if (s1 != null) s1.close(); - if (s2 != null) s2.close(); - } - } - - /** * Creates a ServerSocket with a SocketImpl returns the given Socket from * accept. The given SocketImplFactory is set during the accept and the * consumer is invoked when the server socket and the accepted socket.