Issue #207 - testcase rework due to new async behaviors

# Conflicts:
#	jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/ConnectionManager.java
#	jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RegexMatcher.java
This commit is contained in:
Joakim Erdfelt 2017-04-11 15:46:47 -07:00
parent 3888cd5347
commit fcb8693c52
82 changed files with 2688 additions and 1575 deletions

View File

@ -42,7 +42,7 @@ import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
@ -113,11 +113,11 @@ public class DecoderReaderManySmallTest
private static class EventIdServer implements Runnable private static class EventIdServer implements Runnable
{ {
private BlockheadServer server; private XBlockheadServer server;
private IBlockheadServerConnection sconnection; private IBlockheadServerConnection sconnection;
private CountDownLatch connectLatch = new CountDownLatch(1); private CountDownLatch connectLatch = new CountDownLatch(1);
public EventIdServer(BlockheadServer server) public EventIdServer(XBlockheadServer server)
{ {
this.server = server; this.server = server;
} }
@ -167,7 +167,7 @@ public class DecoderReaderManySmallTest
@Rule @Rule
public TestTracker tt = new TestTracker(); public TestTracker tt = new TestTracker();
private BlockheadServer server; private XBlockheadServer server;
private WebSocketContainer client; private WebSocketContainer client;
@Before @Before
@ -185,7 +185,7 @@ public class DecoderReaderManySmallTest
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -50,7 +50,7 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.ContinuationFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
@ -155,11 +155,11 @@ public class DecoderReaderTest
private static class QuoteServer implements Runnable private static class QuoteServer implements Runnable
{ {
private BlockheadServer server; private XBlockheadServer server;
private IBlockheadServerConnection sconnection; private IBlockheadServerConnection sconnection;
private CountDownLatch connectLatch = new CountDownLatch(1); private CountDownLatch connectLatch = new CountDownLatch(1);
public QuoteServer(BlockheadServer server) public QuoteServer(XBlockheadServer server)
{ {
this.server = server; this.server = server;
} }
@ -231,7 +231,7 @@ public class DecoderReaderTest
@Rule @Rule
public TestTracker tt = new TestTracker(); public TestTracker tt = new TestTracker();
private BlockheadServer server; private XBlockheadServer server;
private WebSocketContainer client; private WebSocketContainer client;
@Before @Before
@ -249,7 +249,7 @@ public class DecoderReaderTest
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -45,7 +45,7 @@ import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.test.BlockheadServer; import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
@ -58,11 +58,11 @@ public class EncoderTest
private static class EchoServer implements Runnable private static class EchoServer implements Runnable
{ {
private Thread thread; private Thread thread;
private BlockheadServer server; private XBlockheadServer server;
private IBlockheadServerConnection sconnection; private IBlockheadServerConnection sconnection;
private CountDownLatch connectLatch = new CountDownLatch(1); private CountDownLatch connectLatch = new CountDownLatch(1);
public EchoServer(BlockheadServer server) public EchoServer(XBlockheadServer server)
{ {
this.server = server; this.server = server;
} }
@ -193,7 +193,7 @@ public class EncoderTest
@Rule @Rule
public TestTracker tt = new TestTracker(); public TestTracker tt = new TestTracker();
private BlockheadServer server; private XBlockheadServer server;
private WebSocketContainer client; private WebSocketContainer client;
@ -248,7 +248,7 @@ public class EncoderTest
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -98,7 +98,7 @@ public class MisbehavingClassTest
server.addBean(container); // allow to shutdown with server server.addBean(container); // allow to shutdown with server
EndpointRuntimeOnOpen socket = new EndpointRuntimeOnOpen(); EndpointRuntimeOnOpen socket = new EndpointRuntimeOnOpen();
try (StacklessLogging logging = new StacklessLogging(EndpointRuntimeOnOpen.class, WebSocketSession.class)) try (StacklessLogging ignored = new StacklessLogging(EndpointRuntimeOnOpen.class, WebSocketSession.class))
{ {
// expecting IOException during onOpen // expecting IOException during onOpen
expectedException.expect(IOException.class); expectedException.expect(IOException.class);
@ -121,7 +121,7 @@ public class MisbehavingClassTest
server.addBean(container); // allow to shutdown with server server.addBean(container); // allow to shutdown with server
AnnotatedRuntimeOnOpen socket = new AnnotatedRuntimeOnOpen(); AnnotatedRuntimeOnOpen socket = new AnnotatedRuntimeOnOpen();
try (StacklessLogging logging = new StacklessLogging(AnnotatedRuntimeOnOpen.class, WebSocketSession.class)) try (StacklessLogging ignored = new StacklessLogging(AnnotatedRuntimeOnOpen.class, WebSocketSession.class))
{ {
// expecting IOException during onOpen // expecting IOException during onOpen
expectedException.expect(IOException.class); expectedException.expect(IOException.class);

View File

@ -60,7 +60,7 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.util.QuoteUtil; import org.eclipse.jetty.websocket.api.util.QuoteUtil;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.common.test.HttpResponse;
import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
@ -413,7 +413,7 @@ public class ConfiguratorTest
{ {
URI uri = baseServerUri.resolve("/empty"); URI uri = baseServerUri.resolve("/empty");
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.addExtensions("identity"); client.addExtensions("identity");
client.connect(); client.connect();
@ -428,7 +428,7 @@ public class ConfiguratorTest
{ {
URI uri = baseServerUri.resolve("/no-extensions"); URI uri = baseServerUri.resolve("/no-extensions");
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.addExtensions("identity"); client.addExtensions("identity");
client.connect(); client.connect();
@ -448,7 +448,7 @@ public class ConfiguratorTest
{ {
URI uri = baseServerUri.resolve("/capture-request-headers"); URI uri = baseServerUri.resolve("/capture-request-headers");
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.addHeader("X-Dummy: Bogus\r\n"); client.addHeader("X-Dummy: Bogus\r\n");
client.connect(); client.connect();
@ -468,7 +468,7 @@ public class ConfiguratorTest
URI uri = baseServerUri.resolve("/unique-user-props"); URI uri = baseServerUri.resolve("/unique-user-props");
// First request // First request
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -481,7 +481,7 @@ public class ConfiguratorTest
} }
// Second request // Second request
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -505,7 +505,7 @@ public class ConfiguratorTest
URI uri = baseServerUri.resolve("/addr"); URI uri = baseServerUri.resolve("/addr");
// First request // First request
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -540,7 +540,7 @@ public class ConfiguratorTest
URI uri = baseServerUri.resolve("/protocols"); URI uri = baseServerUri.resolve("/protocols");
ProtocolsConfigurator.seenProtocols.set(null); ProtocolsConfigurator.seenProtocols.set(null);
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.addHeader("Sec-WebSocket-Protocol: echo\r\n"); client.addHeader("Sec-WebSocket-Protocol: echo\r\n");
client.connect(); client.connect();
@ -564,7 +564,7 @@ public class ConfiguratorTest
URI uri = baseServerUri.resolve("/protocols"); URI uri = baseServerUri.resolve("/protocols");
ProtocolsConfigurator.seenProtocols.set(null); ProtocolsConfigurator.seenProtocols.set(null);
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.addHeader("Sec-WebSocket-Protocol: echo, chat, status\r\n"); client.addHeader("Sec-WebSocket-Protocol: echo, chat, status\r\n");
client.connect(); client.connect();
@ -588,7 +588,7 @@ public class ConfiguratorTest
URI uri = baseServerUri.resolve("/protocols"); URI uri = baseServerUri.resolve("/protocols");
ProtocolsConfigurator.seenProtocols.set(null); ProtocolsConfigurator.seenProtocols.set(null);
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.addHeader("sec-websocket-protocol: echo, chat, status\r\n"); client.addHeader("sec-websocket-protocol: echo, chat, status\r\n");
client.connect(); client.connect();
@ -612,7 +612,7 @@ public class ConfiguratorTest
URI uri = baseServerUri.resolve("/protocols"); URI uri = baseServerUri.resolve("/protocols");
ProtocolsConfigurator.seenProtocols.set(null); ProtocolsConfigurator.seenProtocols.set(null);
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.addHeader("Sec-Websocket-Protocol: echo, chat, status\r\n"); client.addHeader("Sec-Websocket-Protocol: echo, chat, status\r\n");
client.connect(); client.connect();
@ -634,7 +634,7 @@ public class ConfiguratorTest
{ {
URI uri = baseServerUri.resolve("/timedecoder"); URI uri = baseServerUri.resolve("/timedecoder");
try (BlockheadClient client = new BlockheadClient(uri)) try (XBlockheadClient client = new XBlockheadClient(uri))
{ {
client.addHeader("Sec-Websocket-Protocol: gmt\r\n"); client.addHeader("Sec-Websocket-Protocol: gmt\r\n");
client.connect(); client.connect();

View File

@ -19,6 +19,7 @@
<module>websocket-client</module> <module>websocket-client</module>
<module>websocket-server</module> <module>websocket-server</module>
<module>websocket-servlet</module> <module>websocket-servlet</module>
<module>websocket-tests</module>
<module>javax-websocket-client-impl</module> <module>javax-websocket-client-impl</module>
<module>javax-websocket-server-impl</module> <module>javax-websocket-server-impl</module>
</modules> </modules>

View File

@ -47,7 +47,6 @@ import org.eclipse.jetty.websocket.api.WebSocketBehavior;
import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory; import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory;
import org.eclipse.jetty.websocket.client.io.ConnectionManager;
import org.eclipse.jetty.websocket.client.io.UpgradeListener; import org.eclipse.jetty.websocket.client.io.UpgradeListener;
import org.eclipse.jetty.websocket.client.masks.Masker; import org.eclipse.jetty.websocket.client.masks.Masker;
import org.eclipse.jetty.websocket.client.masks.RandomMasker; import org.eclipse.jetty.websocket.client.masks.RandomMasker;
@ -494,12 +493,6 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont
return httpClient.getByteBufferPool(); return httpClient.getByteBufferPool();
} }
@Deprecated
public ConnectionManager getConnectionManager()
{
throw new UnsupportedOperationException("ConnectionManager is no longer supported");
}
public long getConnectTimeout() public long getConnectTimeout()
{ {
return httpClient.getConnectTimeout(); return httpClient.getConnectTimeout();
@ -626,18 +619,6 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont
} }
} }
/**
* Factory method for new ConnectionManager
*
* @return the ConnectionManager instance to use
* @deprecated use HttpClient instead
*/
@Deprecated
protected ConnectionManager newConnectionManager()
{
throw new UnsupportedOperationException("ConnectionManager is no longer supported");
}
@Override @Override
public void onSessionClosed(WebSocketSession session) public void onSessionClosed(WebSocketSession session)
{ {

View File

@ -1,172 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.client.io;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Locale;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.websocket.client.WebSocketClient;
/**
* Deprecated ConnectionManager
* @deprecated use {@link HttpClient} with WebSocketClient directly
*/
@Deprecated
public class ConnectionManager extends ContainerLifeCycle
{
private class PhysicalConnect extends ConnectPromise
{
private SocketAddress bindAddress;
public PhysicalConnect(WebSocketClient client, ClientUpgradeRequest request, Object websocket)
{
super(client,request,websocket);
this.bindAddress = client.getBindAddress();
}
@Override
public void run()
{
SocketChannel channel = null;
try
{
channel = SocketChannel.open();
if (bindAddress != null)
{
channel.bind(bindAddress);
}
URI wsUri = getRequest().getRequestURI();
channel.socket().setTcpNoDelay(true); // disable nagle
channel.configureBlocking(false); // async always
InetSocketAddress address = toSocketAddress(wsUri);
if (channel.connect(address))
{
getSelector().accept(channel, this);
}
else
{
getSelector().connect(channel, this);
}
}
catch (Throwable t)
{
// close the socket channel
if (channel != null)
{
try
{
channel.close();
}
catch (IOException ignore)
{
LOG.ignore(ignore);
}
}
// notify the future
failed(t);
}
}
}
private static final Logger LOG = Log.getLogger(ConnectionManager.class);
public static InetSocketAddress toSocketAddress(URI uri)
{
if (!uri.isAbsolute())
{
throw new IllegalArgumentException("Cannot get InetSocketAddress of non-absolute URIs");
}
int port = uri.getPort();
String scheme = uri.getScheme().toLowerCase(Locale.ENGLISH);
if ("ws".equals(scheme))
{
if (port == (-1))
{
port = 80;
}
}
else if ("wss".equals(scheme))
{
if (port == (-1))
{
port = 443;
}
}
else
{
throw new IllegalArgumentException("Only support ws:// and wss:// URIs");
}
return new InetSocketAddress(uri.getHost(),port);
}
public ConnectionManager(WebSocketClient client)
{
this.client = client;
}
public ConnectPromise connect(WebSocketClient client, ClientUpgradeRequest request, Object websocket)
{
return new PhysicalConnect(client,request,websocket);
}
@Override
protected void doStart() throws Exception
{
selector = newWebSocketClientSelectorManager(client);
selector.setSslContextFactory(client.getSslContextFactory());
selector.setConnectTimeout(client.getConnectTimeout());
addBean(selector);
super.doStart();
}
@Override
protected void doStop() throws Exception
{
super.doStop();
removeBean(selector);
}
public WebSocketClientSelectorManager getSelector()
{
return selector;
}
/**
* Factory method for new WebSocketClientSelectorManager (used by other projects like cometd)
*
* @param client
* the client used to create the WebSocketClientSelectorManager
* @return the new WebSocketClientSelectorManager
*/
protected WebSocketClientSelectorManager newWebSocketClientSelectorManager(WebSocketClient client)
{
return new WebSocketClientSelectorManager(client);
}
}

View File

@ -27,9 +27,9 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule;
import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -46,7 +46,7 @@ public class BadNetworkTest
@Rule @Rule
public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test");
private BlockheadServer server; private XBlockheadServer server;
private WebSocketClient client; private WebSocketClient client;
@Before @Before
@ -60,7 +60,7 @@ public class BadNetworkTest
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -67,10 +67,10 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection; import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.eclipse.jetty.websocket.common.test.IncomingFramesCapture; import org.eclipse.jetty.websocket.common.test.IncomingFramesCapture;
import org.eclipse.jetty.websocket.common.test.RawFrameBuilder; import org.eclipse.jetty.websocket.common.test.RawFrameBuilder;
import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -188,7 +188,7 @@ public class ClientCloseTest
@Rule @Rule
public TestTracker tt = new TestTracker(); public TestTracker tt = new TestTracker();
private BlockheadServer server; private XBlockheadServer server;
private WebSocketClient client; private WebSocketClient client;
private void confirmConnection(CloseTrackingSocket clientSocket, Future<Session> clientFuture, IBlockheadServerConnection serverConns) throws Exception private void confirmConnection(CloseTrackingSocket clientSocket, Future<Session> clientFuture, IBlockheadServerConnection serverConns) throws Exception
@ -301,7 +301,7 @@ public class ClientCloseTest
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }
@ -442,7 +442,7 @@ public class ClientCloseTest
bad.putShort((short)StatusCode.NORMAL); bad.putShort((short)StatusCode.NORMAL);
bad.put(msg); bad.put(msg);
BufferUtil.flipToFlush(bad,0); BufferUtil.flipToFlush(bad,0);
try (StacklessLogging quiet = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class))
{ {
serverConn.write(bad); serverConn.write(bad);
@ -480,7 +480,7 @@ public class ClientCloseTest
// client confirms connection via echo // client confirms connection via echo
confirmConnection(clientSocket,clientConnectFuture,serverConn); confirmConnection(clientSocket,clientConnectFuture,serverConn);
try(StacklessLogging scope = new StacklessLogging(CloseTrackingSocket.class)) try(StacklessLogging ignored = new StacklessLogging(CloseTrackingSocket.class))
{ {
// client sends close frame // client sends close frame
final String origCloseReason = "Normal Close"; final String origCloseReason = "Normal Close";

View File

@ -41,10 +41,9 @@ import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.UpgradeException; import org.eclipse.jetty.websocket.api.UpgradeException;
import org.eclipse.jetty.websocket.common.AcceptHash; import org.eclipse.jetty.websocket.common.AcceptHash;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule;
import org.hamcrest.Matcher; import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -64,7 +63,7 @@ public class ClientConnectTest
public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test");
private final int timeout = 500; private final int timeout = 500;
private BlockheadServer server; private XBlockheadServer server;
private WebSocketClient client; private WebSocketClient client;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -110,7 +109,7 @@ public class ClientConnectTest
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -1,82 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.client;
import static org.hamcrest.Matchers.is;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.websocket.client.io.ConnectionManager;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
public class ConnectionManagerTest
{
@Rule
public TestTracker tt = new TestTracker();
private void assertToSocketAddress(String uriStr, String expectedHost, int expectedPort) throws URISyntaxException
{
URI uri = new URI(uriStr);
InetSocketAddress addr = ConnectionManager.toSocketAddress(uri);
Assert.assertThat("URI (" + uri + ").host",addr.getHostName(),is(expectedHost));
Assert.assertThat("URI (" + uri + ").port",addr.getPort(),is(expectedPort));
}
@Test
public void testToSocketAddress_AltWsPort() throws Exception
{
assertToSocketAddress("ws://localhost:8099","localhost",8099);
}
@Test
public void testToSocketAddress_AltWssPort() throws Exception
{
assertToSocketAddress("wss://localhost","localhost",443);
}
@Test
public void testToSocketAddress_DefaultWsPort() throws Exception
{
assertToSocketAddress("ws://localhost","localhost",80);
}
@Test
public void testToSocketAddress_DefaultWsPort_Path() throws Exception
{
assertToSocketAddress("ws://localhost/sockets/chat","localhost",80);
}
@Test
public void testToSocketAddress_DefaultWssPort() throws Exception
{
assertToSocketAddress("wss://localhost:9443","localhost",9443);
}
@Test
public void testToSocketAddress_DefaultWssPort_Path() throws Exception
{
assertToSocketAddress("wss://localhost/sockets/chat","localhost",443);
}
}

View File

@ -40,8 +40,8 @@ import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketAdapter; import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.util.QuoteUtil; import org.eclipse.jetty.websocket.api.util.QuoteUtil;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -85,7 +85,7 @@ public class CookieTest
} }
private WebSocketClient client; private WebSocketClient client;
private BlockheadServer server; private XBlockheadServer server;
@Before @Before
public void startClient() throws Exception public void startClient() throws Exception
@ -97,7 +97,7 @@ public class CookieTest
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.websocket.client; package org.eclipse.jetty.websocket.client;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.is;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;

View File

@ -31,8 +31,8 @@ import org.eclipse.jetty.websocket.api.BatchMode;
import org.eclipse.jetty.websocket.api.RemoteEndpoint; import org.eclipse.jetty.websocket.api.RemoteEndpoint;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -40,12 +40,12 @@ import org.junit.Test;
public class SessionTest public class SessionTest
{ {
private BlockheadServer server; private XBlockheadServer server;
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.websocket.client; package org.eclipse.jetty.websocket.client;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.is;
import java.net.URI; import java.net.URI;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -28,8 +28,8 @@ import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -41,7 +41,7 @@ public class SlowClientTest
@Rule @Rule
public TestTracker tt = new TestTracker(); public TestTracker tt = new TestTracker();
private BlockheadServer server; private XBlockheadServer server;
private WebSocketClient client; private WebSocketClient client;
@Before @Before
@ -55,7 +55,7 @@ public class SlowClientTest
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -29,8 +29,8 @@ import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.client.masks.ZeroMasker; import org.eclipse.jetty.websocket.client.masks.ZeroMasker;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -44,7 +44,7 @@ public class SlowServerTest
@Rule @Rule
public TestTracker tt = new TestTracker(); public TestTracker tt = new TestTracker();
private BlockheadServer server; private XBlockheadServer server;
private WebSocketClient client; private WebSocketClient client;
@Before @Before
@ -58,7 +58,7 @@ public class SlowServerTest
@Before @Before
public void startServer() throws Exception public void startServer() throws Exception
{ {
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -27,8 +27,8 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter; import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -71,7 +71,7 @@ public class TomcatServerQuirksTest
@Test @Test
public void testTomcat7_0_32_WithTransferEncoding() throws Exception public void testTomcat7_0_32_WithTransferEncoding() throws Exception
{ {
BlockheadServer server = new BlockheadServer(); XBlockheadServer server = new XBlockheadServer();
WebSocketClient client = new WebSocketClient(); WebSocketClient client = new WebSocketClient();
try try

View File

@ -41,8 +41,8 @@ import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.io.FutureWriteCallback; import org.eclipse.jetty.websocket.common.io.FutureWriteCallback;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection; import org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection;
import org.eclipse.jetty.websocket.common.test.XBlockheadServer;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -52,7 +52,7 @@ import org.junit.runner.RunWith;
@RunWith(AdvancedRunner.class) @RunWith(AdvancedRunner.class)
public class WebSocketClientTest public class WebSocketClientTest
{ {
private BlockheadServer server; private XBlockheadServer server;
private WebSocketClient client; private WebSocketClient client;
@Before @Before
@ -60,7 +60,7 @@ public class WebSocketClientTest
{ {
client = new WebSocketClient(); client = new WebSocketClient();
client.start(); client.start();
server = new BlockheadServer(); server = new XBlockheadServer();
server.start(); server.start();
} }

View File

@ -212,15 +212,15 @@ public class Generator
public ByteBuffer generateHeaderBytes(Frame frame) public ByteBuffer generateHeaderBytes(Frame frame)
{ {
ByteBuffer buffer = bufferPool.acquire(MAX_HEADER_LENGTH,true); ByteBuffer buffer = bufferPool.acquire(MAX_HEADER_LENGTH,false);
int p = BufferUtil.flipToFill(buffer);
generateHeaderBytes(frame,buffer); generateHeaderBytes(frame,buffer);
BufferUtil.flipToFlush(buffer,p);
return buffer; return buffer;
} }
public void generateHeaderBytes(Frame frame, ByteBuffer buffer) public void generateHeaderBytes(Frame frame, ByteBuffer buffer)
{ {
int p = BufferUtil.flipToFill(buffer);
// we need a framing header // we need a framing header
assertFrameValid(frame); assertFrameValid(frame);
@ -337,8 +337,6 @@ public class Generator
} }
} }
} }
BufferUtil.flipToFlush(buffer,p);
} }
/** /**

View File

@ -269,6 +269,8 @@ public class Parser
{ {
case START: case START:
{ {
payload = null;
// peek at byte // peek at byte
byte b = buffer.get(); byte b = buffer.get();
boolean fin = ((b & 0x80) != 0); boolean fin = ((b & 0x80) != 0);
@ -579,31 +581,22 @@ public class Parser
maskProcessor.process(window); maskProcessor.process(window);
if (window.remaining() == payloadLength) if (payload == null)
{ {
// We have the whole content, no need to copy. payload = bufferPool.acquire(payloadLength,false);
frame.setPayload(window); BufferUtil.clearToFill(payload);
return true;
} }
else
// Copy the payload.
payload.put(window);
// if the payload is complete
if (payload.position() == payloadLength)
{ {
if (payload == null) BufferUtil.flipToFlush(payload, 0);
{ frame.setPayload(payload);
payload = bufferPool.acquire(payloadLength,false); // notify that frame is complete
BufferUtil.clearToFill(payload); return true;
}
// Copy the payload.
payload.put(window);
// if the payload is complete
if (payload.position() == payloadLength)
{
BufferUtil.flipToFlush(payload, 0);
frame.setPayload(payload);
// notify that frame is complete
return true;
}
} }
} }
// frame not (yet) complete // frame not (yet) complete

View File

@ -34,7 +34,7 @@ public class WebSocketSessionFactory implements SessionFactory
public WebSocketSessionFactory(WebSocketContainerScope containerScope) public WebSocketSessionFactory(WebSocketContainerScope containerScope)
{ {
this.containerScope = containerScope; this.containerScope = containerScope;
} }
@Override @Override
public boolean supports(Object websocket) public boolean supports(Object websocket)

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.websocket.common.io; package org.eclipse.jetty.websocket.common.io;
import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
@ -171,8 +170,8 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
} }
private static final Logger LOG = Log.getLogger(AbstractWebSocketConnection.class); private static final Logger LOG = Log.getLogger(AbstractWebSocketConnection.class);
private static final Logger LOG_OPEN = Log.getLogger(AbstractWebSocketConnection.class.getName() + "_OPEN"); private static final Logger LOG_OPEN = Log.getLogger(AbstractWebSocketConnection.class.getName() + ".OPEN");
private static final Logger LOG_CLOSE = Log.getLogger(AbstractWebSocketConnection.class.getName() + "_CLOSE"); private static final Logger LOG_CLOSE = Log.getLogger(AbstractWebSocketConnection.class.getName() + ".CLOSE");
/** /**
* Minimum size of a buffer is the determined to be what would be the maximum framing header size (not including payload) * Minimum size of a buffer is the determined to be what would be the maximum framing header size (not including payload)
@ -518,7 +517,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
if (filled < 0) if (filled < 0)
{ {
bufferPool.release(networkBuffer); bufferPool.release(networkBuffer);
notifyError(new EOFException("Read EOF")); // notifyError(new EOFException("Read EOF"));
return; return;
} }

View File

@ -64,7 +64,7 @@ public class BlockheadClientConstructionTest
public void testURIs() throws URISyntaxException public void testURIs() throws URISyntaxException
{ {
@SuppressWarnings("resource") @SuppressWarnings("resource")
BlockheadClient client = new BlockheadClient(expectedWsUri); XBlockheadClient client = new XBlockheadClient(expectedWsUri);
Assert.assertThat("Websocket URI",client.getWebsocketURI(),is(expectedWsUri)); Assert.assertThat("Websocket URI",client.getWebsocketURI(),is(expectedWsUri));
Assert.assertThat("Websocket URI",client.getHttpURI(),is(expectedHttpUri)); Assert.assertThat("Websocket URI",client.getHttpURI(),is(expectedHttpUri));
} }

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.websocket.common.test; package org.eclipse.jetty.websocket.common.test;
import static org.eclipse.jetty.websocket.common.test.RegexMatcher.matchesPattern; import static org.eclipse.jetty.toolchain.test.matchers.RegexMatcher.matchesPattern;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.util.Iterator; import java.util.Iterator;

View File

@ -1,66 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.common.test;
import java.util.regex.Pattern;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.TypeSafeMatcher;
public class RegexMatcher extends TypeSafeMatcher
{
private final Pattern pattern;
public RegexMatcher(String pattern)
{
this(Pattern.compile(pattern));
}
public RegexMatcher(Pattern pattern)
{
this.pattern = pattern;
}
@Override
public void describeTo(Description description)
{
description.appendText("matches regular expression ").appendValue(pattern);
}
@Override
protected boolean matchesSafely(Object item)
{
if(item == null) return false;
return pattern.matcher(item.toString()).matches();
}
@Factory
public static RegexMatcher matchesPattern(Pattern pattern)
{
return new RegexMatcher(pattern);
}
@Factory
public static RegexMatcher matchesPattern(String pattern)
{
return new RegexMatcher(pattern);
}
}

View File

@ -50,7 +50,7 @@ public class UnitParser extends Parser
@Deprecated @Deprecated
public void parseQuietly(ByteBuffer buf) public void parseQuietly(ByteBuffer buf)
{ {
try (StacklessLogging suppress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class))
{ {
parse(buf); parse(buf);
} }

View File

@ -88,7 +88,7 @@ import org.junit.Assert;
* with regards to basic IO behavior, a write should work as expected, a read should work as expected, but <u>what</u> byte it sends or reads is not within its * with regards to basic IO behavior, a write should work as expected, a read should work as expected, but <u>what</u> byte it sends or reads is not within its
* scope. * scope.
*/ */
public class BlockheadClient implements OutgoingFrames, ConnectionStateListener, AutoCloseable, IBlockheadClient, Parser.Handler public class XBlockheadClient implements OutgoingFrames, ConnectionStateListener, AutoCloseable, IBlockheadClient, Parser.Handler
{ {
private class FrameReadingThread extends Thread implements Runnable, IncomingFrames private class FrameReadingThread extends Thread implements Runnable, IncomingFrames
{ {
@ -172,7 +172,7 @@ public class BlockheadClient implements OutgoingFrames, ConnectionStateListener,
private static final String REQUEST_HASH_KEY = "dGhlIHNhbXBsZSBub25jZQ=="; private static final String REQUEST_HASH_KEY = "dGhlIHNhbXBsZSBub25jZQ==";
private static final int BUFFER_SIZE = 64 * 1024; private static final int BUFFER_SIZE = 64 * 1024;
private static final Logger LOG = Log.getLogger(BlockheadClient.class); private static final Logger LOG = Log.getLogger(XBlockheadClient.class);
private final URI destHttpURI; private final URI destHttpURI;
private final URI destWebsocketURI; private final URI destWebsocketURI;
private final ByteBufferPool bufferPool; private final ByteBufferPool bufferPool;
@ -201,12 +201,12 @@ public class BlockheadClient implements OutgoingFrames, ConnectionStateListener,
private String connectionValue = "Upgrade"; private String connectionValue = "Upgrade";
public BlockheadClient(URI destWebsocketURI) throws URISyntaxException public XBlockheadClient(URI destWebsocketURI) throws URISyntaxException
{ {
this(WebSocketPolicy.newClientPolicy(),destWebsocketURI); this(WebSocketPolicy.newClientPolicy(),destWebsocketURI);
} }
public BlockheadClient(WebSocketPolicy policy, URI destWebsocketURI) throws URISyntaxException public XBlockheadClient(WebSocketPolicy policy, URI destWebsocketURI) throws URISyntaxException
{ {
Assert.assertThat("Websocket URI scheme",destWebsocketURI.getScheme(),anyOf(is("ws"),is("wss"))); Assert.assertThat("Websocket URI scheme",destWebsocketURI.getScheme(),anyOf(is("ws"),is("wss")));
this.destWebsocketURI = destWebsocketURI; this.destWebsocketURI = destWebsocketURI;

View File

@ -36,9 +36,9 @@ import org.junit.Assert;
* <p> * <p>
* This is not meant to be performant or accurate. In fact, having the server misbehave is a useful trait during testing. * This is not meant to be performant or accurate. In fact, having the server misbehave is a useful trait during testing.
*/ */
public class BlockheadServer public class XBlockheadServer
{ {
private static final Logger LOG = Log.getLogger(BlockheadServer.class); private static final Logger LOG = Log.getLogger(XBlockheadServer.class);
private ServerSocket serverSocket; private ServerSocket serverSocket;
private URI wsUri; private URI wsUri;
@ -47,7 +47,7 @@ public class BlockheadServer
LOG.debug(".accept()"); LOG.debug(".accept()");
assertIsStarted(); assertIsStarted();
Socket socket = serverSocket.accept(); Socket socket = serverSocket.accept();
return new BlockheadServerConnection(socket); return new XBlockheadServerConnection(socket);
} }
private void assertIsStarted() private void assertIsStarted()

View File

@ -66,9 +66,9 @@ import org.eclipse.jetty.websocket.common.frames.CloseFrame;
import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope; import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope;
import org.junit.Assert; import org.junit.Assert;
public class BlockheadServerConnection implements IncomingFrames, OutgoingFrames, Runnable, IBlockheadServerConnection public class XBlockheadServerConnection implements IncomingFrames, OutgoingFrames, Runnable, IBlockheadServerConnection
{ {
private static final Logger LOG = Log.getLogger(BlockheadServerConnection.class); private static final Logger LOG = Log.getLogger(XBlockheadServerConnection.class);
private final int BUFFER_SIZE = 8192; private final int BUFFER_SIZE = 8192;
private final Socket socket; private final Socket socket;
@ -91,7 +91,7 @@ public class BlockheadServerConnection implements IncomingFrames, OutgoingFrames
private OutgoingFrames outgoing = this; private OutgoingFrames outgoing = this;
private ExtensionStack extensionStack; private ExtensionStack extensionStack;
public BlockheadServerConnection(Socket socket) public XBlockheadServerConnection(Socket socket)
{ {
this.socket = socket; this.socket = socket;
this.incomingFrames = new IncomingFramesCapture(); this.incomingFrames = new IncomingFramesCapture();

View File

@ -45,7 +45,7 @@ import org.junit.Assert;
/** /**
* Fuzzing utility for the AB tests. * Fuzzing utility for the AB tests.
*/ */
public class Fuzzer implements AutoCloseable public class XFuzzer implements AutoCloseable
{ {
public static enum CloseState public static enum CloseState
{ {
@ -72,19 +72,19 @@ public class Fuzzer implements AutoCloseable
private static final int KBYTE = 1024; private static final int KBYTE = 1024;
private static final int MBYTE = KBYTE * KBYTE; private static final int MBYTE = KBYTE * KBYTE;
private static final Logger LOG = Log.getLogger(Fuzzer.class); private static final Logger LOG = Log.getLogger(XFuzzer.class);
// Client side framing mask // Client side framing mask
protected static final byte[] MASK = protected static final byte[] MASK =
{ 0x11, 0x22, 0x33, 0x44 }; { 0x11, 0x22, 0x33, 0x44 };
private final BlockheadClient client; private final XBlockheadClient client;
private final Generator generator; private final Generator generator;
private final String testname; private final String testname;
private SendMode sendMode = SendMode.BULK; private SendMode sendMode = SendMode.BULK;
private int slowSendSegmentSize = 5; private int slowSendSegmentSize = 5;
public Fuzzer(Fuzzed testcase) throws Exception public XFuzzer(Fuzzed testcase) throws Exception
{ {
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy(); WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
@ -94,7 +94,7 @@ public class Fuzzer implements AutoCloseable
policy.setMaxBinaryMessageSize(bigMessageSize); policy.setMaxBinaryMessageSize(bigMessageSize);
policy.setIdleTimeout(5000); policy.setIdleTimeout(5000);
this.client = new BlockheadClient(policy,testcase.getServerURI()); this.client = new XBlockheadClient(policy,testcase.getServerURI());
this.client.setTimeout(2,TimeUnit.SECONDS); this.client.setTimeout(2,TimeUnit.SECONDS);
this.generator = testcase.getLaxGenerator(); this.generator = testcase.getLaxGenerator();
this.testname = testcase.getTestMethodName(); this.testname = testcase.getTestMethodName();

View File

@ -37,7 +37,7 @@ import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser; import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.server.examples.echo.BigEchoSocket; import org.eclipse.jetty.websocket.server.examples.echo.BigEchoSocket;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -92,7 +92,7 @@ public class AnnotatedMaxMessageSizeTest
@Test @Test
public void testEchoGood() throws IOException, Exception public void testEchoGood() throws IOException, Exception
{ {
BlockheadClient client = new BlockheadClient(serverUri); XBlockheadClient client = new XBlockheadClient(serverUri);
try try
{ {
client.setProtocols("echo"); client.setProtocols("echo");
@ -118,8 +118,8 @@ public class AnnotatedMaxMessageSizeTest
@Test(timeout=8000) @Test(timeout=8000)
public void testEchoTooBig() throws IOException, Exception public void testEchoTooBig() throws IOException, Exception
{ {
BlockheadClient client = new BlockheadClient(serverUri); XBlockheadClient client = new XBlockheadClient(serverUri);
try(StacklessLogging logging = new StacklessLogging(Parser.class)) try(StacklessLogging ignored = new StacklessLogging(Parser.class))
{ {
client.setProtocols("echo"); client.setProtocols("echo");
client.connect(); client.connect();

View File

@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.common.test.HttpResponse;
import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -58,7 +58,7 @@ public class ChromeTest
Assume.assumeTrue("Server has x-webkit-deflate-frame registered", Assume.assumeTrue("Server has x-webkit-deflate-frame registered",
server.getWebSocketServletFactory().getExtensionFactory().isAvailable("x-webkit-deflate-frame")); server.getWebSocketServletFactory().getExtensionFactory().isAvailable("x-webkit-deflate-frame"));
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
try try
{ {
client.addExtensions("x-webkit-deflate-frame"); client.addExtensions("x-webkit-deflate-frame");

View File

@ -35,7 +35,7 @@ import org.eclipse.jetty.util.Decorator;
import org.eclipse.jetty.websocket.api.WebSocketAdapter; import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator; import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
@ -154,7 +154,7 @@ public class DecoratorsLegacyTest
@Test @Test
public void testAccessRequestCookies() throws Exception public void testAccessRequestCookies() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try try

View File

@ -35,7 +35,7 @@ import org.eclipse.jetty.util.Decorator;
import org.eclipse.jetty.websocket.api.WebSocketAdapter; import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator; import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
@ -154,7 +154,7 @@ public class DecoratorsTest
@Test @Test
public void testAccessRequestCookies() throws Exception public void testAccessRequestCookies() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try try

View File

@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient;
import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -53,7 +53,7 @@ public class FirefoxTest
@Test @Test
public void testConnectionKeepAlive() throws Exception public void testConnectionKeepAlive() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
// Odd Connection Header value seen in Firefox // Odd Connection Header value seen in Firefox
client.setConnectionValue("keep-alive, Upgrade"); client.setConnectionValue("keep-alive, Upgrade");

View File

@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.common.test.HttpResponse;
import org.eclipse.jetty.websocket.server.helper.EchoServlet; import org.eclipse.jetty.websocket.server.helper.EchoServlet;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -70,7 +70,7 @@ public class FragmentExtensionTest
{ {
int fragSize = 4; int fragSize = 4;
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
client.clearExtensions(); client.clearExtensions();
client.addExtensions("fragment;maxLength=" + fragSize); client.addExtensions("fragment;maxLength=" + fragSize);
client.setProtocols("onConnect"); client.setProtocols("onConnect");

View File

@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.common.test.HttpResponse;
import org.eclipse.jetty.websocket.server.helper.EchoServlet; import org.eclipse.jetty.websocket.server.helper.EchoServlet;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -54,7 +54,7 @@ public class IdentityExtensionTest
@Test(timeout = 10000) @Test(timeout = 10000)
public void testIdentityExtension() throws Exception public void testIdentityExtension() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
client.clearExtensions(); client.clearExtensions();
client.addExtensions("identity;param=0"); client.addExtensions("identity;param=0");
client.addExtensions("identity;param=1, identity ; param = '2' ; other = ' some = value '"); client.addExtensions("identity;param=1, identity ; param = '2' ; other = ' some = value '");

View File

@ -30,7 +30,7 @@ import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.server.helper.RFCSocket; import org.eclipse.jetty.websocket.server.helper.RFCSocket;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
@ -78,7 +78,7 @@ public class IdleTimeoutTest
@Test @Test
public void testIdleTimeout() throws Exception public void testIdleTimeout() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
client.setProtocols("onConnect"); client.setProtocols("onConnect");
client.setTimeout(2500,TimeUnit.MILLISECONDS); client.setTimeout(2500,TimeUnit.MILLISECONDS);
try try

View File

@ -41,7 +41,7 @@ import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient;
import org.eclipse.jetty.websocket.server.helper.RFCSocket; import org.eclipse.jetty.websocket.server.helper.RFCSocket;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
@ -261,7 +261,7 @@ public class ManyConnectionsCleanupTest
sessLog.setLevel(oldLevel); sessLog.setLevel(oldLevel);
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("container"); client.setProtocols("container");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
@ -301,11 +301,11 @@ public class ManyConnectionsCleanupTest
private void fastClose() throws Exception private void fastClose() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("fastclose"); client.setProtocols("fastclose");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -328,11 +328,11 @@ public class ManyConnectionsCleanupTest
private void fastFail() throws Exception private void fastFail() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("fastfail"); client.setProtocols("fastfail");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -353,11 +353,11 @@ public class ManyConnectionsCleanupTest
private void dropConnection() throws Exception private void dropConnection() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("container"); client.setProtocols("container");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();

View File

@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.server.helper.EchoSocket; import org.eclipse.jetty.websocket.server.helper.EchoSocket;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
@ -106,7 +106,7 @@ public class RequestHeadersTest
@Test @Test
public void testAccessRequestCookies() throws Exception public void testAccessRequestCookies() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try try

View File

@ -30,7 +30,7 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket; import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator; import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
@ -119,7 +119,7 @@ public class SubProtocolTest
private void testSubProtocol(String requestProtocols, String acceptedSubProtocols) throws Exception private void testSubProtocol(String requestProtocols, String acceptedSubProtocols) throws Exception
{ {
try (BlockheadClient client = new BlockheadClient(server.getServerUri())) try (XBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setTimeout(1, TimeUnit.SECONDS); client.setTimeout(1, TimeUnit.SECONDS);

View File

@ -32,7 +32,7 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket; import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator; import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
@ -117,7 +117,7 @@ public class SuspendResumeTest
@Test @Test
public void testSuspendResume() throws Exception public void testSuspendResume() throws Exception
{ {
try (BlockheadClient client = new BlockheadClient(server.getServerUri())) try (XBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setTimeout(1, TimeUnit.SECONDS); client.setTimeout(1, TimeUnit.SECONDS);

View File

@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.Generator; import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule;
import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -69,7 +69,7 @@ public class TooFastClientTest
@Ignore("RELEASE") @Ignore("RELEASE")
public void testUpgradeWithSmallFrames() throws Exception public void testUpgradeWithSmallFrames() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
try try
{ {
client.connect(); client.connect();
@ -132,7 +132,7 @@ public class TooFastClientTest
@Ignore("RELEASE") @Ignore("RELEASE")
public void testUpgradeWithLargeFrame() throws Exception public void testUpgradeWithLargeFrame() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
try try
{ {
client.connect(); client.connect();

View File

@ -40,7 +40,7 @@ import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient;
import org.eclipse.jetty.websocket.server.helper.RFCSocket; import org.eclipse.jetty.websocket.server.helper.RFCSocket;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
@ -222,7 +222,7 @@ public class WebSocketCloseTest
@Test @Test
public void testFastClose() throws Exception public void testFastClose() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("fastclose"); client.setProtocols("fastclose");
client.setTimeout(5,TimeUnit.SECONDS); client.setTimeout(5,TimeUnit.SECONDS);
@ -255,11 +255,11 @@ public class WebSocketCloseTest
@Test @Test
public void testFastFail() throws Exception public void testFastFail() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("fastfail"); client.setProtocols("fastfail");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(CloseServlet.class)) try (StacklessLogging ignored = new StacklessLogging(CloseServlet.class))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -294,7 +294,7 @@ public class WebSocketCloseTest
fastClose(); fastClose();
dropConnection(); dropConnection();
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("container"); client.setProtocols("container");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
@ -329,11 +329,11 @@ public class WebSocketCloseTest
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
private void fastClose() throws Exception private void fastClose() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("fastclose"); client.setProtocols("fastclose");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -356,11 +356,11 @@ public class WebSocketCloseTest
private void fastFail() throws Exception private void fastFail() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("fastfail"); client.setProtocols("fastfail");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -382,11 +382,11 @@ public class WebSocketCloseTest
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
private void dropConnection() throws Exception private void dropConnection() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) try (IBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("container"); client.setProtocols("container");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) try (StacklessLogging ignored = new StacklessLogging(WebSocketSession.class))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();

View File

@ -21,7 +21,7 @@ package org.eclipse.jetty.websocket.server;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.HttpResponse; import org.eclipse.jetty.websocket.common.test.HttpResponse;
import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -54,7 +54,7 @@ public class WebSocketInvalidVersionTest
public void testRequestVersion29() throws Exception public void testRequestVersion29() throws Exception
{ {
@SuppressWarnings("resource") @SuppressWarnings("resource")
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
client.setVersion(29); // intentionally bad version client.setVersion(29); // intentionally bad version
try try
{ {

View File

@ -27,7 +27,7 @@ import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient;
import org.eclipse.jetty.websocket.server.helper.SessionServlet; import org.eclipse.jetty.websocket.server.helper.SessionServlet;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -61,7 +61,7 @@ public class WebSocketServerSessionTest
public void testDisconnect() throws Exception public void testDisconnect() throws Exception
{ {
URI uri = server.getServerUri().resolve("/test/disconnect"); URI uri = server.getServerUri().resolve("/test/disconnect");
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -77,7 +77,7 @@ public class WebSocketServerSessionTest
public void testUpgradeRequestResponse() throws Exception public void testUpgradeRequestResponse() throws Exception
{ {
URI uri = server.getServerUri().resolve("/test?snack=cashews&amount=handful&brand=off"); URI uri = server.getServerUri().resolve("/test?snack=cashews&amount=handful&brand=off");
try (IBlockheadClient client = new BlockheadClient(uri)) try (IBlockheadClient client = new XBlockheadClient(uri))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();

View File

@ -40,7 +40,7 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.BinaryFrame; import org.eclipse.jetty.websocket.common.frames.BinaryFrame;
import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.ContinuationFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.UnitGenerator; import org.eclipse.jetty.websocket.common.test.UnitGenerator;
import org.eclipse.jetty.websocket.common.util.Hex; import org.eclipse.jetty.websocket.common.util.Hex;
import org.eclipse.jetty.websocket.server.helper.RFCServlet; import org.eclipse.jetty.websocket.server.helper.RFCServlet;
@ -93,7 +93,7 @@ public class WebSocketServletRFCTest
@Test @Test
public void testBinaryAggregate() throws Exception public void testBinaryAggregate() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
try try
{ {
client.connect(); client.connect();
@ -179,7 +179,7 @@ public class WebSocketServletRFCTest
@Test @Test
public void testEcho() throws Exception public void testEcho() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
try try
{ {
client.connect(); client.connect();
@ -209,7 +209,7 @@ public class WebSocketServletRFCTest
@Test @Test
public void testInternalError() throws Exception public void testInternalError() throws Exception
{ {
try (BlockheadClient client = new BlockheadClient(server.getServerUri()); try (XBlockheadClient client = new XBlockheadClient(server.getServerUri());
StacklessLogging stackless=new StacklessLogging(RFCSocket.class)) StacklessLogging stackless=new StacklessLogging(RFCSocket.class))
{ {
client.connect(); client.connect();
@ -236,7 +236,7 @@ public class WebSocketServletRFCTest
@Test @Test
public void testLowercaseUpgrade() throws Exception public void testLowercaseUpgrade() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
try try
{ {
client.connect(); client.connect();
@ -274,7 +274,7 @@ public class WebSocketServletRFCTest
public void testTextNotUTF8() throws Exception public void testTextNotUTF8() throws Exception
{ {
try (StacklessLogging stackless=new StacklessLogging(Parser.class); try (StacklessLogging stackless=new StacklessLogging(Parser.class);
BlockheadClient client = new BlockheadClient(server.getServerUri())) XBlockheadClient client = new XBlockheadClient(server.getServerUri()))
{ {
client.setProtocols("other"); client.setProtocols("other");
client.connect(); client.connect();
@ -307,7 +307,7 @@ public class WebSocketServletRFCTest
@Test @Test
public void testUppercaseUpgrade() throws Exception public void testUppercaseUpgrade() throws Exception
{ {
BlockheadClient client = new BlockheadClient(server.getServerUri()); XBlockheadClient client = new XBlockheadClient(server.getServerUri());
try try
{ {
client.connect(); client.connect();

View File

@ -41,7 +41,7 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator; import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -304,7 +304,7 @@ public class WebSocketUpgradeFilterTest
{ {
URI destUri = serverUri.resolve("/info/"); URI destUri = serverUri.resolve("/info/");
try (BlockheadClient client = new BlockheadClient(destUri)) try (XBlockheadClient client = new XBlockheadClient(destUri))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -326,7 +326,7 @@ public class WebSocketUpgradeFilterTest
{ {
URI destUri = serverUri.resolve("/info/"); URI destUri = serverUri.resolve("/info/");
try (BlockheadClient client = new BlockheadClient(destUri)) try (XBlockheadClient client = new XBlockheadClient(destUri))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();
@ -345,7 +345,7 @@ public class WebSocketUpgradeFilterTest
server.getHandler().stop(); server.getHandler().stop();
server.getHandler().start(); server.getHandler().start();
try (BlockheadClient client = new BlockheadClient(destUri)) try (XBlockheadClient client = new XBlockheadClient(destUri))
{ {
client.connect(); client.connect();
client.sendStandardRequest(); client.sendStandardRequest();

View File

@ -1,150 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.server.ab;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer;
import org.eclipse.jetty.websocket.common.util.Hex;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* Tests of Known Good UTF8 sequences.
* <p>
* Should be preserved / echoed back, with normal close code.
*/
@RunWith(Parameterized.class)
public class TestABCase6_GoodUTF extends AbstractABCase
{
private static final Logger LOG = Log.getLogger(TestABCase6_GoodUTF.class);
@Parameters(name = "{0} - {1}")
public static Collection<String[]> data()
{
// The various Good UTF8 sequences as a String (hex form)
List<String[]> data = new ArrayList<>();
// @formatter:off
// - combination of simple 1 byte characters and unicode code points
data.add(new String[]{ "6.2.1", "48656C6C6F2DC2B540C39FC3B6C3A4C3BCC3A0C3A12D5554462D382121" });
// - simple valid UTF8 sequence
data.add(new String[]{ "6.5.1", "CEBAE1BDB9CF83CEBCCEB5" });
// - multi-byte code points
data.add(new String[]{ "6.6.11", "CEBAE1BDB9CF83CEBCCEB5" });
data.add(new String[]{ "6.6.2", "CEBA" });
data.add(new String[]{ "6.6.5", "CEBAE1BDB9" });
data.add(new String[]{ "6.6.7", "CEBAE1BDB9CF83" });
data.add(new String[]{ "6.6.9", "CEBAE1BDB9CF83CEBC" });
// - first possible sequence of a certain length (1 code point)
data.add(new String[]{ "6.7.1", "00" });
data.add(new String[]{ "6.7.2", "C280" });
data.add(new String[]{ "6.7.3", "E0A080" });
data.add(new String[]{ "6.7.4", "F0908080" });
// - last possible sequence of a certain length (1 code point)
data.add(new String[]{ "6.9.1", "7F" });
data.add(new String[]{ "6.9.2", "DFBF" });
data.add(new String[]{ "6.9.3", "EFBFBF" });
data.add(new String[]{ "6.9.4", "F48FBFBF" });
// - other boundary conditions
data.add(new String[]{ "6.11.1", "ED9FBF" });
data.add(new String[]{ "6.11.2", "EE8080" });
data.add(new String[]{ "6.11.3", "EFBFBD" });
data.add(new String[]{ "6.11.4", "F48FBFBF" });
// - non character code points
data.add(new String[]{ "6.22.1", "EFBFBE" });
data.add(new String[]{ "6.22.2", "EFBFBF" });
data.add(new String[]{ "6.22.3", "F09FBFBE" });
data.add(new String[]{ "6.22.4", "F09FBFBF" });
data.add(new String[]{ "6.22.5", "F0AFBFBE" });
data.add(new String[]{ "6.22.6", "F0AFBFBF" });
data.add(new String[]{ "6.22.7", "F0BFBFBE" });
data.add(new String[]{ "6.22.8", "F0BFBFBF" });
data.add(new String[]{ "6.22.9", "F18FBFBE" });
data.add(new String[]{ "6.22.10", "F18FBFBF" });
data.add(new String[]{ "6.22.11", "F19FBFBE" });
data.add(new String[]{ "6.22.12", "F19FBFBF" });
data.add(new String[]{ "6.22.13", "F1AFBFBE" });
data.add(new String[]{ "6.22.14", "F1AFBFBF" });
data.add(new String[]{ "6.22.15", "F1BFBFBE" });
data.add(new String[]{ "6.22.16", "F1BFBFBF" });
data.add(new String[]{ "6.22.17", "F28FBFBE" });
data.add(new String[]{ "6.22.18", "F28FBFBF" });
data.add(new String[]{ "6.22.19", "F29FBFBE" });
data.add(new String[]{ "6.22.20", "F29FBFBF" });
data.add(new String[]{ "6.22.21", "F2AFBFBE" });
data.add(new String[]{ "6.22.22", "F2AFBFBF" });
data.add(new String[]{ "6.22.23", "F2BFBFBE" });
data.add(new String[]{ "6.22.24", "F2BFBFBF" });
data.add(new String[]{ "6.22.25", "F38FBFBE" });
data.add(new String[]{ "6.22.26", "F38FBFBF" });
data.add(new String[]{ "6.22.27", "F39FBFBE" });
data.add(new String[]{ "6.22.28", "F39FBFBF" });
data.add(new String[]{ "6.22.29", "F3AFBFBE" });
data.add(new String[]{ "6.22.30", "F3AFBFBF" });
data.add(new String[]{ "6.22.31", "F3BFBFBE" });
data.add(new String[]{ "6.22.32", "F3BFBFBF" });
data.add(new String[]{ "6.22.33", "F48FBFBE" });
data.add(new String[]{ "6.22.34", "F48FBFBF" });
// - unicode replacement character
data.add(new String[]{ "6.23.1", "EFBFBD" });
// @formatter:on
return data;
}
private final ByteBuffer msg;
public TestABCase6_GoodUTF(String testId, String hexMsg)
{
LOG.debug("Test ID: {}",testId);
this.msg = Hex.asByteBuffer(hexMsg);
}
@Test
public void assertEchoTextMessage() throws Exception
{
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(msg));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame().setPayload(clone(msg)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this))
{
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
}

View File

@ -30,7 +30,7 @@ import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo; import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.test.BlockheadClient; import org.eclipse.jetty.websocket.common.test.XBlockheadClient;
import org.eclipse.jetty.websocket.common.test.IBlockheadClient; import org.eclipse.jetty.websocket.common.test.IBlockheadClient;
import org.eclipse.jetty.websocket.server.SimpleServletServer; import org.eclipse.jetty.websocket.server.SimpleServletServer;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -63,8 +63,8 @@ public class MisbehavingClassTest
@Test @Test
public void testListenerRuntimeOnConnect() throws Exception public void testListenerRuntimeOnConnect() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri()); try (IBlockheadClient client = new XBlockheadClient(server.getServerUri());
StacklessLogging scope = new StacklessLogging(ListenerRuntimeOnConnectSocket.class)) StacklessLogging ignored = new StacklessLogging(ListenerRuntimeOnConnectSocket.class))
{ {
client.setProtocols("listener-runtime-connect"); client.setProtocols("listener-runtime-connect");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);
@ -97,8 +97,8 @@ public class MisbehavingClassTest
@Test @Test
public void testAnnotatedRuntimeOnConnect() throws Exception public void testAnnotatedRuntimeOnConnect() throws Exception
{ {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri()); try (IBlockheadClient client = new XBlockheadClient(server.getServerUri());
StacklessLogging scope = new StacklessLogging(AnnotatedRuntimeOnConnectSocket.class)) StacklessLogging ignored = new StacklessLogging(AnnotatedRuntimeOnConnectSocket.class))
{ {
client.setProtocols("annotated-runtime-connect"); client.setProtocols("annotated-runtime-connect");
client.setTimeout(1,TimeUnit.SECONDS); client.setTimeout(1,TimeUnit.SECONDS);

View File

@ -25,5 +25,5 @@ org.eclipse.jetty.websocket.server.browser.LEVEL=DEBUG
org.eclipse.jetty.websocket.server.helper.RFCSocket.LEVEL=OFF org.eclipse.jetty.websocket.server.helper.RFCSocket.LEVEL=OFF
### Hiding Stack Traces from various test cases ### Hiding Stack Traces from various test cases
org.eclipse.jetty.websocket.server.ab.ABSocket.STACKS=OFF org.eclipse.jetty.websocket.tests.server.ABSocket.STACKS=OFF
org.eclipse.jetty.websocket.server.WebSocketCloseTest$FastFailSocket.STACKS=OFF org.eclipse.jetty.websocket.server.WebSocketCloseTest$FastFailSocket.STACKS=OFF

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-parent</artifactId>
<version>9.4.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>websocket-tests</artifactId>
<name>Jetty :: Websocket :: Tests</name>
<properties>
<bundle-symbolic-name>${project.groupId}.tests</bundle-symbolic-name>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>ban-java-servlet-api</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<includes>
<include>javax.servlet</include>
<include>servletapi</include>
<include>org.eclipse.jetty.orbit:javax.servlet</include>
<include>org.mortbay.jetty:servlet-api</include>
<include>jetty:servlet-api</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,44 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import org.eclipse.jetty.websocket.common.io.IOState;
public enum CloseState
{
OPEN,
REMOTE_INITIATED,
LOCAL_INITIATED;
public static CloseState from(IOState ios)
{
if (ios.wasLocalCloseInitiated())
{
return CloseState.LOCAL_INITIATED;
}
else if (ios.wasRemoteCloseInitiated())
{
return CloseState.REMOTE_INITIATED;
}
else
{
return CloseState.OPEN;
}
}
}

View File

@ -0,0 +1,32 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import java.net.URI;
import org.eclipse.jetty.websocket.common.Generator;
public interface Fuzzed
{
URI getServerURI();
Generator getLaxGenerator();
String getTestMethodName();
}

View File

@ -0,0 +1,368 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import static org.eclipse.jetty.websocket.tests.Fuzzer.SendMode.BULK;
import static org.eclipse.jetty.websocket.tests.Fuzzer.SendMode.PER_FRAME;
import static org.eclipse.jetty.websocket.tests.Fuzzer.SendMode.SLOW;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.ByteBufferAssert;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
/**
* Fuzzing utility for the AB tests.
*/
public class Fuzzer extends ContainerLifeCycle
{
public static class Session implements AutoCloseable
{
// Client side framing mask
private static final byte[] MASK = {0x11, 0x22, 0x33, 0x44};
private final Fuzzed testcase;
private final UntrustedWSSession session;
private final Generator generator;
private SendMode sendMode = SendMode.BULK;
private int slowSendSegmentSize = 5;
private boolean ignoreBrokenPipe = false;
public Session(Fuzzed testcase, UntrustedWSSession session)
{
this.testcase = testcase;
this.session = session;
this.generator = testcase.getLaxGenerator();
}
@Override
public void close() throws Exception
{
session.close();
}
public Session slowMode(int slowSendSegmentSize)
{
this.sendMode = SLOW;
this.slowSendSegmentSize = slowSendSegmentSize;
return this;
}
public Session bulkMode()
{
this.sendMode = BULK;
return this;
}
public Session perFrameMode()
{
this.sendMode = PER_FRAME;
return this;
}
public Session ignoreBrokenPipe()
{
this.ignoreBrokenPipe = true;
return this;
}
private void assertIsOpen()
{
assertThat("Session exists", session, notNullValue());
assertThat("Session is open", session.isOpen(), is(true));
}
public ByteBuffer asNetworkBuffer(List<WebSocketFrame> send)
{
int buflen = 0;
for (Frame f : send)
{
buflen += f.getPayloadLength() + Generator.MAX_HEADER_LENGTH;
}
ByteBuffer buf = session.getBufferPool().acquire(buflen, false);
BufferUtil.clearToFill(buf);
// Generate frames
for (WebSocketFrame f : send)
{
setClientMask(f);
generator.generateWholeFrame(f, buf);
}
buf.flip();
return buf;
}
private void setClientMask(WebSocketFrame f)
{
if (LOG.isDebugEnabled())
{
f.setMask(new byte[]
{0x00, 0x00, 0x00, 0x00});
}
else
{
f.setMask(MASK); // make sure we have mask set
}
}
public void expect(List<WebSocketFrame> expect) throws Exception
{
expect(expect, 10, TimeUnit.SECONDS);
}
public void expect(List<WebSocketFrame> expect, int duration, TimeUnit unit) throws Exception
{
int expectedCount = expect.size();
LOG.debug("expect() {} frame(s)", expect.size());
// Read frames
Future<List<WebSocketFrame>> futFrames = session.getUntrustedEndpoint().expectedFrames(expectedCount);
List<WebSocketFrame> frames = futFrames.get(duration, unit);
String prefix = "";
for (int i = 0; i < expectedCount; i++)
{
WebSocketFrame expected = expect.get(i);
WebSocketFrame actual = frames.get(i);
prefix = "Frame[" + i + "]";
LOG.debug("{} {}", prefix, actual);
assertThat(prefix + ".opcode", OpCode.name(actual.getOpCode()), is(OpCode.name(expected.getOpCode())));
prefix += "/" + actual.getOpCode();
if (expected.getOpCode() == OpCode.CLOSE)
{
CloseInfo expectedClose = new CloseInfo(expected);
CloseInfo actualClose = new CloseInfo(actual);
assertThat(prefix + ".statusCode", actualClose.getStatusCode(), is(expectedClose.getStatusCode()));
}
else
{
assertThat(prefix + ".payloadLength", actual.getPayloadLength(), is(expected.getPayloadLength()));
ByteBufferAssert.assertEquals(prefix + ".payload", expected.getPayload(), actual.getPayload());
}
}
}
public void expect(WebSocketFrame expect) throws Exception
{
expect(Collections.singletonList(expect));
}
public Session send(WebSocketFrame send) throws IOException
{
send(Collections.singletonList(send));
return this;
}
public Session send(ByteBuffer buf) throws IOException
{
assertIsOpen();
LOG.debug("Sending bytes {}", BufferUtil.toDetailString(buf));
if (sendMode == SLOW)
{
session.getUntrustedConnection().writeRawSlowly(buf, slowSendSegmentSize);
}
else
{
session.getUntrustedConnection().writeRaw(buf);
}
return this;
}
public Session send(ByteBuffer buf, int numBytes) throws IOException
{
session.getUntrustedConnection().writeRaw(buf, numBytes);
return this;
}
public Session send(List<WebSocketFrame> send) throws IOException
{
assertIsOpen();
LOG.debug("[{}] Sending {} frames (mode {})", testcase.getTestMethodName(), send.size(), sendMode);
try
{
if ((sendMode == SendMode.BULK) || (sendMode == SLOW))
{
int bufferLen = 0;
for (Frame f : send)
{
bufferLen += f.getPayloadLength() + Generator.MAX_HEADER_LENGTH;
}
ByteBuffer buffer = null;
try
{
buffer = session.getBufferPool().acquire(bufferLen, false);
BufferUtil.clearToFill(buffer);
// Generate frames
for (WebSocketFrame f : send)
{
setClientMask(f);
generator.generateHeaderBytes(f, buffer);
if (f.hasPayload())
{
buffer.put(f.getPayload());
}
}
BufferUtil.flipToFlush(buffer, 0);
// Write Data Frame
switch (sendMode)
{
case BULK:
session.getUntrustedConnection().writeRaw(buffer);
break;
case SLOW:
session.getUntrustedConnection().writeRawSlowly(buffer, slowSendSegmentSize);
break;
default:
throw new RuntimeException("Whoops, unsupported sendMode: " + sendMode);
}
}
finally
{
session.getBufferPool().release(buffer);
}
}
else if (sendMode == SendMode.PER_FRAME)
{
for (WebSocketFrame f : send)
{
f.setMask(MASK); // make sure we have mask set
// Using lax generator, generate and send
ByteBuffer buffer = null;
try
{
buffer = session.getBufferPool().acquire(f.getPayloadLength() + Generator.MAX_HEADER_LENGTH, false);
BufferUtil.clearToFill(buffer);
generator.generateWholeFrame(f, buffer);
BufferUtil.flipToFlush(buffer, 0);
session.getUntrustedConnection().writeRaw(buffer);
}
finally
{
session.getBufferPool().release(buffer);
}
}
}
}
catch (SocketException e)
{
if (ignoreBrokenPipe)
{
// Potential for SocketException (Broken Pipe) here.
// But not in 100% of testing scenarios. It is a safe
// exception to ignore in this testing scenario, as the
// slow writing of the frames can result in the server
// throwing a PROTOCOL ERROR termination/close when it
// encounters the bad continuation frame above (this
// termination is the expected behavior), and this
// early socket close can propagate back to the client
// before it has a chance to finish writing out the
// remaining frame octets
assertThat("Allowed to be a broken pipe", e.getMessage().toLowerCase(Locale.ENGLISH), containsString("broken pipe"));
}
else
{
throw e;
}
}
return this;
}
}
public enum SendMode
{
BULK,
PER_FRAME,
SLOW
}
public enum DisconnectMode
{
/** Disconnect occurred after a proper close handshake */
CLEAN,
/** Disconnect occurred in a harsh manner, without a close handshake */
UNCLEAN
}
private static final int KBYTE = 1024;
private static final int MBYTE = KBYTE * KBYTE;
private static final Logger LOG = Log.getLogger(Fuzzer.class);
private final UntrustedWSClient client;
private long connectTimeout = 2;
private TimeUnit connectTimeoutUnit = TimeUnit.SECONDS;
public Fuzzer() throws Exception
{
this.client = new UntrustedWSClient();
int bigMessageSize = 20 * MBYTE;
this.client.getPolicy().setMaxTextMessageSize(bigMessageSize);
this.client.getPolicy().setMaxBinaryMessageSize(bigMessageSize);
this.client.getPolicy().setIdleTimeout(5000);
this.client.setMaxIdleTimeout(TimeUnit.SECONDS.toMillis(2));
addBean(this.client);
}
public UntrustedWSClient getWSClient()
{
return this.client;
}
public Fuzzer.Session connect(Fuzzed testcase) throws Exception
{
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
upgradeRequest.setHeader("X-TestCase", testcase.getTestMethodName());
UntrustedWSSession session = client.connect(testcase.getServerURI(), upgradeRequest).get(connectTimeout, connectTimeoutUnit);
return new Fuzzer.Session(testcase, session);
}
}

View File

@ -0,0 +1,61 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import org.eclipse.jetty.io.LeakTrackingByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
public class LeakTrackingBufferPoolRule extends LeakTrackingByteBufferPool implements TestRule
{
private final String id;
public LeakTrackingBufferPoolRule(String id)
{
super(new MappedByteBufferPool.Tagged());
this.id = id;
}
public void assertNoLeaks()
{
assertThat("Leaked Acquires Count for [" + id + "]", getLeakedAcquires(), is(0L));
assertThat("Leaked Releases Count for [" + id + "]", getLeakedReleases(), is(0L));
assertThat("Leaked Resource Count for [" + id + "]", getLeakedResources(), is(0L));
}
@Override
public Statement apply(final Statement statement, Description description)
{
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
clearTracking();
statement.evaluate();
assertNoLeaks();
}
};
}
}

View File

@ -0,0 +1,110 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import static org.hamcrest.Matchers.is;
import java.nio.ByteBuffer;
import org.junit.Assert;
public class RawFrameBuilder
{
public static void putOpFin(ByteBuffer buf, byte opcode, boolean fin)
{
byte b = 0x00;
if (fin)
{
b |= 0x80;
}
b |= opcode & 0x0F;
buf.put(b);
}
public static void putLengthAndMask(ByteBuffer buf, int length, byte mask[])
{
if (mask != null)
{
Assert.assertThat("Mask.length",mask.length,is(4));
putLength(buf,length,(mask != null));
buf.put(mask);
}
else
{
putLength(buf,length,false);
}
}
public static byte[] mask(final byte[] data, final byte mask[])
{
Assert.assertThat("Mask.length",mask.length,is(4));
int len = data.length;
byte ret[] = new byte[len];
System.arraycopy(data,0,ret,0,len);
for (int i = 0; i < len; i++)
{
ret[i] ^= mask[i % 4];
}
return ret;
}
public static void putLength(ByteBuffer buf, int length, boolean masked)
{
if (length < 0)
{
throw new IllegalArgumentException("Length cannot be negative");
}
byte b = (masked?(byte)0x80:0x00);
// write the uncompressed length
if (length > 0xFF_FF)
{
buf.put((byte)(b | 0x7F));
buf.put((byte)0x00);
buf.put((byte)0x00);
buf.put((byte)0x00);
buf.put((byte)0x00);
buf.put((byte)((length >> 24) & 0xFF));
buf.put((byte)((length >> 16) & 0xFF));
buf.put((byte)((length >> 8) & 0xFF));
buf.put((byte)(length & 0xFF));
}
else if (length >= 0x7E)
{
buf.put((byte)(b | 0x7E));
buf.put((byte)(length >> 8));
buf.put((byte)(length & 0xFF));
}
else
{
buf.put((byte)(b | length));
}
}
public static void putMask(ByteBuffer buf, byte mask[])
{
Assert.assertThat("Mask.length",mask.length,is(4));
buf.put(mask);
}
public static void putPayloadLength(ByteBuffer buf, int length)
{
putLength(buf,length,true);
}
}

View File

@ -0,0 +1,163 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import java.net.URI;
import javax.servlet.http.HttpServlet;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
public class SimpleServletServer extends ContainerLifeCycle
{
private static final Logger LOG = Log.getLogger(SimpleServletServer.class);
private Server server;
private ServerConnector connector;
private URI serverUri;
private HttpServlet servlet;
private boolean ssl = false;
private SslContextFactory sslContextFactory;
public SimpleServletServer(HttpServlet servlet)
{
this.servlet = servlet;
}
public void enableSsl(boolean ssl)
{
this.ssl = ssl;
}
public URI getServerUri()
{
return serverUri;
}
public SslContextFactory getSslContextFactory()
{
return sslContextFactory;
}
public boolean isSslEnabled()
{
return ssl;
}
@Override
protected void doStart() throws Exception
{
// Configure Server
server = new Server();
if (ssl)
{
// HTTP Configuration
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecureScheme("https");
http_config.setSecurePort(0);
http_config.setOutputBufferSize(32768);
http_config.setRequestHeaderSize(8192);
http_config.setResponseHeaderSize(8192);
http_config.setSendServerVersion(true);
http_config.setSendDateHeader(false);
sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath());
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA","SSL_DHE_RSA_WITH_DES_CBC_SHA","SSL_DHE_DSS_WITH_DES_CBC_SHA",
"SSL_RSA_EXPORT_WITH_RC4_40_MD5","SSL_RSA_EXPORT_WITH_DES40_CBC_SHA","SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
// SSL HTTP Configuration
HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
// SSL Connector
connector = new ServerConnector(server,new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),new HttpConnectionFactory(https_config));
connector.setPort(0);
}
else
{
// Basic HTTP connector
connector = new ServerConnector(server);
connector.setPort(0);
}
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
configureServletContextHandler(context);
server.setHandler(context);
// Serve capture servlet
context.addServlet(new ServletHolder(servlet),"/*");
// Start Server
addBean(server);
super.doStart();
// Establish the Server URI
String host = connector.getHost();
if (host == null)
{
host = "localhost";
}
int port = connector.getLocalPort();
serverUri = new URI(String.format("%s://%s:%d/",ssl?"wss":"ws",host,port));
// Some debugging
if (LOG.isDebugEnabled())
{
LOG.debug(server.dump());
}
}
protected void configureServletContextHandler(ServletContextHandler context)
{
}
public WebSocketServletFactory getWebSocketServletFactory()
{
// Try filter approach first
WebSocketUpgradeFilter filter = (WebSocketUpgradeFilter)this.servlet.getServletContext().getAttribute(WebSocketUpgradeFilter.class.getName());
if (filter != null)
{
return filter.getFactory();
}
// Try servlet next
return (WebSocketServletFactory)this.servlet.getServletContext().getAttribute(WebSocketServletFactory.class.getName());
}
}

View File

@ -0,0 +1,69 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
public class UntrustedWSClient extends WebSocketClient
{
private static final Logger LOG = Log.getLogger(UntrustedWSClient.class);
public UntrustedWSClient()
{
super();
setSessionFactory(new UntrustedWSSessionFactory(this));
}
public UntrustedWSClient(HttpClient httpClient)
{
super(httpClient);
setSessionFactory(new UntrustedWSSessionFactory(this));
}
public Future<UntrustedWSSession> connect(URI toUri, ClientUpgradeRequest req) throws IOException
{
final Future<Session> connectFut = super.connect(new UntrustedWSEndpoint(), toUri, req);
return new CompletableFuture<UntrustedWSSession>() {
@Override
public UntrustedWSSession get() throws InterruptedException, ExecutionException
{
return (UntrustedWSSession) connectFut.get();
}
@Override
public UntrustedWSSession get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
{
return (UntrustedWSSession) connectFut.get(timeout, unit);
}
};
}
}

View File

@ -0,0 +1,124 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.SharedBlockingCallback;
import org.eclipse.jetty.util.SharedBlockingCallback.Blocker;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
/**
* A wrapper for {@link org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection} to
* allow for untrusted behaviors, such as arbitrary writes and flushes on network.
*/
public class UntrustedWSConnection
{
private static final Logger LOG = Log.getLogger(UntrustedWSConnection.class);
private final AbstractWebSocketConnection internalConnection;
private final SharedBlockingCallback writeBlocker;
public UntrustedWSConnection(AbstractWebSocketConnection connection)
{
this.internalConnection = connection;
this.writeBlocker = new SharedBlockingCallback();
}
/**
* Perform write flush.
*/
public void flush() throws IOException
{
internalConnection.getEndPoint().flush();
}
/**
* Write arbitrary bytes out the active connection.
*
* @param buf the buffer to write
* @throws IOException
*/
public void writeRaw(ByteBuffer buf) throws IOException
{
try(Blocker blocker = writeBlocker.acquire())
{
internalConnection.getEndPoint().write(blocker, buf);
blocker.block();
}
}
/**
* Write arbitrary bytes out the active connection.
*
* @param buf the buffer to write
* @param numBytes the number of bytes from the buffer to write
* @throws IOException
*/
public void writeRaw(ByteBuffer buf, int numBytes) throws IOException
{
try(Blocker blocker = writeBlocker.acquire())
{
ByteBuffer slice = buf.slice();
int writeLen = Math.min(buf.remaining(), numBytes);
slice.limit(writeLen);
internalConnection.getEndPoint().write(blocker, slice);
blocker.block();
buf.position(buf.position() + writeLen);
}
}
/**
* Write arbitrary String out the active connection.
*
* @param str the string, converted to UTF8 bytes, then written
* @throws IOException
*/
public void writeRaw(String str) throws IOException
{
LOG.debug("write((String)[{}]){}{})",str.length(),'\n',str);
writeRaw(BufferUtil.toBuffer(str, StandardCharsets.UTF_8));
}
/**
* Write arbitrary buffer out the active connection, slowly.
*
* @param buf the buffer to write
* @param segmentSize the segment size to write, with a {@link #flush()} after each segment
* @throws IOException
*/
public void writeRawSlowly(ByteBuffer buf, int segmentSize) throws IOException
{
while (buf.remaining() > 0)
{
writeRaw(buf,segmentSize);
flush();
}
}
public boolean isConnected()
{
return internalConnection.getEndPoint().isOpen();
}
}

View File

@ -0,0 +1,157 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketFrameListener;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
public class UntrustedWSEndpoint implements WebSocketListener, WebSocketFrameListener
{
@SuppressWarnings("unused")
private Session session;
public CountDownLatch openLatch = new CountDownLatch(1);
public CountDownLatch closeLatch = new CountDownLatch(1);
public AtomicReference<CloseInfo> closeInfo = new AtomicReference<>();
public AtomicReference<Throwable> error = new AtomicReference<>();
private CompletableFuture<List<String>> expectedMessagesFuture;
private AtomicInteger expectedMessageCount;
private List<String> messages = new ArrayList<>();
private CompletableFuture<List<WebSocketFrame>> expectedFramesFuture;
private AtomicInteger expectedFramesCount;
private List<WebSocketFrame> frames = new ArrayList<>();
public Future<List<WebSocketFrame>> expectedFrames(int expectedCount)
{
expectedFramesFuture = new CompletableFuture<>();
expectedFramesCount = new AtomicInteger(expectedCount);
return expectedFramesFuture;
}
public Future<List<String>> expectedMessages(int expected)
{
expectedMessagesFuture = new CompletableFuture<>();
expectedMessageCount = new AtomicInteger(expected);
return expectedMessagesFuture;
}
@Override
public void onWebSocketConnect(Session session)
{
this.session = session;
this.openLatch.countDown();
}
@Override
public void onWebSocketClose(int statusCode, String reason)
{
this.closeLatch.countDown();
CloseInfo close = new CloseInfo(statusCode, reason);
assertThat("Close only happened once", closeInfo.compareAndSet(null, close), is(true));
}
@Override
public void onWebSocketError(Throwable cause)
{
assertThat("Error must have value", cause, notNullValue());
if (error.compareAndSet(null, cause) == false)
{
System.err.println("Original Cause");
error.get().printStackTrace(System.err);
System.err.println("Extra/Excess Cause");
cause.printStackTrace(System.err);
fail("onError should only happen once!");
}
if(expectedMessagesFuture != null)
{
synchronized (expectedMessagesFuture)
{
if (expectedMessagesFuture != null)
expectedMessagesFuture.completeExceptionally(cause);
}
}
if(expectedFramesFuture != null)
{
synchronized (expectedFramesFuture)
{
if (expectedFramesFuture != null)
expectedFramesFuture.completeExceptionally(cause);
}
}
}
@Override
public void onWebSocketBinary(byte[] payload, int offset, int len)
{
// TODO
}
@Override
public void onWebSocketText(String text)
{
if(expectedMessagesFuture == null)
return;
messages.add(text);
synchronized (expectedMessagesFuture)
{
if (expectedMessageCount.decrementAndGet() <= 0)
{
expectedMessagesFuture.complete(messages);
}
}
}
@Override
public void onWebSocketFrame(Frame frame)
{
if (expectedFramesFuture == null)
return;
frames.add(WebSocketFrame.copy(frame));
synchronized (expectedFramesFuture)
{
if (expectedFramesCount.decrementAndGet() <= 0)
{
expectedFramesFuture.complete(frames);
}
}
}
}

View File

@ -0,0 +1,49 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import java.net.URI;
import org.eclipse.jetty.websocket.common.LogicalConnection;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
public class UntrustedWSSession extends WebSocketSession implements AutoCloseable
{
private final UntrustedWSConnection untrustedConnection;
private final UntrustedWSEndpoint untrustedEndpoint;
public UntrustedWSSession(WebSocketContainerScope containerScope, URI requestURI, Object endpoint, LogicalConnection connection)
{
super(containerScope, requestURI, endpoint, connection);
this.untrustedConnection = new UntrustedWSConnection((AbstractWebSocketConnection) connection);
this.untrustedEndpoint = (UntrustedWSEndpoint) endpoint;
}
public UntrustedWSConnection getUntrustedConnection()
{
return untrustedConnection;
}
public UntrustedWSEndpoint getUntrustedEndpoint()
{
return untrustedEndpoint;
}
}

View File

@ -0,0 +1,50 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import java.net.URI;
import org.eclipse.jetty.websocket.api.WebSocketConnectionListener;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.common.LogicalConnection;
import org.eclipse.jetty.websocket.common.SessionFactory;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
public class UntrustedWSSessionFactory implements SessionFactory
{
private final WebSocketContainerScope containerScope;
public UntrustedWSSessionFactory(WebSocketContainerScope containerScope)
{
this.containerScope = containerScope;
}
@Override
public boolean supports(Object websocket)
{
return (websocket instanceof WebSocketConnectionListener) || (websocket.getClass().getAnnotation(WebSocket.class) != null);
}
@Override
public WebSocketSession createSession(URI requestURI, Object websocket, LogicalConnection connection)
{
return new UntrustedWSSession(containerScope, requestURI, websocket, connection);
}
}

View File

@ -0,0 +1,126 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.util.WSURI;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class UntrustedWSClientTest
{
@WebSocket
public static class StatusSocket
{
@OnWebSocketMessage
public void onMessage(Session session, String msg) throws IOException
{
session.getRemote().sendString(msg);
}
}
public static class StatusServlet extends WebSocketServlet implements WebSocketCreator
{
@Override
public void configure(WebSocketServletFactory factory)
{
factory.setCreator(this);
}
@Override
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
return new StatusSocket();
}
}
private static Server server;
private static URI wsServerURI;
@BeforeClass
public static void startServer() throws Exception
{
server = new Server(0);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(StatusServlet.class, "/status");
server.setHandler(context);
server.start();
URI serverURI = server.getURI();
wsServerURI = WSURI.toWebsocket(serverURI);
}
@AfterClass
public static void stopServer() throws Exception
{
server.stop();
}
@Test
public void testConnect() throws Exception
{
UntrustedWSClient client = new UntrustedWSClient();
try
{
client.start();
ClientUpgradeRequest request = new ClientUpgradeRequest();
Future<UntrustedWSSession> fut = client.connect(wsServerURI.resolve("/status"), request);
try (UntrustedWSSession session = fut.get(5, TimeUnit.SECONDS))
{
UntrustedWSEndpoint endpoint = session.getUntrustedEndpoint();
Future<List<String>> futMessages = endpoint.expectedMessages(1);
session.getRemote().sendString("hello");
List<String> messages = futMessages.get();
assertThat("Messages.size", messages.size(), is(1));
assertThat("Messages[0]", messages.get(0), is("hello"));
}
}
finally
{
client.stop();
}
}
}

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.net.URI; import java.net.URI;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -30,10 +30,12 @@ import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.Generator; import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzed; import org.eclipse.jetty.websocket.tests.Fuzzed;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.eclipse.jetty.websocket.common.test.RawFrameBuilder; import org.eclipse.jetty.websocket.tests.LeakTrackingBufferPoolRule;
import org.eclipse.jetty.websocket.server.SimpleServletServer; import org.eclipse.jetty.websocket.tests.RawFrameBuilder;
import org.eclipse.jetty.websocket.tests.SimpleServletServer;
import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -78,27 +80,38 @@ public abstract class AbstractABCase implements Fuzzed
protected Generator strictGenerator; protected Generator strictGenerator;
protected Generator laxGenerator; protected Generator laxGenerator;
protected static SimpleServletServer server; protected static SimpleServletServer server;
protected Fuzzer fuzzer;
@Rule @Rule
public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test");
@Before @Before
public void initGenerators() public void setup() throws Exception
{ {
fuzzer = new Fuzzer();
fuzzer.getWSClient().setBufferPool(bufferPool);
fuzzer.start();
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy(); WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
strictGenerator = new Generator(policy,bufferPool,true); strictGenerator = new Generator(policy,bufferPool,true);
laxGenerator = new Generator(policy,bufferPool,false); laxGenerator = new Generator(policy,bufferPool,false);
} }
@After
public void tearDown() throws Exception
{
fuzzer.stop();
}
@BeforeClass @BeforeClass
public static void startServer() throws Exception public static void startEnv() throws Exception
{ {
server = new SimpleServletServer(new ABServlet()); server = new SimpleServletServer(new ABServlet());
server.start(); server.start();
} }
@AfterClass @AfterClass
public static void stopServer() public static void stopEnv() throws Exception
{ {
server.stop(); server.stop();
} }

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -28,8 +28,7 @@ import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.BinaryFrame; import org.eclipse.jetty.websocket.common.frames.BinaryFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.eclipse.jetty.websocket.common.test.Fuzzer.SendMode;
import org.junit.Test; import org.junit.Test;
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
@ -37,6 +36,7 @@ public class TestABCase1 extends AbstractABCase
{ {
/** /**
* Echo 0 byte TEXT message * Echo 0 byte TEXT message
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -50,24 +50,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new TextFrame()); expect.add(new TextFrame());
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 125 byte TEXT message (uses small 7-bit payload length) * Echo 125 byte TEXT message (uses small 7-bit payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_1_2() throws Exception public void testCase1_1_2() throws Exception
{ {
byte payload[] = new byte[125]; byte payload[] = new byte[125];
Arrays.fill(payload,(byte)'*'); Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -78,24 +78,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 126 byte TEXT message (uses medium 2 byte payload length) * Echo 126 byte TEXT message (uses medium 2 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_1_3() throws Exception public void testCase1_1_3() throws Exception
{ {
byte payload[] = new byte[126]; byte payload[] = new byte[126];
Arrays.fill(payload,(byte)'*'); Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -106,24 +106,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 127 byte TEXT message (uses medium 2 byte payload length) * Echo 127 byte TEXT message (uses medium 2 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_1_4() throws Exception public void testCase1_1_4() throws Exception
{ {
byte payload[] = new byte[127]; byte payload[] = new byte[127];
Arrays.fill(payload,(byte)'*'); Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -134,24 +134,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 128 byte TEXT message (uses medium 2 byte payload length) * Echo 128 byte TEXT message (uses medium 2 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_1_5() throws Exception public void testCase1_1_5() throws Exception
{ {
byte payload[] = new byte[128]; byte payload[] = new byte[128];
Arrays.fill(payload,(byte)'*'); Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -162,24 +162,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 65535 byte TEXT message (uses medium 2 byte payload length) * Echo 65535 byte TEXT message (uses medium 2 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_1_6() throws Exception public void testCase1_1_6() throws Exception
{ {
byte payload[] = new byte[65535]; byte payload[] = new byte[65535];
Arrays.fill(payload,(byte)'*'); Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -190,24 +190,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 65536 byte TEXT message (uses large 8 byte payload length) * Echo 65536 byte TEXT message (uses large 8 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_1_7() throws Exception public void testCase1_1_7() throws Exception
{ {
byte payload[] = new byte[65536]; byte payload[] = new byte[65536];
Arrays.fill(payload,(byte)'*'); Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -218,12 +218,11 @@ public class TestABCase1 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -233,13 +232,14 @@ public class TestABCase1 extends AbstractABCase
* Only send 1 TEXT frame from client, but in small segments (flushed after each). * Only send 1 TEXT frame from client, but in small segments (flushed after each).
* <p> * <p>
* This is done to test the parsing together of the frame on the server side. * This is done to test the parsing together of the frame on the server side.
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_1_8() throws Exception public void testCase1_1_8() throws Exception
{ {
byte payload[] = new byte[65536]; byte payload[] = new byte[65536];
Arrays.fill(payload,(byte)'*'); Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
int segmentSize = 997; int segmentSize = 997;
@ -251,18 +251,17 @@ public class TestABCase1 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(segmentSize);
fuzzer.setSendMode(SendMode.SLOW); session.send(send);
fuzzer.setSlowSendSegmentSize(segmentSize); session.expect(expect);
fuzzer.send(send);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 0 byte BINARY message * Echo 0 byte BINARY message
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -276,24 +275,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new BinaryFrame()); expect.add(new BinaryFrame());
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 125 byte BINARY message (uses small 7-bit payload length) * Echo 125 byte BINARY message (uses small 7-bit payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_2_2() throws Exception public void testCase1_2_2() throws Exception
{ {
byte payload[] = new byte[125]; byte payload[] = new byte[125];
Arrays.fill(payload,(byte)0xFE); Arrays.fill(payload, (byte) 0xFE);
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -304,24 +303,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 126 byte BINARY message (uses medium 2 byte payload length) * Echo 126 byte BINARY message (uses medium 2 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_2_3() throws Exception public void testCase1_2_3() throws Exception
{ {
byte payload[] = new byte[126]; byte payload[] = new byte[126];
Arrays.fill(payload,(byte)0xFE); Arrays.fill(payload, (byte) 0xFE);
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -332,24 +331,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 127 byte BINARY message (uses medium 2 byte payload length) * Echo 127 byte BINARY message (uses medium 2 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_2_4() throws Exception public void testCase1_2_4() throws Exception
{ {
byte payload[] = new byte[127]; byte payload[] = new byte[127];
Arrays.fill(payload,(byte)0xFE); Arrays.fill(payload, (byte) 0xFE);
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -360,24 +359,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 128 byte BINARY message (uses medium 2 byte payload length) * Echo 128 byte BINARY message (uses medium 2 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_2_5() throws Exception public void testCase1_2_5() throws Exception
{ {
byte payload[] = new byte[128]; byte payload[] = new byte[128];
Arrays.fill(payload,(byte)0xFE); Arrays.fill(payload, (byte) 0xFE);
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -388,24 +387,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 65535 byte BINARY message (uses medium 2 byte payload length) * Echo 65535 byte BINARY message (uses medium 2 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_2_6() throws Exception public void testCase1_2_6() throws Exception
{ {
byte payload[] = new byte[65535]; byte payload[] = new byte[65535];
Arrays.fill(payload,(byte)0xFE); Arrays.fill(payload, (byte) 0xFE);
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -416,24 +415,24 @@ public class TestABCase1 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Echo 65536 byte BINARY message (uses large 8 byte payload length) * Echo 65536 byte BINARY message (uses large 8 byte payload length)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_2_7() throws Exception public void testCase1_2_7() throws Exception
{ {
byte payload[] = new byte[65536]; byte payload[] = new byte[65536];
Arrays.fill(payload,(byte)0xFE); Arrays.fill(payload, (byte) 0xFE);
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
@ -444,12 +443,11 @@ public class TestABCase1 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -459,13 +457,14 @@ public class TestABCase1 extends AbstractABCase
* Only send 1 BINARY frame from client, but in small segments (flushed after each). * Only send 1 BINARY frame from client, but in small segments (flushed after each).
* <p> * <p>
* This is done to test the parsing together of the frame on the server side. * This is done to test the parsing together of the frame on the server side.
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testCase1_2_8() throws Exception public void testCase1_2_8() throws Exception
{ {
byte payload[] = new byte[65536]; byte payload[] = new byte[65536];
Arrays.fill(payload,(byte)0xFE); Arrays.fill(payload, (byte) 0xFE);
ByteBuffer buf = ByteBuffer.wrap(payload); ByteBuffer buf = ByteBuffer.wrap(payload);
int segmentSize = 997; int segmentSize = 997;
@ -477,13 +476,11 @@ public class TestABCase1 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(segmentSize);
fuzzer.setSendMode(SendMode.SLOW); session.send(send);
fuzzer.setSlowSendSegmentSize(segmentSize); session.expect(expect);
fuzzer.send(send);
fuzzer.expect(expect);
} }
} }
} }

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame;
import org.eclipse.jetty.websocket.common.frames.PongFrame; import org.eclipse.jetty.websocket.common.frames.PongFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -47,16 +47,17 @@ public class TestABCase2 extends AbstractABCase
@Test @Test
public void testCase2_1() throws Exception public void testCase2_1() throws Exception
{ {
WebSocketFrame send = new PingFrame(); List<WebSocketFrame> send = new ArrayList<>();
send.add(new PingFrame());
WebSocketFrame expect = new PongFrame(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new PongFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -86,12 +87,11 @@ public class TestABCase2 extends AbstractABCase
send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -121,13 +121,11 @@ public class TestABCase2 extends AbstractABCase
send.add(new CloseInfo(StatusCode.NORMAL).asFrame()); send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(5);
fuzzer.setSendMode(Fuzzer.SendMode.SLOW); session.send(send);
fuzzer.setSlowSendSegmentSize(5); session.expect(expect);
fuzzer.send(send);
fuzzer.expect(expect);
} }
} }
@ -148,12 +146,11 @@ public class TestABCase2 extends AbstractABCase
expect.add(new PongFrame().setPayload(copyOf(payload))); expect.add(new PongFrame().setPayload(copyOf(payload)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -174,12 +171,11 @@ public class TestABCase2 extends AbstractABCase
expect.add(new PongFrame().setPayload(copyOf(payload))); expect.add(new PongFrame().setPayload(copyOf(payload)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -201,12 +197,11 @@ public class TestABCase2 extends AbstractABCase
expect.add(new PongFrame().setPayload(copyOf(payload))); expect.add(new PongFrame().setPayload(copyOf(payload)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -217,7 +212,7 @@ public class TestABCase2 extends AbstractABCase
@Test @Test
public void testCase2_5() throws Exception public void testCase2_5() throws Exception
{ {
try (StacklessLogging scope = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class))
{ {
byte payload[] = new byte[126]; // intentionally too big byte payload[] = new byte[126]; // intentionally too big
Arrays.fill(payload,(byte)'5'); Arrays.fill(payload,(byte)'5');
@ -231,12 +226,11 @@ public class TestABCase2 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
} }
@ -259,13 +253,11 @@ public class TestABCase2 extends AbstractABCase
expect.add(new PongFrame().setPayload(copyOf(payload))); expect.add(new PongFrame().setPayload(copyOf(payload)));
expect.add(new CloseInfo(StatusCode.NORMAL,"Test 2.6").asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL,"Test 2.6").asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(1);
fuzzer.setSendMode(Fuzzer.SendMode.SLOW); session.send(send);
fuzzer.setSlowSendSegmentSize(1); session.expect(expect);
fuzzer.send(send);
fuzzer.expect(expect);
} }
} }
@ -283,12 +275,11 @@ public class TestABCase2 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -306,12 +297,11 @@ public class TestABCase2 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -331,12 +321,11 @@ public class TestABCase2 extends AbstractABCase
expect.add(new PongFrame().setPayload("our ping")); // our pong expect.add(new PongFrame().setPayload("our ping")); // our pong
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
} }

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -30,7 +30,7 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.BinaryFrame; import org.eclipse.jetty.websocket.common.frames.BinaryFrame;
import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.junit.Test; import org.junit.Test;
/** /**
@ -49,12 +49,12 @@ public class TestABCase3 extends AbstractABCase
WebSocketFrame expect = new CloseInfo(StatusCode.PROTOCOL).asFrame(); WebSocketFrame expect = new CloseInfo(StatusCode.PROTOCOL).asFrame();
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -74,12 +74,12 @@ public class TestABCase3 extends AbstractABCase
expect.add(new TextFrame().setPayload("small")); // echo on good frame expect.add(new TextFrame().setPayload("small")); // echo on good frame
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -99,12 +99,12 @@ public class TestABCase3 extends AbstractABCase
expect.add(new TextFrame().setPayload("small")); // echo on good frame expect.add(new TextFrame().setPayload("small")); // echo on good frame
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.perFrameMode();
fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -124,13 +124,12 @@ public class TestABCase3 extends AbstractABCase
expect.add(new TextFrame().setPayload("small")); // echo on good frame expect.add(new TextFrame().setPayload("small")); // echo on good frame
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(1);
fuzzer.setSendMode(Fuzzer.SendMode.SLOW); session.send(send);
fuzzer.setSlowSendSegmentSize(1); session.expect(expect);
fuzzer.send(send);
fuzzer.expect(expect);
} }
} }
@ -150,12 +149,12 @@ public class TestABCase3 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -175,12 +174,12 @@ public class TestABCase3 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -204,12 +203,12 @@ public class TestABCase3 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
} }

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -54,12 +54,12 @@ public class TestABCase4 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -79,12 +79,12 @@ public class TestABCase4 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -104,12 +104,12 @@ public class TestABCase4 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new TextFrame().setPayload("hello")); // echo
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -131,12 +131,12 @@ public class TestABCase4 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new TextFrame().setPayload("hello")); // echo
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -158,12 +158,12 @@ public class TestABCase4 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new TextFrame().setPayload("hello")); // echo
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -180,12 +180,12 @@ public class TestABCase4 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -204,12 +204,12 @@ public class TestABCase4 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -229,12 +229,12 @@ public class TestABCase4 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new TextFrame().setPayload("hello")); // echo
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -256,12 +256,12 @@ public class TestABCase4 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new TextFrame().setPayload("hello")); // echo
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -283,12 +283,12 @@ public class TestABCase4 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello")); // echo expect.add(new TextFrame().setPayload("hello")); // echo
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
} }

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.common.frames.ContinuationFrame;
import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame;
import org.eclipse.jetty.websocket.common.frames.PongFrame; import org.eclipse.jetty.websocket.common.frames.PongFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -45,6 +45,7 @@ public class TestABCase5 extends AbstractABCase
{ {
/** /**
* Send ping fragmented in 2 packets * Send ping fragmented in 2 packets
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -58,17 +59,18 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Send continuation+fin, then text+fin (framewise) * Send continuation+fin, then text+fin (framewise)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -82,17 +84,19 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.perFrameMode();
fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); session.ignoreBrokenPipe();
fuzzer.sendAndIgnoreBrokenPipe(send); session.send(send);
fuzzer.expect(expect); session.expect(expect);
} }
} }
/** /**
* Send continuation+fin, then text+fin (slowly) * Send continuation+fin, then text+fin (slowly)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -106,18 +110,19 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(1);
fuzzer.setSendMode(Fuzzer.SendMode.SLOW); session.ignoreBrokenPipe();
fuzzer.setSlowSendSegmentSize(1); session.send(send);
fuzzer.sendAndIgnoreBrokenPipe(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Send continuation+!fin, then text+fin * Send continuation+!fin, then text+fin
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -131,17 +136,19 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.ignoreBrokenPipe();
fuzzer.sendAndIgnoreBrokenPipe(send); session.send(send);
fuzzer.expect(expect); session.expect(expect);
} }
} }
/** /**
* Send continuation+!fin, then text+fin (framewise) * Send continuation+!fin, then text+fin (framewise)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -155,17 +162,19 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.perFrameMode();
fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); session.ignoreBrokenPipe();
fuzzer.sendAndIgnoreBrokenPipe(send); session.send(send);
fuzzer.expect(expect); session.expect(expect);
} }
} }
/** /**
* Send continuation+!fin, then text+fin (slowly) * Send continuation+!fin, then text+fin (slowly)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -179,18 +188,19 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(1);
fuzzer.setSendMode(Fuzzer.SendMode.SLOW); session.ignoreBrokenPipe();
fuzzer.setSlowSendSegmentSize(1); session.send(send);
fuzzer.sendAndIgnoreBrokenPipe(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Send text fragmented properly in 2 frames, then continuation!fin, then text unfragmented. * Send text fragmented properly in 2 frames, then continuation!fin, then text unfragmented.
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -207,17 +217,18 @@ public class TestABCase5 extends AbstractABCase
expect.add(new TextFrame().setPayload("fragment1fragment2")); expect.add(new TextFrame().setPayload("fragment1fragment2"));
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* (continuation!fin, text!fin, continuation+fin) * 2 * (continuation!fin, text!fin, continuation+fin) * 2
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -235,17 +246,19 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.ignoreBrokenPipe();
fuzzer.sendAndIgnoreBrokenPipe(send); session.send(send);
fuzzer.expect(expect); session.expect(expect);
} }
} }
/** /**
* (continuation+fin, text!fin, continuation+fin) * 2 * (continuation+fin, text!fin, continuation+fin) * 2
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -263,17 +276,18 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* text message fragmented in 2 frames, both frames as opcode=TEXT * text message fragmented in 2 frames, both frames as opcode=TEXT
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -287,17 +301,18 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* send text message fragmented in 5 frames, with 2 pings and wait between. * send text message fragmented in 5 frames, with 2 pings and wait between.
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -326,26 +341,27 @@ public class TestABCase5 extends AbstractABCase
expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5")); expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5"));
expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
// phase 1 // phase 1
fuzzer.send(send1); session.send(send1);
fuzzer.expect(expect1); session.expect(expect1);
// delay // delay
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
// phase 2 // phase 2
fuzzer.send(send2); session.send(send2);
fuzzer.expect(expect2); session.expect(expect2);
} }
} }
/** /**
* Send pong fragmented in 2 packets * Send pong fragmented in 2 packets
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -359,17 +375,18 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* send text message fragmented in 5 frames, with 2 pings and wait between. (framewise) * send text message fragmented in 5 frames, with 2 pings and wait between. (framewise)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -395,23 +412,23 @@ public class TestABCase5 extends AbstractABCase
expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5")); expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5"));
expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.perFrameMode();
fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); session.send(send1);
session.expect(expect1);
fuzzer.send(send1);
fuzzer.expect(expect1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
fuzzer.send(send2); session.send(send2);
fuzzer.expect(expect2); session.expect(expect2);
} }
} }
/** /**
* send text message fragmented in 5 frames, with 2 pings and wait between. (framewise) * send text message fragmented in 5 frames, with 2 pings and wait between. (framewise)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -437,24 +454,23 @@ public class TestABCase5 extends AbstractABCase
expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5")); expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5"));
expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(1);
fuzzer.setSendMode(Fuzzer.SendMode.SLOW); session.send(send1);
fuzzer.setSlowSendSegmentSize(1); session.expect(expect1);
fuzzer.send(send1);
fuzzer.expect(expect1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
fuzzer.send(send2); session.send(send2);
fuzzer.expect(expect2); session.expect(expect2);
} }
} }
/** /**
* Send text fragmented in 2 packets * Send text fragmented in 2 packets
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -469,17 +485,18 @@ public class TestABCase5 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello, world")); expect.add(new TextFrame().setPayload("hello, world"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Send text fragmented in 2 packets (framewise) * Send text fragmented in 2 packets (framewise)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -494,17 +511,18 @@ public class TestABCase5 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello, world")); expect.add(new TextFrame().setPayload("hello, world"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.perFrameMode();
fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Send text fragmented in 2 packets (slowly) * Send text fragmented in 2 packets (slowly)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -519,18 +537,18 @@ public class TestABCase5 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello, world")); expect.add(new TextFrame().setPayload("hello, world"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(1);
fuzzer.setSendMode(Fuzzer.SendMode.SLOW); session.send(send);
fuzzer.setSlowSendSegmentSize(1); session.expect(expect);
fuzzer.send(send);
fuzzer.expect(expect);
} }
} }
/** /**
* Send text fragmented in 2 packets, with ping between them * Send text fragmented in 2 packets, with ping between them
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -547,17 +565,18 @@ public class TestABCase5 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello, world")); expect.add(new TextFrame().setPayload("hello, world"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Send text fragmented in 2 packets, with ping between them (frame wise) * Send text fragmented in 2 packets, with ping between them (frame wise)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -574,17 +593,18 @@ public class TestABCase5 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello, world")); expect.add(new TextFrame().setPayload("hello, world"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.perFrameMode();
fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
/** /**
* Send text fragmented in 2 packets, with ping between them (slowly) * Send text fragmented in 2 packets, with ping between them (slowly)
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -601,18 +621,18 @@ public class TestABCase5 extends AbstractABCase
expect.add(new TextFrame().setPayload("hello, world")); expect.add(new TextFrame().setPayload("hello, world"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(1);
fuzzer.setSendMode(Fuzzer.SendMode.SLOW); session.send(send);
fuzzer.setSlowSendSegmentSize(1); session.expect(expect);
fuzzer.send(send);
fuzzer.expect(expect);
} }
} }
/** /**
* Send continuation+fin, then text+fin * Send continuation+fin, then text+fin
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -627,12 +647,12 @@ public class TestABCase5 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this);StacklessLogging supress = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
} }

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,6 +24,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.AdvancedRunner; import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.toolchain.test.Hex;
import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
@ -36,8 +37,7 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.ContinuationFrame;
import org.eclipse.jetty.websocket.common.frames.DataFrame; import org.eclipse.jetty.websocket.common.frames.DataFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.eclipse.jetty.websocket.common.util.Hex;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -93,12 +93,11 @@ public class TestABCase6 extends AbstractABCase
expect.add(new TextFrame()); expect.add(new TextFrame());
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -119,12 +118,11 @@ public class TestABCase6 extends AbstractABCase
expect.add(new TextFrame()); expect.add(new TextFrame());
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -145,12 +143,11 @@ public class TestABCase6 extends AbstractABCase
expect.add(new TextFrame().setPayload("middle")); expect.add(new TextFrame().setPayload("middle"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -180,12 +177,11 @@ public class TestABCase6 extends AbstractABCase
expect.add(new TextFrame().setPayload(e1)); expect.add(new TextFrame().setPayload(e1));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -207,12 +203,11 @@ public class TestABCase6 extends AbstractABCase
expect.add(new TextFrame().setPayload(ByteBuffer.wrap(msg))); expect.add(new TextFrame().setPayload(ByteBuffer.wrap(msg)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -233,12 +228,11 @@ public class TestABCase6 extends AbstractABCase
expect.add(new TextFrame().setPayload(ByteBuffer.wrap(msg))); expect.add(new TextFrame().setPayload(ByteBuffer.wrap(msg)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -258,12 +252,11 @@ public class TestABCase6 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -286,18 +279,16 @@ public class TestABCase6 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false)); session.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false));
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true)); session.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true));
fuzzer.expect(expect); session.expect(expect);
} }
} }
@ -322,16 +313,15 @@ public class TestABCase6 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false)); session.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false));
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true)); session.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true));
fuzzer.expect(expect); session.expect(expect);
} }
} }
@ -344,7 +334,7 @@ public class TestABCase6 extends AbstractABCase
public void testCase6_4_3() throws Exception public void testCase6_4_3() throws Exception
{ {
// Disable Long Stacks from Parser (we know this test will throw an exception) // Disable Long Stacks from Parser (we know this test will throw an exception)
try (StacklessLogging scope = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class))
{ {
ByteBuffer payload = ByteBuffer.allocate(64); ByteBuffer payload = ByteBuffer.allocate(64);
BufferUtil.clearToFill(payload); BufferUtil.clearToFill(payload);
@ -360,11 +350,10 @@ public class TestABCase6 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
ByteBuffer net = session.asNetworkBuffer(send);
ByteBuffer net = fuzzer.asNetworkBuffer(send);
int splits[] = { 17, 21, net.limit() }; int splits[] = { 17, 21, net.limit() };
@ -377,13 +366,13 @@ public class TestABCase6 extends AbstractABCase
part3.position(splits[1]); part3.position(splits[1]);
part3.limit(splits[2]); part3.limit(splits[2]);
fuzzer.send(part1); // the header + good utf session.send(part1); // the header + good utf
TimeUnit.MILLISECONDS.sleep(500); TimeUnit.MILLISECONDS.sleep(500);
fuzzer.send(part2); // the bad UTF session.send(part2); // the bad UTF
TimeUnit.MILLISECONDS.sleep(500); TimeUnit.MILLISECONDS.sleep(500);
fuzzer.send(part3); // the rest (shouldn't work) session.send(part3); // the rest (shouldn't work)
fuzzer.expect(expect); session.expect(expect);
} }
} }
} }
@ -405,20 +394,19 @@ public class TestABCase6 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); try (StacklessLogging ignored = new StacklessLogging(Parser.class);
StacklessLogging scope = new StacklessLogging(Parser.class)) Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
ByteBuffer net = session.asNetworkBuffer(send);
ByteBuffer net = fuzzer.asNetworkBuffer(send); session.send(net,6);
fuzzer.send(net,6); session.send(net,11);
fuzzer.send(net,11);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
fuzzer.send(net,1); session.send(net,1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
fuzzer.send(net,100); // the rest session.send(net,100); // the rest
fuzzer.expect(expect); session.expect(expect);
} }
} }
} }

View File

@ -16,13 +16,14 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.eclipse.jetty.toolchain.test.Hex;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.log.StacklessLogging;
@ -31,8 +32,7 @@ import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Parser; import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.eclipse.jetty.websocket.common.util.Hex;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
@ -163,13 +163,12 @@ public class TestABCase6_BadUTF extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); try (StacklessLogging ignored = new StacklessLogging(Parser.class);
StacklessLogging ignored = new StacklessLogging(Parser.class) ) Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
} }

View File

@ -0,0 +1,149 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.jetty.toolchain.test.Hex;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* Tests of Known Good UTF8 sequences.
* <p>
* Should be preserved / echoed back, with normal close code.
*/
@RunWith(Parameterized.class)
public class TestABCase6_GoodUTF extends AbstractABCase
{
private static final Logger LOG = Log.getLogger(TestABCase6_GoodUTF.class);
@Parameters(name = "{0} - {1}")
public static Collection<String[]> data()
{
// The various Good UTF8 sequences as a String (hex form)
List<String[]> data = new ArrayList<>();
// @formatter:off
// - combination of simple 1 byte characters and unicode code points
data.add(new String[]{"6.2.1", "48656C6C6F2DC2B540C39FC3B6C3A4C3BCC3A0C3A12D5554462D382121"});
// - simple valid UTF8 sequence
data.add(new String[]{"6.5.1", "CEBAE1BDB9CF83CEBCCEB5"});
// - multi-byte code points
data.add(new String[]{"6.6.11", "CEBAE1BDB9CF83CEBCCEB5"});
data.add(new String[]{"6.6.2", "CEBA"});
data.add(new String[]{"6.6.5", "CEBAE1BDB9"});
data.add(new String[]{"6.6.7", "CEBAE1BDB9CF83"});
data.add(new String[]{"6.6.9", "CEBAE1BDB9CF83CEBC"});
// - first possible sequence of a certain length (1 code point)
data.add(new String[]{"6.7.1", "00"});
data.add(new String[]{"6.7.2", "C280"});
data.add(new String[]{"6.7.3", "E0A080"});
data.add(new String[]{"6.7.4", "F0908080"});
// - last possible sequence of a certain length (1 code point)
data.add(new String[]{"6.9.1", "7F"});
data.add(new String[]{"6.9.2", "DFBF"});
data.add(new String[]{"6.9.3", "EFBFBF"});
data.add(new String[]{"6.9.4", "F48FBFBF"});
// - other boundary conditions
data.add(new String[]{"6.11.1", "ED9FBF"});
data.add(new String[]{"6.11.2", "EE8080"});
data.add(new String[]{"6.11.3", "EFBFBD"});
data.add(new String[]{"6.11.4", "F48FBFBF"});
// - non character code points
data.add(new String[]{"6.22.1", "EFBFBE"});
data.add(new String[]{"6.22.2", "EFBFBF"});
data.add(new String[]{"6.22.3", "F09FBFBE"});
data.add(new String[]{"6.22.4", "F09FBFBF"});
data.add(new String[]{"6.22.5", "F0AFBFBE"});
data.add(new String[]{"6.22.6", "F0AFBFBF"});
data.add(new String[]{"6.22.7", "F0BFBFBE"});
data.add(new String[]{"6.22.8", "F0BFBFBF"});
data.add(new String[]{"6.22.9", "F18FBFBE"});
data.add(new String[]{"6.22.10", "F18FBFBF"});
data.add(new String[]{"6.22.11", "F19FBFBE"});
data.add(new String[]{"6.22.12", "F19FBFBF"});
data.add(new String[]{"6.22.13", "F1AFBFBE"});
data.add(new String[]{"6.22.14", "F1AFBFBF"});
data.add(new String[]{"6.22.15", "F1BFBFBE"});
data.add(new String[]{"6.22.16", "F1BFBFBF"});
data.add(new String[]{"6.22.17", "F28FBFBE"});
data.add(new String[]{"6.22.18", "F28FBFBF"});
data.add(new String[]{"6.22.19", "F29FBFBE"});
data.add(new String[]{"6.22.20", "F29FBFBF"});
data.add(new String[]{"6.22.21", "F2AFBFBE"});
data.add(new String[]{"6.22.22", "F2AFBFBF"});
data.add(new String[]{"6.22.23", "F2BFBFBE"});
data.add(new String[]{"6.22.24", "F2BFBFBF"});
data.add(new String[]{"6.22.25", "F38FBFBE"});
data.add(new String[]{"6.22.26", "F38FBFBF"});
data.add(new String[]{"6.22.27", "F39FBFBE"});
data.add(new String[]{"6.22.28", "F39FBFBF"});
data.add(new String[]{"6.22.29", "F3AFBFBE"});
data.add(new String[]{"6.22.30", "F3AFBFBF"});
data.add(new String[]{"6.22.31", "F3BFBFBE"});
data.add(new String[]{"6.22.32", "F3BFBFBF"});
data.add(new String[]{"6.22.33", "F48FBFBE"});
data.add(new String[]{"6.22.34", "F48FBFBF"});
// - unicode replacement character
data.add(new String[]{"6.23.1", "EFBFBD"});
// @formatter:on
return data;
}
private final ByteBuffer msg;
public TestABCase6_GoodUTF(String testId, String hexMsg)
{
LOG.debug("Test ID: {}", testId);
this.msg = Hex.asByteBuffer(hexMsg);
}
@Test
public void assertEchoTextMessage() throws Exception
{
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(msg));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame().setPayload(clone(msg)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer.Session session = fuzzer.connect(this))
{
session.bulkMode();
session.send(send);
session.expect(expect);
}
}
}

View File

@ -16,13 +16,14 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.eclipse.jetty.toolchain.test.Hex;
import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
@ -37,8 +38,7 @@ import org.eclipse.jetty.websocket.common.frames.ContinuationFrame;
import org.eclipse.jetty.websocket.common.frames.PingFrame; import org.eclipse.jetty.websocket.common.frames.PingFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection; import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.eclipse.jetty.websocket.common.util.Hex;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -65,12 +65,11 @@ public class TestABCase7 extends AbstractABCase
expect.add(new TextFrame().setPayload("Hello World")); expect.add(new TextFrame().setPayload("Hello World"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -88,13 +87,11 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -112,13 +109,11 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -136,13 +131,11 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -161,13 +154,11 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -191,13 +182,11 @@ public class TestABCase7 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -214,13 +203,11 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseFrame()); expect.add(new CloseFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -240,13 +227,12 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging scope = new StacklessLogging(Parser.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -263,13 +249,11 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -286,13 +270,11 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL,"Hic").asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL,"Hic").asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -313,13 +295,12 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL,reason).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL,reason).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging logging = new StacklessLogging(AbstractWebSocketConnection.class)) try (StacklessLogging ignored = new StacklessLogging(AbstractWebSocketConnection.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
@ -346,13 +327,12 @@ public class TestABCase7 extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame()); expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this); StacklessLogging scope = new StacklessLogging(Parser.class,CloseInfo.class)) try (StacklessLogging ignored = new StacklessLogging(Parser.class,CloseInfo.class);
Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
} }

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo; import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.CloseFrame; import org.eclipse.jetty.websocket.common.frames.CloseFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
@ -45,29 +45,29 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase
{ {
private static final Logger LOG = Log.getLogger(TestABCase7_GoodStatusCodes.class); private static final Logger LOG = Log.getLogger(TestABCase7_GoodStatusCodes.class);
@Parameters(name = "{1} / {0}") @Parameters
public static Collection<Object[]> data() public static Collection<Object[]> data()
{ {
// The various Good UTF8 sequences as a String (hex form) // The various Good UTF8 sequences as a String (hex form)
List<Object[]> data = new ArrayList<>(); List<Object[]> data = new ArrayList<>();
// @formatter:off // @formatter:off
data.add(new Object[] { "7.9.1", 0 }); data.add(new Object[]{"7.9.1", 0});
data.add(new Object[] { "7.9.2", 999 }); data.add(new Object[]{"7.9.2", 999});
data.add(new Object[] { "7.9.3", 1004 }); // RFC6455/UNDEFINED data.add(new Object[]{"7.9.3", 1004});
data.add(new Object[] { "7.9.4", 1005 }); // RFC6455/Cannot Be Transmitted data.add(new Object[]{"7.9.4", 1005});
data.add(new Object[] { "7.9.5", 1006 }); // RFC6455/Cannot Be Transmitted data.add(new Object[]{"7.9.5", 1006});
// data.add(new Object[] { "7.9.6", 1012 }); - IANA Defined data.add(new Object[]{"7.9.6", 1012});
// data.add(new Object[] { "7.9.7", 1013 }); - IANA Defined data.add(new Object[]{"7.9.7", 1013});
// data.add(new Object[] { "7.9.8", 1014 }); - IANA Defined data.add(new Object[]{"7.9.8", 1014});
data.add(new Object[] { "7.9.9", 1015 }); // RFC6455/Cannot Be Transmitted data.add(new Object[]{"7.9.9", 1015});
data.add(new Object[] { "7.9.10", 1016 }); data.add(new Object[]{"7.9.10", 1016});
data.add(new Object[] { "7.9.11", 1100 }); data.add(new Object[]{"7.9.11", 1100});
data.add(new Object[] { "7.9.12", 2000 }); data.add(new Object[]{"7.9.12", 2000});
data.add(new Object[] { "7.9.13", 2999 }); data.add(new Object[]{"7.9.13", 2999});
// -- close status codes, with undefined events in spec // -- close status codes, with undefined events in spec
data.add(new Object[] { "7.13.1", 5000 }); data.add(new Object[]{"7.13.1", 5000});
data.add(new Object[] { "7.13.2", 65536 }); data.add(new Object[]{"7.13.2", 65536});
// @formatter:on // @formatter:on
return data; return data;
@ -77,12 +77,13 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase
public TestABCase7_BadStatusCodes(String testId, int statusCode) public TestABCase7_BadStatusCodes(String testId, int statusCode)
{ {
LOG.debug("Test ID: {}",testId); LOG.debug("Test ID: {}", testId);
this.statusCode = statusCode; this.statusCode = statusCode;
} }
/** /**
* just the close code, no reason * just the close code, no reason
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -90,8 +91,8 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase
{ {
ByteBuffer payload = ByteBuffer.allocate(256); ByteBuffer payload = ByteBuffer.allocate(256);
BufferUtil.clearToFill(payload); BufferUtil.clearToFill(payload);
payload.putChar((char)statusCode); payload.putChar((char) statusCode);
BufferUtil.flipToFlush(payload,0); BufferUtil.flipToFlush(payload, 0);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame().setPayload(payload.slice())); send.add(new CloseFrame().setPayload(payload.slice()));
@ -99,18 +100,17 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
/** /**
* the bad close code, with reason * the bad close code, with reason
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -118,9 +118,9 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase
{ {
ByteBuffer payload = ByteBuffer.allocate(256); ByteBuffer payload = ByteBuffer.allocate(256);
BufferUtil.clearToFill(payload); BufferUtil.clearToFill(payload);
payload.putChar((char)statusCode); payload.putChar((char) statusCode);
payload.put(StringUtil.getBytes("Reason")); payload.put(StringUtil.getBytes("Reason"));
BufferUtil.flipToFlush(payload,0); BufferUtil.flipToFlush(payload, 0);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame().setPayload(payload.slice())); send.add(new CloseFrame().setPayload(payload.slice()));
@ -128,13 +128,11 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame()); expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
} }

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -29,7 +29,7 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.frames.CloseFrame; import org.eclipse.jetty.websocket.common.frames.CloseFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
@ -43,29 +43,26 @@ public class TestABCase7_GoodStatusCodes extends AbstractABCase
{ {
private static final Logger LOG = Log.getLogger(TestABCase7_GoodStatusCodes.class); private static final Logger LOG = Log.getLogger(TestABCase7_GoodStatusCodes.class);
@Parameters(name = "{1} / {0}") @Parameters
public static Collection<Object[]> data() public static Collection<Object[]> data()
{ {
// The various Good UTF8 sequences as a String (hex form) // The various Good UTF8 sequences as a String (hex form)
List<Object[]> data = new ArrayList<>(); List<Object[]> data = new ArrayList<>();
// @formatter:off // @formatter:off
data.add(new Object[] { "7.7.1", 1000 }); data.add(new Object[]{"7.7.1", 1000});
data.add(new Object[] { "7.7.2", 1001 }); data.add(new Object[]{"7.7.2", 1001});
data.add(new Object[] { "7.7.3", 1002 }); data.add(new Object[]{"7.7.3", 1002});
data.add(new Object[] { "7.7.4", 1003 }); data.add(new Object[]{"7.7.4", 1003});
data.add(new Object[] { "7.7.5", 1007 }); data.add(new Object[]{"7.7.5", 1007});
data.add(new Object[] { "7.7.6", 1008 }); data.add(new Object[]{"7.7.6", 1008});
data.add(new Object[] { "7.7.7", 1009 }); data.add(new Object[]{"7.7.7", 1009});
data.add(new Object[] { "7.7.8", 1010 }); data.add(new Object[]{"7.7.8", 1010});
data.add(new Object[] { "7.7.9", 1011 }); data.add(new Object[]{"7.7.9", 1011});
data.add(new Object[] { "IANA Assigned", 1012 }); data.add(new Object[]{"7.7.10", 3000});
data.add(new Object[] { "IANA Assigned", 1013 }); data.add(new Object[]{"7.7.11", 3999});
data.add(new Object[] { "IANA Assigned", 1014 }); data.add(new Object[]{"7.7.12", 4000});
data.add(new Object[] { "7.7.10", 3000 }); data.add(new Object[]{"7.7.13", 4999});
data.add(new Object[] { "7.7.11", 3999 });
data.add(new Object[] { "7.7.12", 4000 });
data.add(new Object[] { "7.7.13", 4999 });
// @formatter:on // @formatter:on
return data; return data;
@ -75,12 +72,13 @@ public class TestABCase7_GoodStatusCodes extends AbstractABCase
public TestABCase7_GoodStatusCodes(String testId, int statusCode) public TestABCase7_GoodStatusCodes(String testId, int statusCode)
{ {
LOG.debug("Test ID: {}",testId); LOG.debug("Test ID: {}", testId);
this.statusCode = statusCode; this.statusCode = statusCode;
} }
/** /**
* just the close code, no reason * just the close code, no reason
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
@ -88,8 +86,8 @@ public class TestABCase7_GoodStatusCodes extends AbstractABCase
{ {
ByteBuffer payload = ByteBuffer.allocate(256); ByteBuffer payload = ByteBuffer.allocate(256);
BufferUtil.clearToFill(payload); BufferUtil.clearToFill(payload);
payload.putChar((char)statusCode); payload.putChar((char) statusCode);
BufferUtil.flipToFlush(payload,0); BufferUtil.flipToFlush(payload, 0);
List<WebSocketFrame> send = new ArrayList<>(); List<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseFrame().setPayload(payload.slice())); send.add(new CloseFrame().setPayload(payload.slice()));
@ -97,25 +95,24 @@ public class TestABCase7_GoodStatusCodes extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseFrame().setPayload(clone(payload))); expect.add(new CloseFrame().setPayload(clone(payload)));
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
/** /**
* the good close code, with reason * the good close code, with reason
*
* @throws Exception on test failure * @throws Exception on test failure
*/ */
@Test @Test
public void testStatusCodeWithReason() throws Exception public void testStatusCodeWithReason() throws Exception
{ {
ByteBuffer payload = ByteBuffer.allocate(256); ByteBuffer payload = ByteBuffer.allocate(256);
payload.putChar((char)statusCode); payload.putChar((char) statusCode);
payload.put(StringUtil.getBytes("Reason")); payload.put(StringUtil.getBytes("Reason"));
payload.flip(); payload.flip();
@ -125,13 +122,11 @@ public class TestABCase7_GoodStatusCodes extends AbstractABCase
List<WebSocketFrame> expect = new ArrayList<>(); List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseFrame().setPayload(clone(payload))); expect.add(new CloseFrame().setPayload(clone(payload)));
try(Fuzzer fuzzer = new Fuzzer(this)) try (Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
} }
} }
} }

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.server.ab; package org.eclipse.jetty.websocket.tests.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,7 +35,7 @@ import org.eclipse.jetty.websocket.common.frames.BinaryFrame;
import org.eclipse.jetty.websocket.common.frames.ContinuationFrame; import org.eclipse.jetty.websocket.common.frames.ContinuationFrame;
import org.eclipse.jetty.websocket.common.frames.DataFrame; import org.eclipse.jetty.websocket.common.frames.DataFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzer; import org.eclipse.jetty.websocket.tests.Fuzzer;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -96,12 +96,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(toDataFrame(opcode).setPayload(copyOf(msg))); expect.add(toDataFrame(opcode).setPayload(copyOf(msg)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect, 32, TimeUnit.SECONDS);
fuzzer.expect(expect,8,TimeUnit.SECONDS);
} }
} }
@ -119,13 +118,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(toDataFrame(opcode).setPayload(clone(buf))); expect.add(toDataFrame(opcode).setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.slowMode(segmentSize);
fuzzer.setSendMode(Fuzzer.SendMode.SLOW); session.send(send);
fuzzer.setSlowSendSegmentSize(segmentSize); session.expect(expect, 32, TimeUnit.SECONDS);
fuzzer.send(send);
fuzzer.expect(expect,8,TimeUnit.SECONDS);
} }
} }
@ -148,12 +145,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new TextFrame().setPayload(msg)); expect.add(new TextFrame().setPayload(msg));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -176,12 +172,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -204,12 +199,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect,4,TimeUnit.SECONDS);
} }
} }
@ -232,12 +226,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect,8,TimeUnit.SECONDS);
} }
} }
@ -261,12 +254,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect, 16, TimeUnit.SECONDS);
fuzzer.expect(expect,16,TimeUnit.SECONDS);
} }
} }
@ -290,12 +282,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new TextFrame().setPayload(clone(buf))); expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect, 32, TimeUnit.SECONDS);
fuzzer.expect(expect,32,TimeUnit.SECONDS);
} }
} }
@ -317,12 +308,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(copyOf(data))); expect.add(new BinaryFrame().setPayload(copyOf(data)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -345,12 +335,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect);
} }
} }
@ -374,12 +363,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect,4,TimeUnit.SECONDS);
} }
} }
@ -403,12 +391,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect);
fuzzer.expect(expect,8,TimeUnit.SECONDS);
} }
} }
@ -432,12 +419,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect,16,TimeUnit.SECONDS);
fuzzer.expect(expect,16,TimeUnit.SECONDS);
} }
} }
@ -461,12 +447,11 @@ public class TestABCase9 extends AbstractABCase
expect.add(new BinaryFrame().setPayload(clone(buf))); expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame()); expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try(Fuzzer fuzzer = new Fuzzer(this)) try(Fuzzer.Session session = fuzzer.connect(this))
{ {
fuzzer.connect(); session.bulkMode();
fuzzer.setSendMode(Fuzzer.SendMode.BULK); session.send(send);
fuzzer.send(send); session.expect(expect,32,TimeUnit.SECONDS);
fuzzer.expect(expect,32,TimeUnit.SECONDS);
} }
} }

View File

@ -0,0 +1,50 @@
#
#
# ========================================================================
# Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
# ------------------------------------------------------------------------
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# and Apache License v2.0 which accompanies this distribution.
#
# The Eclipse Public License is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# The Apache License v2.0 is available at
# http://www.opensource.org/licenses/apache2.0.php
#
# You may elect to redistribute this code under either of these licenses.
# ========================================================================
#
#
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=WARN
# org.eclipse.jetty.io.WriteFlusher.LEVEL=DEBUG
# org.eclipse.jetty.websocket.LEVEL=DEBUG
# org.eclipse.jetty.websocket.LEVEL=INFO
org.eclipse.jetty.websocket.common.io.LEVEL=DEBUG
# org.eclipse.jetty.websocket.server.ab.LEVEL=DEBUG
org.eclipse.jetty.websocket.common.WebSocketSession.LEVEL=DEBUG
# org.eclipse.jetty.websocket.common.Parser.LEVEL=DEBUG
# org.eclipse.jetty.websocket.common.Generator.LEVEL=DEBUG
# org.eclipse.jetty.websocket.server.ab.Fuzzer.LEVEL=DEBUG
# org.eclipse.jetty.websocket.server.blockhead.LEVEL=DEBUG
# org.eclipse.jetty.websocket.server.helper.LEVEL=DEBUG
# org.eclipse.jetty.websocket.client.io.ConnectPromise.LEVEL=DEBUG
# org.eclipse.jetty.websocket.common.WebSocketSession_OPEN.LEVEL=DEBUG
# org.eclipse.jetty.websocket.common.io.IOState.LEVEL=DEBUG
# org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection_OPEN.LEVEL=DEBUG
### Show state changes on BrowserDebugTool
# -- LEAVE THIS AT DEBUG LEVEL --
org.eclipse.jetty.websocket.server.browser.LEVEL=DEBUG
### Disabling intentional error out of RFCSocket
org.eclipse.jetty.websocket.server.helper.RFCSocket.LEVEL=OFF
### Hiding Stack Traces from various test cases
org.eclipse.jetty.websocket.tests.server.ABSocket.STACKS=OFF
org.eclipse.jetty.websocket.server.WebSocketCloseTest$FastFailSocket.STACKS=OFF

13
pom.xml
View File

@ -947,7 +947,7 @@
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId> <artifactId>jetty-test-helper</artifactId>
<version>4.0</version> <version>4.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>
@ -1543,6 +1543,17 @@
<url>https://webtide.com</url> <url>https://webtide.com</url>
</organization> </organization>
<repositories>
<repository>
<id>jetty-snapshots</id>
<name>jetty-snapshots</name>
<url>http://oss.sonatype.org/content/repositories/jetty-snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement> <distributionManagement>
<repository> <repository>
<id>oss.sonatype.org</id> <id>oss.sonatype.org</id>