use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.
the class HttpClientTimeoutTest method testTimeoutOnQueuedRequest.
@Slow
@Test
public void testTimeoutOnQueuedRequest() throws Exception {
long timeout = 1000;
start(new TimeoutHandler(3 * timeout));
// Only one connection so requests get queued
client.setMaxConnectionsPerDestination(1);
// The first request has a long timeout
final CountDownLatch firstLatch = new CountDownLatch(1);
Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(4 * timeout, TimeUnit.MILLISECONDS);
request.send(new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
Assert.assertFalse(result.isFailed());
firstLatch.countDown();
}
});
// Second request has a short timeout and should fail in the queue
final CountDownLatch secondLatch = new CountDownLatch(1);
request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(timeout, TimeUnit.MILLISECONDS);
request.send(new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
Assert.assertTrue(result.isFailed());
secondLatch.countDown();
}
});
Assert.assertTrue(secondLatch.await(2 * timeout, TimeUnit.MILLISECONDS));
// The second request must fail before the first request has completed
Assert.assertTrue(firstLatch.getCount() > 0);
Assert.assertTrue(firstLatch.await(5 * timeout, TimeUnit.MILLISECONDS));
}
use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.
the class HttpSenderOverHTTPTest method test_Send_NoRequestContent_Exception.
@Test
public void test_Send_NoRequestContent_Exception() throws Exception {
ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
// Shutdown output to trigger the exception on write
endPoint.shutdownOutput();
HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
destination.start();
HttpConnectionOverHTTP connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<Connection>());
Request request = client.newRequest(URI.create("http://localhost/"));
final CountDownLatch failureLatch = new CountDownLatch(2);
request.listener(new Request.Listener.Adapter() {
@Override
public void onFailure(Request request, Throwable x) {
failureLatch.countDown();
}
});
connection.send(request, new Response.Listener.Adapter() {
@Override
public void onComplete(Result result) {
Assert.assertTrue(result.isFailed());
failureLatch.countDown();
}
});
Assert.assertTrue(failureLatch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.
the class HttpClientTimeoutTest method testTimeoutOnListenerWithExplicitConnection.
@Slow
@Test
public void testTimeoutOnListenerWithExplicitConnection() throws Exception {
long timeout = 1000;
start(new TimeoutHandler(2 * timeout));
final CountDownLatch latch = new CountDownLatch(1);
Destination destination = client.getDestination(scheme, "localhost", connector.getLocalPort());
FuturePromise<Connection> futureConnection = new FuturePromise<>();
destination.newConnection(futureConnection);
try (Connection connection = futureConnection.get(5, TimeUnit.SECONDS)) {
Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(timeout, TimeUnit.MILLISECONDS);
connection.send(request, new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
Assert.assertTrue(result.isFailed());
latch.countDown();
}
});
Assert.assertTrue(latch.await(3 * timeout, TimeUnit.MILLISECONDS));
}
}
use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.
the class HttpClientTimeoutTest method retryAfterConnectTimeout.
@Test
public void retryAfterConnectTimeout() throws Exception {
final String host = "10.255.255.1";
final int port = 80;
int connectTimeout = 1000;
assumeConnectTimeout(host, port, connectTimeout);
start(new EmptyServerHandler());
client.stop();
client.setConnectTimeout(connectTimeout);
client.start();
final CountDownLatch latch = new CountDownLatch(1);
Request request = client.newRequest(host, port);
request.scheme(scheme).send(new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
if (result.isFailed()) {
// Retry
client.newRequest(host, port).scheme(scheme).send(new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
if (result.isFailed())
latch.countDown();
}
});
}
}
});
Assert.assertTrue(latch.await(333 * connectTimeout, TimeUnit.MILLISECONDS));
Assert.assertNotNull(request.getAbortCause());
}
use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.
the class HttpClientTimeoutTest method testTimeoutOnListener.
@Slow
@Test
public void testTimeoutOnListener() throws Exception {
long timeout = 1000;
start(new TimeoutHandler(2 * timeout));
final CountDownLatch latch = new CountDownLatch(1);
Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(timeout, TimeUnit.MILLISECONDS);
request.send(new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
Assert.assertTrue(result.isFailed());
latch.countDown();
}
});
Assert.assertTrue(latch.await(3 * timeout, TimeUnit.MILLISECONDS));
}
Aggregations