use of org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection in project jetty.project by eclipse.
the class WebSocketClientTest method testMessageBiggerThanBufferSize.
@Test
public void testMessageBiggerThanBufferSize() throws Exception {
int bufferSize = 512;
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection ssocket = server.accept();
ssocket.upgrade();
future.get(30, TimeUnit.SECONDS);
Assert.assertTrue(wsocket.openLatch.await(1, TimeUnit.SECONDS));
// 1.5 times buffer size
int length = bufferSize + (bufferSize / 2);
// FIN + TEXT
ssocket.write(0x80 | 0x01);
// No MASK and 2 bytes length
ssocket.write(0x7E);
// first length byte
ssocket.write(length >> 8);
// second length byte
ssocket.write(length & 0xFF);
for (int i = 0; i < length; ++i) {
ssocket.write('x');
}
ssocket.flush();
Assert.assertTrue(wsocket.dataLatch.await(1000, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection in project jetty.project by eclipse.
the class WebSocketClientTest method testBasicEcho_FromServer.
@Test
public void testBasicEcho_FromServer() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
Future<Session> future = client.connect(wsocket, server.getWsUri());
// Server
final IBlockheadServerConnection srvSock = server.accept();
srvSock.upgrade();
// Validate connect
Session sess = future.get(30, TimeUnit.SECONDS);
Assert.assertThat("Session", sess, notNullValue());
Assert.assertThat("Session.open", sess.isOpen(), is(true));
Assert.assertThat("Session.upgradeRequest", sess.getUpgradeRequest(), notNullValue());
Assert.assertThat("Session.upgradeResponse", sess.getUpgradeResponse(), notNullValue());
// Have server send initial message
srvSock.write(new TextFrame().setPayload("Hello World"));
// Verify connect
future.get(30, TimeUnit.SECONDS);
wsocket.assertWasOpened();
wsocket.awaitMessage(1, TimeUnit.SECONDS, 2);
wsocket.assertMessage("Hello World");
}
use of org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection in project jetty.project by eclipse.
the class ClientCloseTest method testReadEOF.
@Test
public void testReadEOF() throws Exception {
// Set client timeout
final int timeout = 1000;
client.setMaxIdleTimeout(timeout);
// Client connects
CloseTrackingSocket clientSocket = new CloseTrackingSocket();
Future<Session> clientConnectFuture = client.connect(clientSocket, server.getWsUri());
// Server accepts connect
IBlockheadServerConnection serverConn = server.accept();
serverConn.upgrade();
// client confirms connection via echo
confirmConnection(clientSocket, clientConnectFuture, serverConn);
// client sends close frame
final String origCloseReason = "Normal Close";
clientSocket.getSession().close(StatusCode.NORMAL, origCloseReason);
// server receives close frame
confirmServerReceivedCloseFrame(serverConn, StatusCode.NORMAL, is(origCloseReason));
// client should not have received close message (yet)
clientSocket.assertNoCloseEvent();
// server shuts down connection (no frame reply)
serverConn.disconnect();
// client reads -1 (EOF)
// client triggers close event on client ws-endpoint
clientSocket.assertReceivedCloseEvent(timeout, is(StatusCode.ABNORMAL), containsString("EOF"));
}
use of org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection in project jetty.project by eclipse.
the class ClientCloseTest method testServerNoCloseHandshake.
@Test
public void testServerNoCloseHandshake() throws Exception {
// Set client timeout
final int timeout = 1000;
client.setMaxIdleTimeout(timeout);
// Client connects
CloseTrackingSocket clientSocket = new CloseTrackingSocket();
Future<Session> clientConnectFuture = client.connect(clientSocket, server.getWsUri());
// Server accepts connect
IBlockheadServerConnection serverConn = server.accept();
serverConn.upgrade();
// client confirms connection via echo
confirmConnection(clientSocket, clientConnectFuture, serverConn);
// client sends close frame
final String origCloseReason = "Normal Close";
clientSocket.getSession().close(StatusCode.NORMAL, origCloseReason);
// server receives close frame
confirmServerReceivedCloseFrame(serverConn, StatusCode.NORMAL, is(origCloseReason));
// client should not have received close message (yet)
clientSocket.assertNoCloseEvent();
// server never sends close frame handshake
// server sits idle
// client idle timeout triggers close event on client ws-endpoint
assertThat("OnError Latch", clientSocket.errorLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat("OnError", clientSocket.error.get(), instanceOf(SocketTimeoutException.class));
assertThat("OnError", clientSocket.error.get().getMessage(), containsString("Timeout on Read"));
}
use of org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection in project jetty.project by eclipse.
the class ClientCloseTest method testWriteException.
@Test
public void testWriteException() throws Exception {
// Set client timeout
final int timeout = 1000;
client.setMaxIdleTimeout(timeout);
// Client connects
CloseTrackingSocket clientSocket = new CloseTrackingSocket();
Future<Session> clientConnectFuture = client.connect(clientSocket, server.getWsUri());
// Server accepts connect
IBlockheadServerConnection serverConn = server.accept();
serverConn.upgrade();
// client confirms connection via echo
confirmConnection(clientSocket, clientConnectFuture, serverConn);
// setup client endpoint for write failure (test only)
EndPoint endp = clientSocket.getEndPoint();
endp.shutdownOutput();
// client enqueue close frame
// client write failure
final String origCloseReason = "Normal Close";
clientSocket.getSession().close(StatusCode.NORMAL, origCloseReason);
assertThat("OnError Latch", clientSocket.errorLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat("OnError", clientSocket.error.get(), instanceOf(EofException.class));
// client triggers close event on client ws-endpoint
// assert - close code==1006 (abnormal)
// assert - close reason message contains (write failure)
clientSocket.assertReceivedCloseEvent(timeout, is(StatusCode.ABNORMAL), containsString("EOF"));
}
Aggregations