From fadcd6501879af40360b217d2f76ab86a6f55d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jeli=C5=84ski?= Date: Wed, 7 Jun 2023 07:51:05 +0000 Subject: [PATCH] 8309527: Improve test proxy performance Reviewed-by: dfuchs, jpai --- .../SetAuthenticator/HTTPTestServer.java | 11 ++++++----- test/jdk/java/net/httpclient/DigestEchoServer.java | 11 ++++++----- test/jdk/java/net/httpclient/ProxyTest.java | 11 ++++++----- test/jdk/java/net/httpclient/http2/ProxyTest2.java | 9 +++++---- test/jdk/sun/net/www/http/HttpClient/B8209178.java | 11 ++++++----- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestServer.java b/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestServer.java index 5bdc032280a..aa158c3b667 100644 --- a/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestServer.java +++ b/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1023,13 +1023,14 @@ public class HTTPTestServer extends HTTPTest { public void run() { try { try { - int c; - while ((c = is.read()) != -1) { - os.write(c); + int len; + byte[] buf = new byte[16 * 1024]; + while ((len = is.read(buf)) != -1) { + os.write(buf, 0, len); os.flush(); // if DEBUG prints a + or a - for each transferred // character. - if (DEBUG) System.out.print(tag); + if (DEBUG) System.out.print(String.valueOf(tag).repeat(len)); } is.close(); } finally { diff --git a/test/jdk/java/net/httpclient/DigestEchoServer.java b/test/jdk/java/net/httpclient/DigestEchoServer.java index 970be335b82..187951405c2 100644 --- a/test/jdk/java/net/httpclient/DigestEchoServer.java +++ b/test/jdk/java/net/httpclient/DigestEchoServer.java @@ -1443,18 +1443,19 @@ public abstract class DigestEchoServer implements HttpServerAdapters { @Override public void run() { try { - int c = 0; + int len = 0; + byte[] buf = new byte[16 * 1024]; try { - while ((c = is.read()) != -1) { - os.write(c); + while ((len = is.read(buf)) != -1) { + os.write(buf, 0, len); os.flush(); // if DEBUG prints a + or a - for each transferred // character. - if (DEBUG) System.out.print(tag); + if (DEBUG) System.out.print(String.valueOf(tag).repeat(len)); } is.close(); } catch (IOException ex) { - if (DEBUG || !stopped && c > -1) + if (DEBUG || !stopped && len > -1) ex.printStackTrace(System.out); end.completeExceptionally(ex); } finally { diff --git a/test/jdk/java/net/httpclient/ProxyTest.java b/test/jdk/java/net/httpclient/ProxyTest.java index aa2faeff327..8763e168a06 100644 --- a/test/jdk/java/net/httpclient/ProxyTest.java +++ b/test/jdk/java/net/httpclient/ProxyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -256,13 +256,14 @@ public class ProxyTest { public void run() { try { try { - int c; - while ((c = is.read()) != -1) { - os.write(c); + int len; + byte[] buf = new byte[16 * 1024]; + while ((len = is.read(buf)) != -1) { + os.write(buf, 0, len); os.flush(); // if DEBUG prints a + or a - for each transferred // character. - if (DEBUG) System.out.print(tag); + if (DEBUG) System.out.print(String.valueOf(tag).repeat(len)); } is.close(); } finally { diff --git a/test/jdk/java/net/httpclient/http2/ProxyTest2.java b/test/jdk/java/net/httpclient/http2/ProxyTest2.java index 32f7bd6b708..733c21ffe68 100644 --- a/test/jdk/java/net/httpclient/http2/ProxyTest2.java +++ b/test/jdk/java/net/httpclient/http2/ProxyTest2.java @@ -187,13 +187,14 @@ public class ProxyTest2 { public void run() { try { try { - int c; - while ((c = is.read()) != -1) { - os.write(c); + int len; + byte[] buf = new byte[16 * 1024]; + while ((len = is.read(buf)) != -1) { + os.write(buf, 0, len); os.flush(); // if DEBUG prints a + or a - for each transferred // character. - if (DEBUG) System.out.print(tag); + if (DEBUG) System.out.print(String.valueOf(tag).repeat(len)); } is.close(); } finally { diff --git a/test/jdk/sun/net/www/http/HttpClient/B8209178.java b/test/jdk/sun/net/www/http/HttpClient/B8209178.java index fec17ff84d1..9d1a89aabd5 100644 --- a/test/jdk/sun/net/www/http/HttpClient/B8209178.java +++ b/test/jdk/sun/net/www/http/HttpClient/B8209178.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -214,13 +214,14 @@ public class B8209178 { public void run() { try { try { - int c; - while ((c = is.read()) != -1) { - os.write(c); + int len; + byte[] buf = new byte[16 * 1024]; + while ((len = is.read(buf)) != -1) { + os.write(buf, 0, len); os.flush(); // if DEBUG prints a + or a - for each transferred // character. - if (DEBUG) System.out.print(tag); + if (DEBUG) System.out.print(String.valueOf(tag).repeat(len)); } is.close(); } finally {