test/jdk/java/net/httpclient/http2/BasicTest.java
branchhttp-client-branch
changeset 55912 dfa9489d1cb1
parent 55909 583695a0ed6a
child 55941 2d423c9b73bb
equal deleted inserted replaced
55911:d3298b9365e7 55912:dfa9489d1cb1
    91     }
    91     }
    92 
    92 
    93     static List<CompletableFuture<Long>> cfs = Collections
    93     static List<CompletableFuture<Long>> cfs = Collections
    94         .synchronizedList( new LinkedList<>());
    94         .synchronizedList( new LinkedList<>());
    95 
    95 
    96     static AtomicReference<CompletableFuture<Long>> currentCF =
    96     static CompletableFuture<Long> currentCF;
    97         new AtomicReference<>();
       
    98 
    97 
    99     static class EchoWithPingHandler extends Http2EchoHandler {
    98     static class EchoWithPingHandler extends Http2EchoHandler {
       
    99         private final Object lock = new Object();
       
   100 
   100         @Override
   101         @Override
   101         public void handle(Http2TestExchange exchange) throws IOException {
   102         public void handle(Http2TestExchange exchange) throws IOException {
   102             // ensure only one ping active at a time.
   103             // for now only one ping active at a time. don't want to saturate
   103             currentCF.getAndUpdate((cf) -> {
   104             synchronized(lock) {
   104                 if (cf  == null || cf.isDone()) {
   105                 CompletableFuture<Long> cf = currentCF;
       
   106                 if (cf == null || cf.isDone()) {
   105                     cf = exchange.sendPing();
   107                     cf = exchange.sendPing();
   106                     assert cf != null;
   108                     assert cf != null;
   107                     cfs.add(cf);
   109                     cfs.add(cf);
       
   110                     currentCF = cf;
   108                 }
   111                 }
   109                 return cf;
   112             }
   110             });
       
   111             super.handle(exchange);
   113             super.handle(exchange);
   112         }
   114         }
   113     }
   115     }
   114 
   116 
   115     @Test
   117     @Test
   120             simpleTest(false, true);
   122             simpleTest(false, true);
   121             simpleTest(true, false);
   123             simpleTest(true, false);
   122             streamTest(false);
   124             streamTest(false);
   123             streamTest(true);
   125             streamTest(true);
   124             paramsTest();
   126             paramsTest();
   125             Thread.sleep(1000 * 4);
       
   126             CompletableFuture.allOf(cfs.toArray(new CompletableFuture[0])).join();
   127             CompletableFuture.allOf(cfs.toArray(new CompletableFuture[0])).join();
   127             synchronized (cfs) {
   128             synchronized (cfs) {
   128                 for (CompletableFuture<Long> cf : cfs) {
   129                 for (CompletableFuture<Long> cf : cfs) {
   129                     System.out.printf("Ping ack received in %d millisec\n", cf.get());
   130                     System.out.printf("Ping ack received in %d millisec\n", cf.get());
   130                 }
   131                 }