Index: src/test/java/org/apache/harmony/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java *************** *** 84,89 **** --- 84,135 ---- } } + static class MockHTTPServer extends MockServer { + int persUses; + + public MockHTTPServer(String name, int persUses) throws IOException { + super(name); + this.persUses = persUses; + } + + public int port() { + return serverSocket.getLocalPort(); + } + + @Override + public void run() { + try { + synchronized (bound) { + started = true; + bound.notify(); + } + try { + Socket client = serverSocket.accept(); + accepted = true; + for (int i=0; i").getBytes()); + } + } catch (SocketTimeoutException ignore) { + } + serverSocket.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + static class MockProxyServer extends MockServer { boolean acceptedAuthorizedRequest; *************** *** 436,441 **** --- 482,535 ---- * @throws IOException * @throws MalformedURLException */ + public void testConnectionPersistance() throws Exception { + MockHTTPServer httpServer = + new MockHTTPServer("HTTP Server for persistence checking", 2); + httpServer.start(); + synchronized(bound) { + if (!httpServer.started) { + bound.wait(5000); + } + } + + HttpURLConnection c = (HttpURLConnection) + new URL("http://localhost:"+httpServer.port()).openConnection(); + System.out.println("Actual connection class: "+c.getClass()); + + c.setDoInput(true); + c.setConnectTimeout(1000); + c.setReadTimeout(1000); + InputStream is = c.getInputStream(); + byte[] buffer = new byte[128]; + int totalBytes = 0; + int bytesRead = 0; + while((bytesRead = is.read(buffer)) > 0){ + System.out.println("Client got response: '" + + new String(buffer, 0, bytesRead) + "'"); + totalBytes += bytesRead; + } + + HttpURLConnection c2 = (HttpURLConnection) + new URL("http://localhost:"+httpServer.port()).openConnection(); + c2.setDoInput(true); + c2.setConnectTimeout(1000); + c2.setReadTimeout(1000); + is = c2.getInputStream(); + buffer = new byte[128]; + totalBytes = 0; + bytesRead = 0; + while((bytesRead = is.read(buffer)) > 0){ + System.out.println("Client got response: '" + + new String(buffer, 0, bytesRead) + "'"); + totalBytes += bytesRead; + } + } + + /** + * Test that a connection is not closed if the client does read all the data + * @throws IOException + * @throws MalformedURLException + */ public void testCorrectUsage() throws MalformedURLException, IOException { int initialFreeConnections = HttpConnectionManager.getDefault().numFreeConnections(); HttpURLConnection c = (HttpURLConnection)