64 this.authority = authority; |
64 this.authority = authority; |
65 this.path = path; |
65 this.path = path; |
66 this.allowerror = allowerror; |
66 this.allowerror = allowerror; |
67 } |
67 } |
68 |
68 |
|
69 @Override |
69 public void run () { |
70 public void run () { |
70 try { |
71 try { |
71 URI u = new URI ("http", authority, path, null, null); |
72 URI u = new URI ("http", authority, path, null, null); |
72 URL url = u.toURL(); |
73 URL url = u.toURL(); |
73 URLConnection urlc = url.openConnection(); |
74 URLConnection urlc = url.openConnection(); |
74 InputStream is = urlc.getInputStream(); |
75 try (InputStream is = urlc.getInputStream()) { |
75 read (is); |
76 read (is); |
76 is.close(); |
77 } |
77 } catch (URISyntaxException e) { |
78 } catch (URISyntaxException e) { |
78 System.out.println (e); |
79 System.out.println (e); |
79 error = true; |
80 error = true; |
80 } catch (IOException e) { |
81 } catch (IOException e) { |
81 if (!allowerror) { |
82 if (!allowerror) { |
124 new AuthenticationHandlerT3a()); |
123 new AuthenticationHandlerT3a()); |
125 server.createContext("/test/realm4/t3b", |
124 server.createContext("/test/realm4/t3b", |
126 new AuthenticationHandlerT3bc()); |
125 new AuthenticationHandlerT3bc()); |
127 server.createContext("/test/realm4/t3c", |
126 server.createContext("/test/realm4/t3c", |
128 new AuthenticationHandlerT3bc()); |
127 new AuthenticationHandlerT3bc()); |
129 t1Cond1 = new CyclicBarrier(2); |
128 t1Cond1 = new CyclicBarrier(3); |
130 t1Cond2 = new CyclicBarrier(2); |
|
131 server.start(); |
129 server.start(); |
132 } |
130 } |
133 |
131 |
134 public int getPort() { |
132 public int getPort() { |
135 return server.getAddress().getPort(); |
133 return server.getAddress().getPort(); |
136 } |
134 } |
137 |
135 |
|
136 @Override |
138 public void close() { |
137 public void close() { |
139 if (executor != null) |
138 if (executor != null) |
140 ((ExecutorService)executor).shutdownNow(); |
139 ((ExecutorService)executor).shutdownNow(); |
141 if (server != null) |
140 if (server != null) |
142 server.stop(0); |
141 server.stop(0); |
190 AuthenticationHandler.errorReply(exchange, |
188 AuthenticationHandler.errorReply(exchange, |
191 "Basic realm=\"realm2\""); |
189 "Basic realm=\"realm2\""); |
192 break; |
190 break; |
193 case 1: |
191 case 1: |
194 t1Cond1.await(); |
192 t1Cond1.await(); |
195 t1cond1latch.countDown(); |
|
196 t1cond2latch.await(); |
|
197 AuthenticationHandler.okReply(exchange); |
193 AuthenticationHandler.okReply(exchange); |
198 break; |
194 break; |
199 default: |
195 default: |
200 System.out.println ("Unexpected request"); |
196 System.out.println ("Unexpected request"); |
201 } |
197 } |
375 |
356 |
376 static void okReply (HttpExchange exchange) throws IOException { |
357 static void okReply (HttpExchange exchange) throws IOException { |
377 exchange.getResponseHeaders().add("Connection", "close"); |
358 exchange.getResponseHeaders().add("Connection", "close"); |
378 String response = "Hello ."; |
359 String response = "Hello ."; |
379 exchange.sendResponseHeaders(200, response.getBytes().length); |
360 exchange.sendResponseHeaders(200, response.getBytes().length); |
380 OutputStream os = exchange.getResponseBody(); |
361 try (OutputStream os = exchange.getResponseBody()) { |
381 os.write(response.getBytes()); |
362 os.write(response.getBytes()); |
382 os.close(); |
363 } |
383 exchange.close(); |
364 exchange.close(); |
384 } |
365 } |
385 } |
366 } |
386 |
367 |
387 static Server server; |
368 static Server server; |
389 |
370 |
390 static int redirects = 4; |
371 static int redirects = 4; |
391 |
372 |
392 static Client c1,c2,c3,c4,c5,c6,c7,c8,c9; |
373 static Client c1,c2,c3,c4,c5,c6,c7,c8,c9; |
393 |
374 |
394 static CountDownLatch t1cond1latch; |
|
395 static CountDownLatch t1cond2latch; |
|
396 static CountDownLatch t2condlatch; |
375 static CountDownLatch t2condlatch; |
397 static CountDownLatch t3cond1; |
376 static CountDownLatch t3cond1; |
|
377 static CyclicBarrier t1Cond1; |
398 |
378 |
399 static void doServerTests (String authority, Server server) throws Exception |
379 static void doServerTests (String authority, Server server) throws Exception |
400 { |
380 { |
401 System.out.println ("Doing Server tests"); |
381 System.out.println ("Doing Server tests"); |
402 System.out.println ("T1"); |
382 System.out.println ("T1"); |
403 c1 = new Client (authority, "/test/realm1/t1a", false); |
383 c1 = new Client (authority, "/test/realm1/t1a", false); |
404 c2 = new Client (authority, "/test/realm2/t1b", false); |
384 c2 = new Client (authority, "/test/realm2/t1b", false); |
405 c3 = new Client (authority, "/test/realm1/t1c", false); |
385 c3 = new Client (authority, "/test/realm1/t1c", false); |
406 c4 = new Client (authority, "/test/realm2/t1d", false); |
386 c4 = new Client (authority, "/test/realm2/t1d", false); |
407 t1cond1latch = new CountDownLatch(1); |
|
408 t1cond2latch = new CountDownLatch(1); |
|
409 c1.start(); c2.start(); |
387 c1.start(); c2.start(); |
410 t1cond1latch.await(); |
388 t1Cond1.await(); |
411 c3.start(); c4.start(); |
389 c3.start(); c4.start(); |
412 c1.join(); c2.join(); c3.join(); c4.join(); |
390 c1.join(); c2.join(); c3.join(); c4.join(); |
413 |
391 |
414 int f = auth.getCount(); |
392 int f = auth.getCount(); |
415 if (f != 2) { |
393 if (f != 2) { |