Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClientConnection$IBodySinkPair


    public void testHttpConnectionTimeout() throws Exception {
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
       
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
        IFutureResponse futureResponse = con.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?pauseMillis=500"));

        try {
            futureResponse.getResponse(100, TimeUnit.MILLISECONDS);
            Assert.fail("SocketTimeoutException expected");
        } catch (SocketTimeoutException expected) { }
       
        Assert.assertFalse(futureResponse.isCancelled());
        Assert.assertTrue(futureResponse.isDone());
       
        con.close();
        server.close();
    }
View Full Code Here


    public void testHttpConnectionCancel() throws Exception {
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
       
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
        IFutureResponse futureResponse = con.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?pauseMillis=500"));

        futureResponse.cancel(true);
       
        Assert.assertTrue(futureResponse.isCancelled());
        Assert.assertTrue(futureResponse.isDone());
       
        con.close();
        server.close();
    }
View Full Code Here

  public void testConnectionTimeoutHandled() throws Exception {

    IServer server = new HttpServer(new ServerHandler3());
    ConnectionUtils.start(server);
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setConnectionTimeoutMillis(1000);
   
    ResponseHandler respHdl = new ResponseHandler();
    HttpRequestHeader reqHdr = new HttpRequestHeader("POST", "/");

    BodyDataSink bodyDataSink = con.send(reqHdr, respHdl);
    bodyDataSink.write("er");
   
    QAUtil.sleep(1500);
   
    Assert.assertEquals(1, respHdl.getCountSocketException());
    Assert.assertEquals(0, respHdl.getCountIOException());
   
    con.close();
    server.close();
  }
View Full Code Here

  public void testConnectionTimeout() throws Exception {

    IServer server = new HttpServer(new ServerHandler3());
    ConnectionUtils.start(server);
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setConnectionTimeoutMillis(1000);
   
    ResponseHandler2 respHdl = new ResponseHandler2();
    HttpRequestHeader reqHdr = new HttpRequestHeader("POST", "/");

    BodyDataSink bodyDataSink = con.send(reqHdr, respHdl);
    bodyDataSink.write("er");
   
    QAUtil.sleep(2000);
   
    Assert.assertEquals(1, respHdl.getCountIOException());
   
    con.close();
    server.close();
  }
View Full Code Here

  public void testIdleTimeout() throws Exception {

    IServer server = new HttpServer(new ServerHandler());
    ConnectionUtils.start(server);
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setIdleTimeoutMillis(500);
   
    QAUtil.sleep(1000);
    Assert.assertFalse(con.isOpen());
   
    con.close();
    server.close();
  }
View Full Code Here

  @Test
  public void testIdleTimeout2() throws Exception {
    IServer server = new HttpServer(new ServerHandler());
    ConnectionUtils.start(server);
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setIdleTimeoutMillis(500);
   
    GetRequest request = new GetRequest("/");
    request.setHeader("sleep-time", Integer.toString(1000));
    try {
      con.call(request);
      Assert.fail("SocketTimeoutException expected");
    } catch (IOException expected) { }
   
    con.close();
    server.close();
  }
View Full Code Here

  public void testBodyDataReceiveTimeout() throws Exception {
   
    IServer server = new HttpServer(new ServerHandler2());
    server.start();
 
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setBodyDataReceiveTimeoutMillis(1000);

    IHttpResponse response = con.call(new GetRequest("/?loops=3&waittime=200"));
    response.getBody().readString();
   
    response = con.call(new GetRequest("/?loops=1&waittime=20000"));
   
    try {
      response.getBody().readString();
      Assert.fail("ReceiveTimeoutException expected");
    } catch (ReceiveTimeoutException expected) { }

   
    con.close();
    server.close();
  }
View Full Code Here

  public void testResponseTimeoutHandler() throws Exception {

    IServer server = new HttpServer(new ServerHandler());
    ConnectionUtils.start(server);
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setResponseTimeoutMillis(1000);
   
    ResponseHandler respHdl = new ResponseHandler();
    HttpRequestHeader reqHdr = new HttpRequestHeader("GET", "/");
    reqHdr.setHeader("sleep-time", Integer.toString(1000));

    con.send(reqHdr, respHdl);
   
    QAUtil.sleep(1500);
   
    Assert.assertEquals(0, respHdl.getCountIOException());
    Assert.assertEquals(1, respHdl.getCountSocketException());
   
    con.close();
    server.close();
  }
View Full Code Here

  public void testResponseTimeout() throws Exception {

    IServer server = new HttpServer(new ServerHandler());
    ConnectionUtils.start(server);
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setResponseTimeoutMillis(1000);
   
    ResponseHandler2 respHdl = new ResponseHandler2();
    HttpRequestHeader reqHdr = new HttpRequestHeader("GET", "/");
    reqHdr.setHeader("sleep-time", Integer.toString(1000));

    con.send(reqHdr, respHdl);
   
    QAUtil.sleep(1500);
   
    Assert.assertEquals(1, respHdl.getCountIOException());
   
    con.close();
    server.close();
  }
View Full Code Here

      String basepath = file.getParentFile().getAbsolutePath();
   
    IServer server = new HttpServer(new FileServiceRequestHandler(basepath));
    server.start();
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
   

    IHttpRequest request = new GetRequest("/" + file.getName());
    request.setHeader("Range", "bytes=70-");
   
    IHttpResponse response = con.call(request);
   
    Assert.assertEquals(206, response.getStatus());
    Assert.assertEquals("head>", response.getBody().readString());
   
    file.delete();
    con.close();
    server.close();
  }
View Full Code Here

TOP

Related Classes of org.xlightweb.client.HttpClientConnection$IBodySinkPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.