use of org.eclipse.jetty.toolchain.test.annotation.Slow 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));
}
use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.
the class HttpClientTimeoutTest method testTimeoutIsCancelledOnSuccessWithExplicitConnection.
@Slow
@Test
public void testTimeoutIsCancelledOnSuccessWithExplicitConnection() throws Exception {
long timeout = 1000;
start(new TimeoutHandler(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(destination.getHost(), destination.getPort()).scheme(scheme).timeout(2 * timeout, TimeUnit.MILLISECONDS);
connection.send(request, new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
Response response = result.getResponse();
Assert.assertEquals(200, response.getStatus());
Assert.assertFalse(result.isFailed());
latch.countDown();
}
});
Assert.assertTrue(latch.await(3 * timeout, TimeUnit.MILLISECONDS));
TimeUnit.MILLISECONDS.sleep(2 * timeout);
Assert.assertNull(request.getAbortCause());
}
}
use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.
the class HttpConnectionLifecycleTest method test_BadRequest_WithSlowRequest_RemovesConnection.
@Slow
@Test
public void test_BadRequest_WithSlowRequest_RemovesConnection() throws Exception {
start(new EmptyServerHandler());
String host = "localhost";
int port = connector.getLocalPort();
HttpDestinationOverHTTP destination = (HttpDestinationOverHTTP) client.getDestination(scheme, host, port);
DuplexConnectionPool connectionPool = (DuplexConnectionPool) destination.getConnectionPool();
final Collection<Connection> idleConnections = connectionPool.getIdleConnections();
Assert.assertEquals(0, idleConnections.size());
final Collection<Connection> activeConnections = connectionPool.getActiveConnections();
Assert.assertEquals(0, activeConnections.size());
final long delay = 1000;
final CountDownLatch successLatch = new CountDownLatch(3);
client.newRequest(host, port).scheme(scheme).listener(new Request.Listener.Adapter() {
@Override
public void onBegin(Request request) {
// Remove the host header, this will make the request invalid
request.header(HttpHeader.HOST, null);
}
@Override
public void onHeaders(Request request) {
try {
TimeUnit.MILLISECONDS.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void onSuccess(Request request) {
successLatch.countDown();
}
}).send(new Response.Listener.Adapter() {
@Override
public void onSuccess(Response response) {
Assert.assertEquals(400, response.getStatus());
// 400 response also come with a Connection: close,
// so the connection is closed and removed
successLatch.countDown();
}
@Override
public void onComplete(Result result) {
Assert.assertFalse(result.isFailed());
successLatch.countDown();
}
});
Assert.assertTrue(successLatch.await(delay * 30, TimeUnit.MILLISECONDS));
Assert.assertEquals(0, idleConnections.size());
Assert.assertEquals(0, activeConnections.size());
}
use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.
the class ResourceHandlerTest method testSlowBiggest.
@Test
@Slow
public void testSlowBiggest() throws Exception {
_connector.setIdleTimeout(10000);
File dir = MavenTestingUtils.getTargetFile("test-classes/simple");
File biggest = new File(dir, "biggest.txt");
try (OutputStream out = new FileOutputStream(biggest)) {
for (int i = 0; i < 10; i++) {
try (InputStream in = new FileInputStream(new File(dir, "bigger.txt"))) {
IO.copy(in, out);
}
}
out.write("\nTHE END\n".getBytes(StandardCharsets.ISO_8859_1));
}
biggest.deleteOnExit();
try (Socket socket = new Socket("localhost", _connector.getLocalPort());
OutputStream out = socket.getOutputStream();
InputStream in = socket.getInputStream()) {
socket.getOutputStream().write("GET /resource/biggest.txt HTTP/1.0\n\n".getBytes());
byte[] array = new byte[102400];
ByteBuffer buffer = null;
while (true) {
Thread.sleep(100);
int len = in.read(array);
if (len < 0)
break;
buffer = BufferUtil.toBuffer(array, 0, len);
// System.err.println(++i+": "+BufferUtil.toDetailString(buffer));
}
Assert.assertEquals('E', buffer.get(buffer.limit() - 4));
Assert.assertEquals('N', buffer.get(buffer.limit() - 3));
Assert.assertEquals('D', buffer.get(buffer.limit() - 2));
}
}
use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.
the class SameNodeLoadTest method testLoad.
@Test
@Slow
public void testLoad() throws Exception {
DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory();
cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT);
SessionDataStoreFactory storeFactory = new TestSessionDataStoreFactory();
String contextPath = "";
String servletMapping = "/server";
TestServer server1 = new TestServer(0, -1, 4, cacheFactory, storeFactory);
server1.addContext(contextPath).addServlet(TestServlet.class, servletMapping);
try {
server1.start();
int port1 = server1.getPort();
HttpClient client = new HttpClient();
client.start();
try {
String url = "http://localhost:" + port1 + contextPath + servletMapping;
//create session via first server
ContentResponse response1 = client.GET(url + "?action=init");
assertEquals(HttpServletResponse.SC_OK, response1.getStatus());
String sessionCookie = response1.getHeaders().get("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
//simulate 10 clients making 100 requests each
ExecutorService executor = Executors.newCachedThreadPool();
int clientsCount = 10;
CyclicBarrier barrier = new CyclicBarrier(clientsCount + 1);
int requestsCount = 100;
Worker[] workers = new Worker[clientsCount];
for (int i = 0; i < clientsCount; ++i) {
workers[i] = new Worker(barrier, client, requestsCount, sessionCookie, url);
executor.execute(workers[i]);
}
// Wait for all workers to be ready
barrier.await();
long start = System.nanoTime();
// Wait for all workers to be done
barrier.await();
long end = System.nanoTime();
long elapsed = TimeUnit.NANOSECONDS.toMillis(end - start);
System.err.println("Elapsed ms:" + elapsed);
executor.shutdownNow();
// Perform one request to get the result
Request request = client.newRequest(url + "?action=result");
request.header("Cookie", sessionCookie);
ContentResponse response2 = request.send();
assertEquals(HttpServletResponse.SC_OK, response2.getStatus());
String response = response2.getContentAsString();
assertEquals(response.trim(), String.valueOf(clientsCount * requestsCount));
} finally {
client.stop();
}
} finally {
server1.stop();
}
}
Aggregations