< prev index next >

test/java/net/httpclient/ManyRequests.java

Print this page

        

*** 22,43 **** */ /** * @test * @bug 8087112 ! * @library /lib/testlibrary/ ! * @build jdk.testlibrary.SimpleSSLContext * @compile ../../../com/sun/net/httpserver/LogFilter.java * @compile ../../../com/sun/net/httpserver/FileServerHandler.java ! * @run main/othervm ManyRequests * @summary Send a large number of requests asynchronously */ //package javaapplication16; ! import com.sun.net.httpserver.HttpsConfigurator; ! import com.sun.net.httpserver.HttpsServer; import java.io.IOException; import java.io.UncheckedIOException; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; --- 22,42 ---- */ /** * @test * @bug 8087112 ! * @library /lib/testlibrary/ / ! * @build jdk.testlibrary.SimpleSSLContext EchoHandler * @compile ../../../com/sun/net/httpserver/LogFilter.java * @compile ../../../com/sun/net/httpserver/FileServerHandler.java ! * @run main/othervm/timeout=40 -Djava.net.http.HttpClient.log=ssl ManyRequests * @summary Send a large number of requests asynchronously */ //package javaapplication16; ! import com.sun.net.httpserver.*; import java.io.IOException; import java.io.UncheckedIOException; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse;
*** 45,66 **** import java.net.URI; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.Random; import java.util.concurrent.CompletableFuture; ! import javax.net.ssl.SSLContext; import jdk.testlibrary.SimpleSSLContext; public class ManyRequests { public static void main(String[] args) throws Exception { SSLContext ctx = new SimpleSSLContext().get(); InetSocketAddress addr = new InetSocketAddress(0); HttpsServer server = HttpsServer.create(addr, 0); ! server.setHttpsConfigurator(new HttpsConfigurator(ctx)); HttpClient client = HttpClient.create() .sslContext(ctx) .build(); try { --- 44,72 ---- import java.net.URI; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.Random; + import java.util.logging.*; import java.util.concurrent.CompletableFuture; ! import javax.net.ssl.*; import jdk.testlibrary.SimpleSSLContext; public class ManyRequests { + volatile static int counter = 0; + public static void main(String[] args) throws Exception { + Logger logger = Logger.getLogger("com.sun.net.httpserver"); + logger.setLevel(Level.ALL); + logger.info("TEST"); + SSLContext ctx = new SimpleSSLContext().get(); InetSocketAddress addr = new InetSocketAddress(0); HttpsServer server = HttpsServer.create(addr, 0); ! server.setHttpsConfigurator(new Configurator(ctx)); HttpClient client = HttpClient.create() .sslContext(ctx) .build(); try {
*** 70,80 **** server.stop(0); client.executorService().shutdownNow(); } } ! static final int REQUESTS = 1000; static void test(HttpsServer server, HttpClient client) throws Exception { int port = server.getAddress().getPort(); URI uri = new URI("https://127.0.0.1:" + port + "/foo/x"); server.createContext("/foo", new EchoHandler()); --- 76,87 ---- server.stop(0); client.executorService().shutdownNow(); } } ! //static final int REQUESTS = 1000; ! static final int REQUESTS = 20; static void test(HttpsServer server, HttpClient client) throws Exception { int port = server.getAddress().getPort(); URI uri = new URI("https://127.0.0.1:" + port + "/foo/x"); server.createContext("/foo", new EchoHandler());
*** 100,109 **** --- 107,119 ---- limiter.requestComplete(); if (resp.statusCode() != 200) { resp.bodyAsync(HttpResponse.ignoreBody()); String s = "Expected 200, got: " + resp.statusCode(); return completedWithIOException(s); + } else { + counter++; + System.out.println("Result from " + counter); } return resp.bodyAsync(HttpResponse.asByteArray()) .thenApply((b) -> new Pair<>(resp, b)); }) .thenAccept((pair) -> {
*** 112,129 **** check(Arrays.equals(requestBody, pair.u), "bodies not equal"); }); } // wait for them all to complete and throw exception in case of error CompletableFuture.allOf(results).join(); } static <T> CompletableFuture<T> completedWithIOException(String message) { ! CompletableFuture<T> cf = new CompletableFuture<>(); ! cf.completeExceptionally(new IOException(message)); ! return cf; } static final class Pair<T,U> { Pair(T t, U u) { this.t = t; this.u = u; --- 122,143 ---- check(Arrays.equals(requestBody, pair.u), "bodies not equal"); }); } + // wait for them all to complete and throw exception in case of error + //try { CompletableFuture.allOf(results).join(); + //} catch (Exception e) { + //e.printStackTrace(); + //throw e; + //} } static <T> CompletableFuture<T> completedWithIOException(String message) { ! return CompletableFuture.failedFuture(new IOException(message)); } static final class Pair<T,U> { Pair(T t, U u) { this.t = t; this.u = u;
*** 190,194 **** --- 204,219 ---- for (Object o : msg) sb.append(o); throw new RuntimeException(sb.toString()); } } + + class Configurator extends HttpsConfigurator { + public Configurator(SSLContext ctx) { + super(ctx); + } + + public void configure (HttpsParameters params) { + params.setSSLParameters (getSSLContext().getSupportedSSLParameters()); + } + } +
< prev index next >