4545import org .threadly .litesockets .utils .PortUtils ;
4646import org .threadly .test .concurrent .AsyncVerifier ;
4747import org .threadly .test .concurrent .TestCondition ;
48- import org .threadly .test .concurrent .TestUtils ;
4948import org .threadly .util .ArrayIterator ;
5049import org .threadly .util .Clock ;
51- import org .threadly .util .debug .Profiler ;
5250
5351public class HTTPClientTests {
5452 static String CONTENT = "TEST123" ;
@@ -107,13 +105,13 @@ public void manyRequestsConcurrent() throws IOException, InterruptedException, T
107105 @ Override
108106 public void run () {
109107 ClientHTTPRequest chr = hrb .buildClientHTTPRequest ();
110- final long start = Clock .accurateForwardProgressingMillis ();
108+ // final long start = Clock.accurateForwardProgressingMillis();
111109
112110 final ListenableFuture <HTTPResponseData > lf = httpClient .requestAsync (chr );
113111 lf .callback (new FutureCallback <HTTPResponseData >() {
114112 @ Override
115113 public void handleResult (HTTPResponseData result ) {
116- System .out .println ("DELAY:" +(Clock .accurateForwardProgressingMillis ()-start ));
114+ // System.out.println("DELAY:"+(Clock.accurateForwardProgressingMillis()-start));
117115 av .assertEquals (CONTENT , result .getBodyAsString ());
118116 av .signalComplete ();
119117 }
@@ -127,13 +125,6 @@ public void handleFailure(Throwable t) {
127125 for (int i =0 ; i <number ; i ++) {
128126 CLIENT_PS .execute (run );
129127 }
130-
131- Profiler p = new Profiler ();
132- TestUtils .sleep (2_000 );
133- p .start ();
134- TestUtils .sleep (2_000 );
135- p .stop ();
136- System .out .println (p .dump ());
137128
138129 av .waitForTest (10_000 , number );
139130
@@ -234,7 +225,7 @@ public void handleFailure(Throwable t) {
234225 @ Test
235226 public void blockingRequest () throws IOException , HTTPParsingException {
236227 int port = PortUtils .findTCPPort ();
237- fakeServer = new TestHTTPServer (port , RESPONSE_CL , CONTENT , false , true );
228+ fakeServer = new TestHTTPServer (port , RESPONSE_CL , CONTENT , false , true , true );
238229 final HTTPRequestBuilder hrb = new HTTPRequestBuilder (new URL ("http://localhost:" +port ));
239230 hrb .setHTTPAddress (new HTTPAddress ("localhost" , port , false ), true );
240231 final HTTPClient httpClient = new HTTPClient ();
@@ -257,7 +248,7 @@ public void noContentLengthNoBody() throws IOException, HTTPParsingException {
257248 @ Test
258249 public void noContentLengthWithBody () throws IOException , HTTPParsingException {
259250 int port = PortUtils .findTCPPort ();
260- fakeServer = new TestHTTPServer (port , RESPONSE_NO_CL , CONTENT , false , true );
251+ fakeServer = new TestHTTPServer (port , RESPONSE_NO_CL , CONTENT , false , true , true );
261252 final HTTPRequestBuilder hrb = new HTTPRequestBuilder (new URL ("http://localhost:" +port ));
262253
263254 final HTTPClient httpClient = new HTTPClient ();
@@ -267,10 +258,10 @@ public void noContentLengthWithBody() throws IOException, HTTPParsingException {
267258 assertEquals (CONTENT , hrs .getBodyAsString ());
268259 }
269260
270- // @Test
261+ @ Test
271262 public void streamedBodyRequest () throws IOException , HTTPParsingException , InterruptedException , ExecutionException {
272263 int port = PortUtils .findTCPPort ();
273- fakeServer = new TestHTTPServer (port , RESPONSE_CL , CONTENT , false , true );
264+ fakeServer = new TestHTTPServer (port , RESPONSE_CL , CONTENT , false , true , true );
274265 ByteBuffer write1 = ByteBuffer .allocate (100 );
275266 ByteBuffer write2 = ByteBuffer .allocate (100 );
276267 SettableListenableFuture <ByteBuffer > write1SLF = new SettableListenableFuture <>();
@@ -298,7 +289,7 @@ public void streamedBodyRequest() throws IOException, HTTPParsingException, Inte
298289 @ Test
299290 public void streamedBodyResponse () throws IOException , HTTPParsingException {
300291 int port = PortUtils .findTCPPort ();
301- fakeServer = new TestHTTPServer (port , RESPONSE_HUGE , LARGE_CONTENT , false , false );
292+ fakeServer = new TestHTTPServer (port , RESPONSE_HUGE , LARGE_CONTENT , false , false , false );
302293 AtomicInteger readContentSize = new AtomicInteger (0 );
303294 final HTTPRequestBuilder hrb = new HTTPRequestBuilder (new URL ("http://localhost:" +port ))
304295 .setBodyConsumer (new BodyConsumer () {
@@ -349,8 +340,7 @@ public void closeBeforeLength() throws IOException, HTTPParsingException {
349340 httpClient .request (hrb .buildClientHTTPRequest ());
350341 fail ();
351342 } catch (HTTPParsingException e ) {
352- e .printStackTrace ();
353- assertEquals ("Did not get complete body!" , e .getMessage ());
343+ assertTrue (e .getMessage ().startsWith ("Body not complete" ));
354344 }
355345 }
356346
@@ -546,7 +536,7 @@ public void accept(Client c) {
546536 @ Test
547537 public void urlRequest () throws HTTPParsingException , IOException {
548538 int port = PortUtils .findTCPPort ();
549- fakeServer = new TestHTTPServer (port , RESPONSE_CL , CONTENT , false , false );
539+ fakeServer = new TestHTTPServer (port , RESPONSE_CL , CONTENT , false , false , true );
550540 final HTTPClient httpClient = new HTTPClient ();
551541 httpClient .start ();
552542 HTTPResponseData hrd = httpClient .request (new URL ("http://localhost:" +port ));
0 commit comments