/* * Copyright (c) 2018, 2019, 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.
*/
/* * @test * @bug 8196389 * @summary Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server * * @modules java.base/sun.net.www.http * java.net.http/jdk.internal.net.http.common * java.net.http/jdk.internal.net.http.frame * java.net.http/jdk.internal.net.http.hpack * java.logging * jdk.httpserver * @library /test/lib http2/server * @build Http2TestServer * @build jdk.test.lib.net.SimpleSSLContext * @run testng/othervm -ea -esa MaxStreams
*/
Http2TestServer http2TestServer; // HTTP/2 ( h2c )
Http2TestServer https2TestServer; // HTTP/2 ( h2 ) final Http2FixedHandler handler = new Http2FixedHandler();
SSLContext ctx;
String http2FixedURI;
String https2FixedURI; volatile CountDownLatch latch;
ExecutorService exec; final Semaphore canStartTestRun = new Semaphore(1);
// we send an initial warm up request, then MAX_STREAMS+1 requests // in parallel. The last of them should hit the limit. // Then we wait for all the responses and send a further request // which should succeed. The server should see (and respond to) // MAX_STREAMS+2 requests per test run.
// wait until we get local exception before allow server to proceed try {
System.err.println("Waiting for first exception");
CompletableFuture.anyOf(responses.toArray(new CompletableFuture<?>[0])).join();
} catch (Exception ee) {
System.err.println("Expected exception 1 " + ee);
}
latch.countDown();
// check the first MAX_STREAMS requests succeeded try {
System.err.println("Waiting for second exception");
CompletableFuture.allOf(responses.toArray(new CompletableFuture<?>[0])).join();
System.err.println("Did not get Expected exception 2 ");
} catch (Exception ee) {
System.err.println("Expected exception 2 " + ee);
} int count = 0; int failures = 0; for (CompletableFuture<HttpResponse<String>> cf : responses) {
HttpResponse<String> r = null; try {
count++;
r = cf.join(); if (r.statusCode() != 200 || !r.body().equals(RESPONSE)) thrownew RuntimeException();
} catch (Throwable t) {
failures++;
System.err.printf("Failure %d at count %d\n", failures, count);
System.err.println(t);
t.printStackTrace();
}
} if (failures != 1) {
String msg = "Expected 1 failure. Got " + failures; thrownew RuntimeException(msg);
}
System.err.println("Sending last request"); // make sure it succeeds now as number of streams == 0 now
HttpResponse<String> warmdown = client.send(request, BodyHandlers.ofString()); if (warmdown.statusCode() != 200 || !warmdown.body().equals(RESPONSE)) thrownew RuntimeException();
System.err.println("Test OK");
}
@Override publicvoid handle(Http2TestExchange t) throws IOException { int c = -1; try (InputStream is = t.getRequestBody();
OutputStream os = t.getResponseBody()) {
is.readAllBytes();
c = counter.getAndIncrement(); if (c > 0 && c <= MAX_STREAMS) { // Wait for latch. try { // don't send any replies until all requests are sent
System.err.println("Latch await");
getLatch().await();
System.err.println("Latch resume");
} catch (InterruptedException ee) {}
}
t.sendResponseHeaders(200, RESPONSE.length());
os.write(RESPONSE.getBytes());
} finally { // client issues MAX_STREAMS + 3 requests in total // but server should only see MAX_STREAMS + 2 in total. One is rejected by client // counter c captured before increment so final value is MAX_STREAMS + 1 if (c == MAX_STREAMS + 1) {
System.err.println("Semaphore release");
counter.set(0);
canStartTestRun.release();
}
}
}
}
}
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
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.