Examples of AsyncHttpClient


Examples of com.ning.http.client.AsyncHttpClient

  //ning === http://github.com/ning/async-http-client
  @Test
  public void doSimpleAsyncRequestTestWithNing() throws IOException, InterruptedException {
    int iterations = 100;
    final CountDownLatch latch = new CountDownLatch(iterations);
    AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
    for (int i = 1; i <= iterations; i++) {

      asyncHttpClient.prepareGet("http://localhost:" + PORT + "/").
      execute(new AsyncCompletionHandler<com.ning.http.client.Response>(){

        @Override
        public com.ning.http.client.Response onCompleted(com.ning.http.client.Response response) throws Exception{
          String body = response.getResponseBody();
View Full Code Here

Examples of com.ning.http.client.AsyncHttpClient

 
  @Test
  public void smallHttpPostBodyTest() throws ClientProtocolException, IOException, InterruptedException {
    final String body = "Roger Schildmeijer";
    final CountDownLatch latch = new CountDownLatch(1);
    AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
    asyncHttpClient.preparePost("http://localhost:" + PORT + "/echo").setBody(body).
    execute(new AsyncCompletionHandler<Response>(){

      @Override
      public Response onCompleted(Response response) throws Exception{
        assertNotNull(response);
View Full Code Here

Examples of com.ning.http.client.AsyncHttpClient

    for (int i = 1; i <= 1000; i++) {
      body += "Roger Schildmeijer: " + i + "\n";
    }
    final String expectedBody = body;
    final CountDownLatch latch = new CountDownLatch(1);
    AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
    asyncHttpClient.preparePost("http://localhost:" + PORT + "/echo").setBody(body).
    execute(new AsyncCompletionHandler<Response>(){

      @Override
      public Response onCompleted(Response response) throws Exception{
        assertNotNull(response);
View Full Code Here

Examples of com.ning.http.client.AsyncHttpClient

    }

    @Test(timeOut = 20000)
    public void testSuspendTimeout() {
        logger.info("running test: testSuspendTimeout");
        AsyncHttpClient c = new AsyncHttpClient();
        try {
            long t1 = System.currentTimeMillis();
            Response r = c.prepareGet(urlTarget).execute().get(10, TimeUnit.SECONDS);
            assertNotNull(r);
            assertEquals(r.getStatusCode(), 200);
            String resume = r.getResponseBody();
            assertEquals(resume, "resume");
            long current = System.currentTimeMillis() - t1;
            assertTrue(current > 5000 && current < 10000);
        } catch (Exception e) {
            logger.error("test failed", e);
            fail(e.getMessage());
        }
        c.close();

    }
View Full Code Here

Examples of com.ning.http.client.AsyncHttpClient

    @Test(timeOut = 60000)
    public void testSuspendTimeout() {
        logger.info("running test: testSuspendTimeout");

        AsyncHttpClient c = new AsyncHttpClient();
        try {
            long currentTime = System.currentTimeMillis();
            Response r = c.prepareGet(urlTarget).execute().get();

            long time = System.currentTimeMillis() - currentTime;
            if (time > 5000 && time < 15000) {
                assertTrue(true);
            } else {
                assertFalse(false);
            }
            assertNotNull(r);
            assertEquals(r.getStatusCode(), 200);
            String resume = r.getResponseBody();
            assertEquals(resume, "resume");
        } catch (Exception e) {
            logger.error("test failed", e);
            fail(e.getMessage());
        }
        c.close();
    }
View Full Code Here

Examples of com.ning.http.client.AsyncHttpClient

    public void testResumeOnBroadcast() {
        logger.info("running test: testResumeOnBroadcast");

        final CountDownLatch latch = new CountDownLatch(1);
        servletLatch = new CountDownLatch(1);
        AsyncHttpClient c = new AsyncHttpClient();
        try {
            long currentTime = System.currentTimeMillis();
            final AtomicReference<Response> r = new AtomicReference();
            c.prepareGet(urlTarget).execute(new AsyncCompletionHandler<Response>() {

                @Override
                public Response onCompleted(Response response) throws Exception {
                    r.set(response);
                    latch.countDown();
                    return response;
                }
            });

            servletLatch.await();

            Broadcaster b = BroadcasterFactory.getDefault().lookup(DefaultBroadcaster.class, "/*");
            assertNotNull(b);
            b.broadcast("resume").get();

            try {
                latch.await();
            } catch (InterruptedException e) {
                fail(e.getMessage());
                return;
            }

            long time = System.currentTimeMillis() - currentTime;
            if (time < 5000) {
                assertTrue(true);
            } else {
                assertFalse(false);
            }
            assertNotNull(r.get());
            assertEquals(r.get().getStatusCode(), 200);
            String resume = r.get().getResponseBody();
            assertEquals(resume, "resumeresume");
        } catch (Exception e) {
            logger.error("test failed", e);
            fail(e.getMessage());
        }
        c.close();
    }
View Full Code Here

Examples of com.ning.http.client.AsyncHttpClient

                    latch.countDown();
                }
            }
        }, new RecyclableBroadcaster("suspend"));

        AsyncHttpClient c = new AsyncHttpClient();
        try {
            Response r = c.prepareGet(urlTarget).execute().get();

            try {
                latch.await(20, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                fail(e.getMessage());
            }
            assertNotNull(r);
            assertEquals(r.getStatusCode(), 200);
            String resume = r.getResponseBody();
            assertEquals(resume, "resume");
        } catch (Exception e) {
            logger.error("test failed", e);
            fail(e.getMessage());
        }
        c.close();
    }
View Full Code Here

Examples of com.ning.http.client.AsyncHttpClient

                    latch.countDown();
                }
            }
        }, new RecyclableBroadcaster("suspend"));

        AsyncHttpClient c = new AsyncHttpClient();
        try {
            Response r = c.prepareGet(urlTarget).execute().get();

            try {
                latch.await(20, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                fail(e.getMessage());
            }

            assertNotNull(r);
            assertEquals(r.getStatusCode(), 200);
            String resume = r.getResponseBody();
            assertEquals(resume, AtmosphereResourceImpl.createCompatibleStringJunk());
        } catch (Exception e) {
            logger.error("test failed", e);
            fail(e.getMessage());
        }
        c.close();

    }
View Full Code Here

Examples of com.ning.http.client.AsyncHttpClient

                    latch.countDown();
                }
            }
        }, new RecyclableBroadcaster("suspend"));

        AsyncHttpClient c = new AsyncHttpClient();
        try {
            Response r = c.prepareGet(urlTarget).execute().get();

            if (latch.getCount() != 0) {
                fail("timedout");
            }
            assertNotNull(r);
        } catch (Exception e) {
            logger.error("test failed", e);
            fail(e.getMessage());
        }

        c.close();

    }
View Full Code Here

Examples of com.ning.http.client.AsyncHttpClient

                    latch.countDown();
                }
            }
        }, new RecyclableBroadcaster("suspend"));

        AsyncHttpClient c = new AsyncHttpClient();
        try {
            c.prepareGet(urlTarget).execute(new AsyncCompletionHandler<String>() {

                @Override
                public String onCompleted(Response response) throws Exception {
                    try {
                        assertEquals(response.getResponseBody(),
                                AtmosphereResourceImpl.createCompatibleStringJunk());
                    } finally {
                        latch.countDown();
                    }
                    return null;
                }
            });

            suspended.await(20, TimeUnit.SECONDS);
            Response r = c.prepareGet(urlTarget).execute().get();

            try {
                latch.await(20, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                fail(e.getMessage());
            }

            assertNotNull(r);
            assertEquals(r.getStatusCode(), 200);
        } catch (Exception e) {
            logger.error("test failed", e);
            fail(e.getMessage());
        }
        c.close();
    }
View Full Code Here
TOP
Copyright © 2015 www.massapi.com. 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.