Search in sources :

Example 36 with Slow

use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.

the class SlowServerTest method testServerSlowToRead.

@Test
@Slow
public void testServerSlowToRead() throws Exception {
    JettyTrackingSocket tsocket = new JettyTrackingSocket();
    client.setMasker(new ZeroMasker());
    client.setMaxIdleTimeout(60000);
    URI wsUri = server.getWsUri();
    Future<Session> future = client.connect(tsocket, wsUri);
    IBlockheadServerConnection sconnection = server.accept();
    sconnection.setSoTimeout(60000);
    sconnection.upgrade();
    // Confirm connected
    future.get(30, TimeUnit.SECONDS);
    tsocket.waitForConnected(30, TimeUnit.SECONDS);
    int messageCount = 10;
    // Setup slow server read thread
    ServerReadThread reader = new ServerReadThread(sconnection, messageCount);
    // slow it down
    reader.setSlowness(100);
    reader.start();
    // Have client write as quickly as it can.
    ClientWriteThread writer = new ClientWriteThread(tsocket.getSession());
    writer.setMessageCount(messageCount);
    writer.setMessage("Hello");
    // disable slowness
    writer.setSlowness(-1);
    writer.start();
    writer.join();
    // Verify receive
    reader.waitForExpectedMessageCount(10, TimeUnit.SECONDS);
    Assert.assertThat("Frame Receive Count", reader.getFrameCount(), is(messageCount));
    // Close
    tsocket.getSession().close(StatusCode.NORMAL, "Done");
    Assert.assertTrue("Client Socket Closed", tsocket.closeLatch.await(10, TimeUnit.SECONDS));
    tsocket.assertCloseCode(StatusCode.NORMAL);
    // stop reading
    reader.cancel();
}
Also used : IBlockheadServerConnection(org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection) ZeroMasker(org.eclipse.jetty.websocket.client.masks.ZeroMasker) URI(java.net.URI) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 37 with Slow

use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.

the class SlowServerTest method testServerSlowToSend.

@Test
@Slow
public void testServerSlowToSend() throws Exception {
    JettyTrackingSocket clientSocket = new JettyTrackingSocket();
    client.setMasker(new ZeroMasker());
    client.setMaxIdleTimeout(60000);
    URI wsUri = server.getWsUri();
    Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
    IBlockheadServerConnection serverConn = server.accept();
    serverConn.setSoTimeout(60000);
    serverConn.upgrade();
    // Confirm connected
    clientConnectFuture.get(30, TimeUnit.SECONDS);
    clientSocket.waitForConnected(30, TimeUnit.SECONDS);
    // Have server write slowly.
    int messageCount = 1000;
    ServerWriteThread writer = new ServerWriteThread(serverConn);
    writer.setMessageCount(messageCount);
    writer.setMessage("Hello");
    writer.setSlowness(10);
    writer.start();
    writer.join();
    // Verify receive
    Assert.assertThat("Message Receive Count", clientSocket.messageQueue.size(), is(messageCount));
    // Close
    serverConn.close(StatusCode.NORMAL);
    Assert.assertTrue("Client Socket Closed", clientSocket.closeLatch.await(10, TimeUnit.SECONDS));
    clientSocket.assertCloseCode(StatusCode.NORMAL);
}
Also used : IBlockheadServerConnection(org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection) ZeroMasker(org.eclipse.jetty.websocket.client.masks.ZeroMasker) URI(java.net.URI) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Aggregations

Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)37 Test (org.junit.Test)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)18 CountDownLatch (java.util.concurrent.CountDownLatch)17 HttpServletResponse (javax.servlet.http.HttpServletResponse)16 IOException (java.io.IOException)11 Result (org.eclipse.jetty.client.api.Result)11 ServletException (javax.servlet.ServletException)10 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)10 Request (org.eclipse.jetty.client.api.Request)9 Socket (java.net.Socket)7 OutputStream (java.io.OutputStream)6 ArrayList (java.util.ArrayList)6 Response (org.eclipse.jetty.client.api.Response)6 Connection (org.eclipse.jetty.client.api.Connection)5 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)5 BufferingResponseListener (org.eclipse.jetty.client.util.BufferingResponseListener)5 Request (org.eclipse.jetty.server.Request)5 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)5 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)5