/* * Copyright (c) 2018, 2022, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
Server closeImmediatelyServer;
Server closeImmediatelyHttpsServer;
Server variableLengthServer;
Server variableLengthHttpsServer;
Server fixedLengthServer;
SSLContext sslContext;
SSLParameters sslParameters;
HttpClient client; int numberOfRequests;
staticfinalint REQUESTS_PER_CLIENT = 10; // create new client every 10 requests staticfinallong PAUSE_FOR_GC = 5; // 5ms to let gc work staticfinallong PAUSE_FOR_PEER = 5; // 5ms to let server react
staticfinal String EXPECTED_RESPONSE_BODY = "
Heading
Some Text
";
// A request number used to replace %reqnb% in URLs with a unique // number for better log analysis staticfinal AtomicLong reqnb = new AtomicLong();
staticfinal AtomicLong ids = new AtomicLong(); final ThreadFactory factory = new ThreadFactory() {
@Override publicThread newThread(Runnable r) { Threadthread = newThread(r, "HttpClient-Worker-" + ids.incrementAndGet()); thread.setDaemon(true); returnthread;
}
}; final ExecutorService service = Executors.newCachedThreadPool(factory);
final AtomicReference<SkipException> skiptests = new AtomicReference<>(); void checkSkip() { var skip = skiptests.get(); if (skip != null) throw skip;
} static String name(ITestResult result) { var params = result.getParameters(); return result.getName()
+ (params == null ? "()" : Arrays.toString(result.getParameters()));
}
{ httpURIClsImed, "no bytes"},
{ httpsURIClsImed, "no bytes"},
};
if (context.getFailedTests().size() > 0) { // Shorten the log output by preventing useless // skip traces to be printed for subsequent methods // if one of the previous @Test method has failed. returnnew Object[0][];
}
// Asserts that the "send" method appears in the stack of the given // exception. The synchronous API must contain the send method on the stack. staticvoid assertSendMethodOnStack(IOException ioe) { final String cn = "jdk.internal.net.http.HttpClientImpl";
List<StackTraceElement> list = Stream.of(ioe.getStackTrace())
.filter(ste -> ste.getClassName().equals(cn)
&& ste.getMethodName().equals("send"))
.collect(toList()); if (list.size() != 1) {
ioe.printStackTrace(out);
fail(cn + ".send method not found in stack.");
}
}
// Asserts that the implementation-specific ConnectionExpiredException does // NOT appear anywhere in the exception or its causal chain. staticvoid assertNoConnectionExpiredException(IOException ioe) {
Throwable throwable = ioe; do {
String cn = throwable.getClass().getSimpleName(); if (cn.equals("ConnectionExpiredException")) {
ioe.printStackTrace(out);
fail("UNEXPECTED ConnectionExpiredException in:[" + ioe + "]");
}
} while ((throwable = throwable.getCause()) != null);
}
// -- infra
/** * A server that, listens on a port, accepts new connections, and can be * closed.
*/ staticabstractclass Server extendsThreadimplements AutoCloseable { protectedfinal ServerSocket ss; protectedvolatileboolean closed;
/** * A server that closes the connection immediately, without reading or writing.
*/ staticclass PlainCloseImmediatelyServer extends Server {
PlainCloseImmediatelyServer() throws IOException { super("PlainCloseImmediatelyServer");
}
@Override publicvoid run() { while (!closed) { try (Socket s = ss.accept()) { if (s instanceof SSLSocket) {
((SSLSocket)s).startHandshake();
}
out.println("Server: got connection, closing immediately ");
} catch (Throwable e) { if (!closed) {
out.println("Unexpected exception in server: " + e);
e.printStackTrace(out); thrownew RuntimeException("Unexpected: ", e);
}
}
}
}
}
/** * A server that closes the connection immediately, without reading or writing, * after completing the SSL handshake.
*/ staticfinalclass SSLCloseImmediatelyServer extends PlainCloseImmediatelyServer {
SSLCloseImmediatelyServer() throws IOException { super("SSLCloseImmediatelyServer");
}
@Override public ServerSocket newServerSocket() throws IOException { return SSLServerSocketFactory.getDefault().createServerSocket();
}
}
/** * A server that replies with headers and a, possibly partial, reply, before * closing the connection. The number of bytes of written ( header + body), * is controllable through the "length" query string param in the requested * URI.
*/ staticabstractclass ReplyingServer extends Server {
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.