Search in sources :

Example 31 with Request

use of org.asynchttpclient.Request in project async-http-client by AsyncHttpClient.

the class TimeToLiveIssue method testTTLBug.

@Test(enabled = false, description = "https://github.com/AsyncHttpClient/async-http-client/issues/1113")
public void testTTLBug() throws Throwable {
    try (AsyncHttpClient client = asyncHttpClient(config().setKeepAlive(true).setConnectionTtl(1).setPooledConnectionIdleTimeout(1))) {
        for (int i = 0; i < 200000; ++i) {
            Request request = new RequestBuilder().setUrl(String.format("http://localhost:%d/", port1)).build();
            Future<Response> future = client.executeRequest(request);
            future.get(5, TimeUnit.SECONDS);
            // from sometimes winning over poll for the ownership of a connection.
            if (System.currentTimeMillis() % 100 == 0) {
                Thread.sleep(5);
            }
        }
    }
}
Also used : Response(org.asynchttpclient.Response) RequestBuilder(org.asynchttpclient.RequestBuilder) Request(org.asynchttpclient.Request) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest) Test(org.testng.annotations.Test)

Example 32 with Request

use of org.asynchttpclient.Request in project async-http-client by AsyncHttpClient.

the class WebDavBasicTest method mkcolWebDavTest2.

@Test(groups = "standalone")
public void mkcolWebDavTest2() throws InterruptedException, IOException, ExecutionException {
    try (AsyncHttpClient c = asyncHttpClient()) {
        Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl() + "/folder2").build();
        Response response = c.executeRequest(mkcolRequest).get();
        assertEquals(response.getStatusCode(), 409);
    }
}
Also used : Response(org.asynchttpclient.Response) RequestBuilder(org.asynchttpclient.RequestBuilder) Request(org.asynchttpclient.Request) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 33 with Request

use of org.asynchttpclient.Request in project async-http-client by AsyncHttpClient.

the class WebDavBasicTest method basicPropFindWebDavTest.

@Test(groups = "standalone")
public void basicPropFindWebDavTest() throws InterruptedException, IOException, ExecutionException {
    try (AsyncHttpClient c = asyncHttpClient()) {
        Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(getTargetUrl()).build();
        Response response = c.executeRequest(propFindRequest).get();
        assertEquals(response.getStatusCode(), 404);
    }
}
Also used : Response(org.asynchttpclient.Response) RequestBuilder(org.asynchttpclient.RequestBuilder) Request(org.asynchttpclient.Request) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 34 with Request

use of org.asynchttpclient.Request in project async-http-client by AsyncHttpClient.

the class WebDavBasicTest method mkcolWebDavTest1.

@Test(groups = "standalone")
public void mkcolWebDavTest1() throws InterruptedException, IOException, ExecutionException {
    try (AsyncHttpClient c = asyncHttpClient()) {
        Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build();
        Response response = c.executeRequest(mkcolRequest).get();
        assertEquals(response.getStatusCode(), 201);
    }
}
Also used : Response(org.asynchttpclient.Response) RequestBuilder(org.asynchttpclient.RequestBuilder) Request(org.asynchttpclient.Request) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 35 with Request

use of org.asynchttpclient.Request in project async-http-client by AsyncHttpClient.

the class ResumableAsyncHandlerTest method testAdjustRange.

@Test
public void testAdjustRange() {
    MapResumableProcessor proc = new MapResumableProcessor();
    ResumableAsyncHandler handler = new ResumableAsyncHandler(proc);
    Request request = get("http://test/url").build();
    Request newRequest = handler.adjustRequestRange(request);
    assertEquals(newRequest.getUri(), request.getUri());
    String rangeHeader = newRequest.getHeaders().get(RANGE);
    assertNull(rangeHeader);
    proc.put("http://test/url", 5000);
    newRequest = handler.adjustRequestRange(request);
    assertEquals(newRequest.getUri(), request.getUri());
    rangeHeader = newRequest.getHeaders().get(RANGE);
    assertEquals(rangeHeader, "bytes=5000-");
}
Also used : Request(org.asynchttpclient.Request) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Request (org.asynchttpclient.Request)67 Test (org.testng.annotations.Test)32 Response (org.asynchttpclient.Response)31 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)18 RequestBuilder (org.asynchttpclient.RequestBuilder)17 Test (org.junit.Test)16 UnitEvent (org.apache.druid.java.util.emitter.service.UnitEvent)10 HttpRequest (io.netty.handler.codec.http.HttpRequest)8 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)8 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)7 DefaultAsyncHttpClientConfig (org.asynchttpclient.DefaultAsyncHttpClientConfig)6 ListenableFuture (org.asynchttpclient.ListenableFuture)6 Uri (org.asynchttpclient.uri.Uri)5 Realm (org.asynchttpclient.Realm)4 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)3 HttpResponse (io.netty.handler.codec.http.HttpResponse)3 HashMap (java.util.HashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3