Turning on some leak detection in websocket testing

This commit is contained in:
Joakim Erdfelt 2014-01-08 14:54:57 -07:00
parent 36340c4898
commit 29dec203ba
37 changed files with 328 additions and 98 deletions

View File

@ -26,11 +26,13 @@ import java.util.Queue;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.jsr356.server.samples.beans.DateDecoder;
import org.eclipse.jetty.websocket.jsr356.server.samples.beans.TimeEncoder;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.ConfiguredEchoSocket;
@ -38,6 +40,7 @@ import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoSocketConfigur
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
/**
@ -45,6 +48,9 @@ import org.junit.Test;
*/
public class AnnotatedServerEndpointTest
{
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private static WSServer server;
@BeforeClass
@ -72,7 +78,7 @@ public class AnnotatedServerEndpointTest
private void assertResponse(String message, String... expectedTexts) throws Exception
{
WebSocketClient client = new WebSocketClient();
WebSocketClient client = new WebSocketClient(bufferPool);
try
{
client.start();

View File

@ -23,10 +23,12 @@ import java.util.Queue;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoEndpoint;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoEndpointConfigContextListener;
import org.junit.Assert;
@ -42,6 +44,9 @@ public class BasicEndpointTest
@Rule
public TestingDir testdir = new TestingDir();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
@Test
public void testEcho() throws Exception
{
@ -61,7 +66,7 @@ public class BasicEndpointTest
wsb.deployWebapp(webapp);
// wsb.dump();
WebSocketClient client = new WebSocketClient();
WebSocketClient client = new WebSocketClient(bufferPool);
try
{
client.start();

View File

@ -29,6 +29,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.util.log.Log;
@ -36,6 +37,7 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.jsr356.server.samples.idletimeout.IdleTimeoutContextListener;
import org.eclipse.jetty.websocket.jsr356.server.samples.idletimeout.OnOpenIdleTimeoutEndpoint;
import org.eclipse.jetty.websocket.jsr356.server.samples.idletimeout.OnOpenIdleTimeoutSocket;
@ -51,6 +53,9 @@ public class IdleTimeoutTest
@Rule
public TestingDir testdir = new TestingDir();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private static WSServer server;
@BeforeClass
@ -80,7 +85,7 @@ public class IdleTimeoutTest
private void assertConnectionTimeout(URI uri) throws Exception, IOException, InterruptedException, ExecutionException, TimeoutException
{
WebSocketClient client = new WebSocketClient();
WebSocketClient client = new WebSocketClient(bufferPool);
try
{
client.start();

View File

@ -25,10 +25,12 @@ import java.util.Queue;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoConfiguredSocket;
import org.junit.Assert;
import org.junit.Rule;
@ -42,6 +44,9 @@ public class LargeAnnotatedTest
@Rule
public TestingDir testdir = new TestingDir();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
@Test
public void testEcho() throws Exception
{
@ -58,7 +63,7 @@ public class LargeAnnotatedTest
wsb.deployWebapp(webapp);
// wsb.dump();
WebSocketClient client = new WebSocketClient();
WebSocketClient client = new WebSocketClient(bufferPool);
try
{
client.getPolicy().setMaxTextMessageSize(128*1024);

View File

@ -25,10 +25,12 @@ import java.util.Queue;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoDefaultSocket;
import org.junit.Assert;
import org.junit.Rule;
@ -42,6 +44,9 @@ public class LargeContainerTest
@Rule
public TestingDir testdir = new TestingDir();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
@Test
public void testEcho() throws Exception
{
@ -58,7 +63,7 @@ public class LargeContainerTest
wsb.deployWebapp(webapp);
// wsb.dump();
WebSocketClient client = new WebSocketClient();
WebSocketClient client = new WebSocketClient(bufferPool);
try
{
client.getPolicy().setMaxTextMessageSize(128*1024);

View File

@ -23,10 +23,12 @@ import java.util.Queue;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoReturnEndpoint;
import org.junit.Assert;
import org.junit.Rule;
@ -37,6 +39,9 @@ public class OnMessageReturnTest
@Rule
public TestingDir testdir = new TestingDir();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
@Test
public void testEchoReturn() throws Exception
{
@ -53,7 +58,7 @@ public class OnMessageReturnTest
wsb.deployWebapp(webapp);
wsb.dump();
WebSocketClient client = new WebSocketClient();
WebSocketClient client = new WebSocketClient(bufferPool);
try
{
client.start();

View File

@ -28,14 +28,17 @@ import java.util.Queue;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@ -95,6 +98,9 @@ public class SessionTest
return cases;
}
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private final Case testcase;
private WSServer server;
private URI serverUri;
@ -127,7 +133,7 @@ public class SessionTest
private void assertResponse(String requestPath, String requestMessage, String expectedResponse) throws Exception
{
WebSocketClient client = new WebSocketClient();
WebSocketClient client = new WebSocketClient(bufferPool);
try
{
client.start();

View File

@ -94,6 +94,11 @@ public class WebSocketClient extends ContainerLifeCycle implements SessionListen
{
this(null,executor);
}
public WebSocketClient(ByteBufferPool bufferPool)
{
this(null,null,bufferPool);
}
public WebSocketClient(SslContextFactory sslContextFactory)
{
@ -101,11 +106,16 @@ public class WebSocketClient extends ContainerLifeCycle implements SessionListen
}
public WebSocketClient(SslContextFactory sslContextFactory, Executor executor)
{
this(sslContextFactory,executor,new MappedByteBufferPool());
}
public WebSocketClient(SslContextFactory sslContextFactory, Executor executor, ByteBufferPool bufferPool)
{
this.executor = executor;
this.sslContextFactory = sslContextFactory;
this.policy = WebSocketPolicy.newClientPolicy();
this.bufferPool = new MappedByteBufferPool();
this.bufferPool = bufferPool;
this.extensionRegistry = new WebSocketExtensionFactory(policy,bufferPool);
this.masker = new RandomMasker();
this.eventDriverFactory = new EventDriverFactory(policy);

View File

@ -22,10 +22,12 @@ import java.net.URI;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.common.test.BlockheadServer.ServerConnection;
import org.junit.After;
import org.junit.Before;
@ -41,13 +43,16 @@ public class BadNetworkTest
@Rule
public TestTracker tt = new TestTracker();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private BlockheadServer server;
private WebSocketClient client;
@Before
public void startClient() throws Exception
{
client = new WebSocketClient();
client = new WebSocketClient(bufferPool);
client.getPolicy().setIdleTimeout(250);
client.start();
}

View File

@ -33,12 +33,14 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.OS;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.UpgradeException;
import org.eclipse.jetty.websocket.common.AcceptHash;
import org.eclipse.jetty.websocket.common.test.BlockheadServer;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.common.test.BlockheadServer.ServerConnection;
import org.junit.After;
import org.junit.Assert;
@ -55,6 +57,9 @@ public class ClientConnectTest
@Rule
public TestTracker tt = new TestTracker();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private final int timeout = 500;
private BlockheadServer server;
private WebSocketClient client;
@ -86,7 +91,7 @@ public class ClientConnectTest
@Before
public void startClient() throws Exception
{
client = new WebSocketClient();
client = new WebSocketClient(bufferPool);
client.setConnectTimeout(timeout);
client.start();
}

View File

@ -29,11 +29,13 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
/**
* This is not a general purpose websocket client. It's only for testing the websocket server and is hardwired to a specific draft version of the protocol.
@ -95,6 +97,8 @@ public class TestClient
private static final Random __random = new Random();
private static LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("TestClient",new MappedByteBufferPool());
private final String _host;
private final int _port;
private final String _protocol;
@ -172,7 +176,7 @@ public class TestClient
}
TestClient[] client = new TestClient[clients];
WebSocketClient wsclient = new WebSocketClient();
WebSocketClient wsclient = new WebSocketClient(bufferPool);
try
{
wsclient.start();
@ -250,6 +254,7 @@ public class TestClient
wsclient.stop();
}
bufferPool.assertNoLeaks();
}
private static void usage(String[] args)

View File

@ -18,27 +18,30 @@
package org.eclipse.jetty.websocket.common;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.common.test.IncomingFramesCapture;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
public class GeneratorParserRoundtripTest
{
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
@Test
public void testParserAndGenerator() throws Exception
{
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
ByteBufferPool bufferPool = new MappedByteBufferPool();
Generator gen = new Generator(policy,bufferPool);
Parser parser = new Parser(policy,bufferPool);
IncomingFramesCapture capture = new IncomingFramesCapture();
@ -77,7 +80,6 @@ public class GeneratorParserRoundtripTest
@Test
public void testParserAndGeneratorMasked() throws Exception
{
ByteBufferPool bufferPool = new MappedByteBufferPool();
Generator gen = new Generator(WebSocketPolicy.newClientPolicy(),bufferPool);
Parser parser = new Parser(WebSocketPolicy.newServerPolicy(),bufferPool);
IncomingFramesCapture capture = new IncomingFramesCapture();

View File

@ -18,11 +18,10 @@
package org.eclipse.jetty.websocket.common;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import java.nio.ByteBuffer;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.api.StatusCode;
@ -31,15 +30,20 @@ import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.common.frames.CloseFrame;
import org.eclipse.jetty.websocket.common.frames.PingFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.common.util.Hex;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
public class WebSocketFrameTest
{
private static Generator strictGenerator;
private static Generator laxGenerator;
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private Generator strictGenerator;
private Generator laxGenerator;
private ByteBuffer generateWholeFrame(Generator generator, Frame frame)
{
@ -49,11 +53,10 @@ public class WebSocketFrameTest
return buf;
}
@BeforeClass
public static void initGenerator()
@Before
public void initGenerator()
{
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
ByteBufferPool bufferPool = new MappedByteBufferPool();
strictGenerator = new Generator(policy,bufferPool);
laxGenerator = new Generator(policy,bufferPool,false);
}

View File

@ -23,7 +23,9 @@ import static org.hamcrest.Matchers.containsString;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture;
import org.junit.Assert;
import org.junit.Rule;
@ -35,10 +37,13 @@ public class WebSocketRemoteEndpointTest
@Rule
public TestName testname = new TestName();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
@Test
public void testTextBinaryText() throws IOException
{
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname,bufferPool);
OutgoingFramesCapture outgoing = new OutgoingFramesCapture();
WebSocketRemoteEndpoint remote = new WebSocketRemoteEndpoint(conn,outgoing);
conn.connect();
@ -68,7 +73,7 @@ public class WebSocketRemoteEndpointTest
@Test
public void testTextPingText() throws IOException
{
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname,bufferPool);
OutgoingFramesCapture outgoing = new OutgoingFramesCapture();
WebSocketRemoteEndpoint remote = new WebSocketRemoteEndpoint(conn,outgoing);
conn.connect();

View File

@ -25,11 +25,15 @@ import static org.hamcrest.Matchers.startsWith;
import java.util.regex.Pattern;
import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.junit.Assert;
@SuppressWarnings("serial")
public class EventCapture extends EventQueue<String>
{
private static final Logger LOG = Log.getLogger(EventCapture.class);
public static class Assertable
{
private final String event;
@ -63,7 +67,7 @@ public class EventCapture extends EventQueue<String>
public void add(String format, Object... args)
{
String msg = String.format(format,args);
System.err.printf("### EVENT: %s%n",msg);
LOG.debug("EVENT: {}",msg);
super.offer(msg);
}

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common.events;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
@ -30,6 +31,7 @@ import org.eclipse.jetty.websocket.common.frames.BinaryFrame;
import org.eclipse.jetty.websocket.common.frames.PingFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.io.LocalWebSocketSession;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
@ -46,6 +48,9 @@ public class EventDriverTest
@Rule
public TestName testname = new TestName();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private Frame makeBinaryFrame(String content, boolean fin)
{
return new BinaryFrame().setPayload(content).setFin(fin);
@ -57,7 +62,7 @@ public class EventDriverTest
AdapterConnectCloseSocket socket = new AdapterConnectCloseSocket();
EventDriver driver = wrap(socket);
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver))
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver,bufferPool))
{
conn.open();
driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
@ -74,7 +79,7 @@ public class EventDriverTest
AnnotatedBinaryArraySocket socket = new AnnotatedBinaryArraySocket();
EventDriver driver = wrap(socket);
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver))
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver,bufferPool))
{
conn.open();
driver.incomingFrame(makeBinaryFrame("Hello World",true));
@ -93,7 +98,7 @@ public class EventDriverTest
AnnotatedTextSocket socket = new AnnotatedTextSocket();
EventDriver driver = wrap(socket);
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver))
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver,bufferPool))
{
conn.open();
driver.incomingError(new WebSocketException("oof"));
@ -112,7 +117,7 @@ public class EventDriverTest
AnnotatedFramesSocket socket = new AnnotatedFramesSocket();
EventDriver driver = wrap(socket);
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver))
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver,bufferPool))
{
conn.open();
driver.incomingFrame(new PingFrame().setPayload("PING"));
@ -136,7 +141,7 @@ public class EventDriverTest
AnnotatedBinaryStreamSocket socket = new AnnotatedBinaryStreamSocket();
EventDriver driver = wrap(socket);
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver))
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver,bufferPool))
{
conn.open();
driver.incomingFrame(makeBinaryFrame("Hello World",true));
@ -155,7 +160,7 @@ public class EventDriverTest
ListenerBasicSocket socket = new ListenerBasicSocket();
EventDriver driver = wrap(socket);
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver))
try (LocalWebSocketSession conn = new LocalWebSocketSession(testname,driver,bufferPool))
{
conn.start();
conn.open();

View File

@ -18,10 +18,10 @@
package org.eclipse.jetty.websocket.common.extensions;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.junit.BeforeClass;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestName;
@ -29,15 +29,16 @@ public abstract class AbstractExtensionTest
{
@Rule
public TestName testname = new TestName();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private static ByteBufferPool bufferPool;
protected static ExtensionTool clientExtensions;
protected static ExtensionTool serverExtensions;
protected ExtensionTool clientExtensions;
protected ExtensionTool serverExtensions;
@BeforeClass
public static void init()
@Before
public void init()
{
bufferPool = new MappedByteBufferPool();
clientExtensions = new ExtensionTool(WebSocketPolicy.newClientPolicy(),bufferPool);
serverExtensions = new ExtensionTool(WebSocketPolicy.newServerPolicy(),bufferPool);
}

View File

@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.io.ArrayByteBufferPool;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
@ -32,12 +31,17 @@ import org.eclipse.jetty.websocket.api.extensions.Extension;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory;
import org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
public class ExtensionStackTest
{
private static final Logger LOG = Log.getLogger(ExtensionStackTest.class);
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new ArrayByteBufferPool());
@SuppressWarnings("unchecked")
private <T> T assertIsExtension(String msg, Object obj, Class<T> clazz)
@ -53,7 +57,6 @@ public class ExtensionStackTest
private ExtensionStack createExtensionStack()
{
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
ByteBufferPool bufferPool = new ArrayByteBufferPool();
ExtensionFactory factory = new WebSocketExtensionFactory(policy,bufferPool);
return new ExtensionStack(factory);
}

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.websocket.common.extensions;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -40,12 +40,17 @@ import org.eclipse.jetty.websocket.common.frames.PingFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.ByteBufferAssert;
import org.eclipse.jetty.websocket.common.test.IncomingFramesCapture;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
public class FragmentExtensionTest
{
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
/**
* Verify that incoming frames are passed thru without modification
*/
@ -55,7 +60,7 @@ public class FragmentExtensionTest
IncomingFramesCapture capture = new IncomingFramesCapture();
FragmentExtension ext = new FragmentExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newClientPolicy());
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4");
ext.setConfig(config);
@ -107,7 +112,7 @@ public class FragmentExtensionTest
IncomingFramesCapture capture = new IncomingFramesCapture();
FragmentExtension ext = new FragmentExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4");
ext.setConfig(config);
@ -142,7 +147,7 @@ public class FragmentExtensionTest
OutgoingFramesCapture capture = new OutgoingFramesCapture();
FragmentExtension ext = new FragmentExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=20");
ext.setConfig(config);
@ -173,7 +178,7 @@ public class FragmentExtensionTest
expectedFrames.add(new TextFrame().setPayload("-- Albert Einstein").setFin(true));
capture.dump();
// capture.dump();
int len = expectedFrames.size();
capture.assertFrameCount(len);
@ -186,8 +191,8 @@ public class FragmentExtensionTest
WebSocketFrame actualFrame = frames.get(i);
WebSocketFrame expectedFrame = expectedFrames.get(i);
System.out.printf("actual: %s%n",actualFrame);
System.out.printf("expect: %s%n",expectedFrame);
// System.out.printf("actual: %s%n",actualFrame);
// System.out.printf("expect: %s%n",expectedFrame);
// Validate Frame
Assert.assertThat(prefix + ".opcode",actualFrame.getOpCode(),is(expectedFrame.getOpCode()));
@ -214,7 +219,7 @@ public class FragmentExtensionTest
OutgoingFramesCapture capture = new OutgoingFramesCapture();
FragmentExtension ext = new FragmentExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("fragment");
ext.setConfig(config);
@ -278,7 +283,7 @@ public class FragmentExtensionTest
OutgoingFramesCapture capture = new OutgoingFramesCapture();
FragmentExtension ext = new FragmentExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4");
ext.setConfig(config);

View File

@ -28,7 +28,6 @@ import java.util.List;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
@ -45,19 +44,24 @@ import org.eclipse.jetty.websocket.common.extensions.ExtensionTool.Tester;
import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.ByteBufferAssert;
import org.eclipse.jetty.websocket.common.test.IncomingFramesCapture;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.common.test.OutgoingNetworkBytesCapture;
import org.eclipse.jetty.websocket.common.test.UnitParser;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
public class DeflateFrameExtensionTest extends AbstractExtensionTest
{
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private void assertIncoming(byte[] raw, String... expectedTextDatas)
{
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
DeflateFrameExtension ext = new DeflateFrameExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(policy);
ExtensionConfig config = ExtensionConfig.parse("deflate-frame");
@ -101,13 +105,12 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
DeflateFrameExtension ext = new DeflateFrameExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(policy);
ExtensionConfig config = ExtensionConfig.parse("deflate-frame");
ext.setConfig(config);
ByteBufferPool bufferPool = new MappedByteBufferPool();
boolean validating = true;
Generator generator = new Generator(policy,bufferPool,validating);
generator.configureFromExtensions(Collections.singletonList(ext));
@ -235,7 +238,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest
private void init(DeflateFrameExtension ext)
{
ext.setConfig(new ExtensionConfig(ext.getName()));
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
}
@Test
@ -290,11 +293,10 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
DeflateFrameExtension ext = new DeflateFrameExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(policy);
ext.setConfig(new ExtensionConfig(ext.getName()));
ByteBufferPool bufferPool = new MappedByteBufferPool();
boolean validating = true;
Generator generator = new Generator(policy,bufferPool,validating);
generator.configureFromExtensions(Collections.singletonList(ext));

View File

@ -40,8 +40,10 @@ import org.eclipse.jetty.websocket.common.frames.PingFrame;
import org.eclipse.jetty.websocket.common.frames.TextFrame;
import org.eclipse.jetty.websocket.common.test.ByteBufferAssert;
import org.eclipse.jetty.websocket.common.test.IncomingFramesCapture;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
/**
@ -51,6 +53,9 @@ import org.junit.Test;
*/
public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
{
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
/**
* Decode payload example as seen in draft-ietf-hybi-permessage-compression-15.
* <p>
@ -206,7 +211,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
public void testIncomingPing()
{
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.setConfig(config);
@ -243,7 +248,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
public void testIncomingUncompressedFrames()
{
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.setConfig(config);
@ -298,7 +303,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
public void testOutgoingPing() throws IOException
{
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ext.setBufferPool(new MappedByteBufferPool());
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.setConfig(config);

View File

@ -22,7 +22,6 @@ import java.net.InetSocketAddress;
import java.util.concurrent.Executor;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
@ -49,22 +48,22 @@ public class LocalWebSocketConnection implements LogicalConnection, IncomingFram
private IncomingFrames incoming;
private IOState ioState = new IOState();
public LocalWebSocketConnection()
public LocalWebSocketConnection(ByteBufferPool bufferPool)
{
this("anon");
this("anon",bufferPool);
}
public LocalWebSocketConnection(String id)
public LocalWebSocketConnection(String id, ByteBufferPool bufferPool)
{
this.id = id;
this.bufferPool = new MappedByteBufferPool();
this.bufferPool = bufferPool;
this.executor = new ExecutorThreadPool();
this.ioState.addListener(this);
}
public LocalWebSocketConnection(TestName testname)
public LocalWebSocketConnection(TestName testname, ByteBufferPool bufferPool)
{
this(testname.getMethodName());
this(testname.getMethodName(),bufferPool);
}
@Override

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.common.io;
import java.net.URI;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.websocket.common.SessionListener;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.events.EventDriver;
@ -31,9 +32,9 @@ public class LocalWebSocketSession extends WebSocketSession
private String id;
private OutgoingFramesCapture outgoingCapture;
public LocalWebSocketSession(TestName testname, EventDriver driver)
public LocalWebSocketSession(TestName testname, EventDriver driver, ByteBufferPool bufferPool)
{
super(URI.create("ws://localhost/LocalWebSocketSesssion/" + testname.getMethodName()),driver,new LocalWebSocketConnection(testname), new SessionListener[0]);
super(URI.create("ws://localhost/LocalWebSocketSesssion/" + testname.getMethodName()),driver,new LocalWebSocketConnection(testname,bufferPool), new SessionListener[0]);
this.id = testname.getMethodName();
outgoingCapture = new OutgoingFramesCapture();
setOutgoingHandler(outgoingCapture);

View File

@ -27,8 +27,10 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
@ -39,10 +41,13 @@ public class MessageInputStreamTest
@Rule
public TestName testname = new TestName();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
@Test(timeout=10000)
public void testBasicAppendRead() throws IOException
{
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname,bufferPool);
try (MessageInputStream stream = new MessageInputStream(conn))
{
@ -65,7 +70,7 @@ public class MessageInputStreamTest
@Test(timeout=5000)
public void testBlockOnRead() throws Exception
{
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname,bufferPool);
try (MessageInputStream stream = new MessageInputStream(conn))
{
@ -116,7 +121,7 @@ public class MessageInputStreamTest
@Test(timeout=10000)
public void testBlockOnReadInitial() throws IOException
{
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname,bufferPool);
try (MessageInputStream stream = new MessageInputStream(conn))
{
@ -155,7 +160,7 @@ public class MessageInputStreamTest
@Test(timeout=10000)
public void testReadByteNoBuffersClosed() throws IOException
{
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname,bufferPool);
try (MessageInputStream stream = new MessageInputStream(conn))
{

View File

@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.is;
import java.util.Arrays;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -33,6 +34,7 @@ import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.eclipse.jetty.websocket.common.events.EventDriverFactory;
import org.eclipse.jetty.websocket.common.io.FramePipes;
import org.eclipse.jetty.websocket.common.io.LocalWebSocketSession;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -50,6 +52,9 @@ public class MessageOutputStreamTest
@Rule
public TestName testname = new TestName();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private WebSocketPolicy policy;
private TrackingSocket socket;
private LocalWebSocketSession session;
@ -77,7 +82,7 @@ public class MessageOutputStreamTest
socket = new TrackingSocket("remote");
OutgoingFrames socketPipe = FramePipes.to(factory.wrap(socket));
session = new LocalWebSocketSession(testname,driver);
session = new LocalWebSocketSession(testname,driver,bufferPool);
session.setPolicy(policy);
// talk to our remote socket

View File

@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.is;
import java.util.Arrays;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -31,6 +32,7 @@ import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.eclipse.jetty.websocket.common.events.EventDriverFactory;
import org.eclipse.jetty.websocket.common.io.FramePipes;
import org.eclipse.jetty.websocket.common.io.LocalWebSocketSession;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -48,6 +50,9 @@ public class MessageWriterTest
@Rule
public TestName testname = new TestName();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private WebSocketPolicy policy;
private TrackingSocket socket;
private LocalWebSocketSession session;
@ -75,7 +80,7 @@ public class MessageWriterTest
socket = new TrackingSocket("remote");
OutgoingFrames socketPipe = FramePipes.to(factory.wrap(socket));
session = new LocalWebSocketSession(testname,driver);
session = new LocalWebSocketSession(testname,driver,bufferPool);
session.setPolicy(policy);
// talk to our remote socket

View File

@ -133,6 +133,7 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames, Connecti
LOG.debug("WebSocket URI: {}",destWebsocketURI);
LOG.debug(" HTTP URI: {}",destHttpURI);
// This is a blockhead client, no point tracking leaks on this object.
this.bufferPool = new MappedByteBufferPool(8192);
this.generator = new Generator(policy,bufferPool);
this.parser = new Parser(policy,bufferPool);

View File

@ -102,6 +102,7 @@ public class BlockheadServer
this.policy = WebSocketPolicy.newServerPolicy();
this.policy.setMaxBinaryMessageSize(100000);
this.policy.setMaxTextMessageSize(100000);
// This is a blockhead server connection, no point tracking leaks on this object.
this.bufferPool = new MappedByteBufferPool(BUFFER_SIZE);
this.parser = new Parser(policy,bufferPool);
this.parseCount = new AtomicInteger(0);

View File

@ -0,0 +1,80 @@
//
// ========================================================================
// Copyright (c) 1995-2014 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 static org.hamcrest.Matchers.*;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.LeakTrackingByteBufferPool;
import org.eclipse.jetty.util.LeakDetector;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.junit.Assert;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
public class LeakTrackingBufferPool extends LeakTrackingByteBufferPool implements TestRule
{
private static final Logger LOG = Log.getLogger(LeakTrackingBufferPool.class);
private final String id;
private AtomicInteger leakCount = new AtomicInteger(0);
public LeakTrackingBufferPool(String id, ByteBufferPool delegate)
{
super(delegate);
this.id = id;
}
@Override
protected void leaked(LeakDetector<ByteBuffer>.LeakInfo leakInfo)
{
String msg = String.format("%s ByteBuffer %s leaked at:",id,leakInfo.getResourceDescription());
LOG.warn(msg,leakInfo.getStackFrames());
leakCount.incrementAndGet();
}
public void assertNoLeaks()
{
Assert.assertThat("Leak Count for [" + id + "]",leakCount.get(),is(0));
}
public void clearTracking()
{
leakCount.set(0);
}
@Override
public Statement apply(final Statement statement, Description description)
{
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
clearTracking();
statement.evaluate();
assertNoLeaks();
}
};
}
}

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common.test;
import java.nio.ByteBuffer;
import java.util.List;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
@ -122,6 +123,11 @@ public class UnitGenerator extends Generator
public UnitGenerator()
{
super(WebSocketPolicy.newServerPolicy(),new MappedByteBufferPool());
super(WebSocketPolicy.newServerPolicy(),new LeakTrackingBufferPool("UnitGenerator",new MappedByteBufferPool()));
}
public UnitGenerator(ByteBufferPool bufferPool)
{
super(WebSocketPolicy.newServerPolicy(),bufferPool);
}
}

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.websocket.common.test;
import java.nio.ByteBuffer;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.log.StacklessLogging;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
@ -33,14 +32,9 @@ public class UnitParser extends Parser
this(WebSocketPolicy.newServerPolicy());
}
public UnitParser(ByteBufferPool bufferPool, WebSocketPolicy policy)
{
super(policy,bufferPool);
}
public UnitParser(WebSocketPolicy policy)
{
this(new MappedByteBufferPool(),policy);
super(policy,new LeakTrackingBufferPool("UnitParser",new MappedByteBufferPool()));
}
private void parsePartial(ByteBuffer buf, int numBytes)

View File

@ -24,6 +24,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
@ -55,10 +57,15 @@ public abstract class WebSocketHandler extends HandlerWrapper
private final WebSocketServletFactory webSocketFactory;
public WebSocketHandler()
{
this(new MappedByteBufferPool());
}
public WebSocketHandler(ByteBufferPool bufferPool)
{
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
configurePolicy(policy);
webSocketFactory = new WebSocketServerFactory(policy);
webSocketFactory = new WebSocketServerFactory(policy, bufferPool);
addBean(webSocketFactory);
}

View File

@ -96,6 +96,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
private final String supportedVersions;
private final WebSocketPolicy defaultPolicy;
private final EventDriverFactory eventDriverFactory;
private final ByteBufferPool bufferPool;
private final WebSocketExtensionFactory extensionFactory;
private List<SessionFactory> sessionFactories;
private Set<WebSocketSession> openSessions = new CopyOnWriteArraySet<>();
@ -111,6 +112,11 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
{
this(policy,new MappedByteBufferPool());
}
public WebSocketServerFactory(ByteBufferPool bufferPool)
{
this(WebSocketPolicy.newServerPolicy(),bufferPool);
}
public WebSocketServerFactory(WebSocketPolicy policy, ByteBufferPool bufferPool)
{
@ -121,7 +127,8 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
this.defaultPolicy = policy;
this.eventDriverFactory = new EventDriverFactory(defaultPolicy);
this.extensionFactory = new WebSocketExtensionFactory(defaultPolicy,bufferPool);
this.bufferPool = bufferPool;
this.extensionFactory = new WebSocketExtensionFactory(defaultPolicy,this.bufferPool);
this.sessionFactories = new ArrayList<>();
this.sessionFactories.add(new WebSocketSessionFactory(this));
this.creator = this;
@ -228,7 +235,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
@Override
public WebSocketServletFactory createFactory(WebSocketPolicy policy)
{
return new WebSocketServerFactory(policy);
return new WebSocketServerFactory(policy,bufferPool);
}
private WebSocketSession createSession(URI requestURI, EventDriver websocket, LogicalConnection connection)

View File

@ -31,6 +31,8 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
@ -77,7 +79,12 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
public WebSocketUpgradeFilter(WebSocketPolicy policy)
{
factory = new WebSocketServerFactory(policy);
this(policy, new MappedByteBufferPool());
}
public WebSocketUpgradeFilter(WebSocketPolicy policy, ByteBufferPool bufferPool)
{
factory = new WebSocketServerFactory(policy,bufferPool);
addBean(factory,true);
}

View File

@ -24,6 +24,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.websocket.server.pathmap.PathMappings;
@ -38,7 +40,12 @@ public class WebSocketUpgradeHandlerWrapper extends HandlerWrapper implements Ma
public WebSocketUpgradeHandlerWrapper()
{
factory = new WebSocketServerFactory();
this(new MappedByteBufferPool());
}
public WebSocketUpgradeHandlerWrapper(ByteBufferPool bufferPool)
{
factory = new WebSocketServerFactory(bufferPool);
}
@Override

View File

@ -24,10 +24,12 @@ import java.net.URI;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.server.helper.CaptureSocket;
import org.eclipse.jetty.websocket.server.helper.SessionServlet;
import org.junit.AfterClass;
@ -41,6 +43,9 @@ public class WebSocketOverSSLTest
@Rule
public TestTracker tracker = new TestTracker();
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
private static SimpleServletServer server;
@BeforeClass
@ -64,7 +69,7 @@ public class WebSocketOverSSLTest
public void testEcho() throws Exception
{
Assert.assertThat("server scheme",server.getServerUri().getScheme(),is("wss"));
WebSocketClient client = new WebSocketClient(server.getSslContextFactory());
WebSocketClient client = new WebSocketClient(server.getSslContextFactory(),null,bufferPool);
try
{
client.start();
@ -102,7 +107,7 @@ public class WebSocketOverSSLTest
public void testServerSessionIsSecure() throws Exception
{
Assert.assertThat("server scheme",server.getServerUri().getScheme(),is("wss"));
WebSocketClient client = new WebSocketClient(server.getSslContextFactory());
WebSocketClient client = new WebSocketClient(server.getSslContextFactory(),null,bufferPool);
try
{
client.setConnectTimeout(3000);
@ -140,7 +145,7 @@ public class WebSocketOverSSLTest
public void testServerSessionRequestURI() throws Exception
{
Assert.assertThat("server scheme",server.getServerUri().getScheme(),is("wss"));
WebSocketClient client = new WebSocketClient(server.getSslContextFactory());
WebSocketClient client = new WebSocketClient(server.getSslContextFactory(),null,bufferPool);
try
{
client.setConnectTimeout(3000);

View File

@ -21,7 +21,6 @@ package org.eclipse.jetty.websocket.server.ab;
import java.net.URI;
import java.nio.ByteBuffer;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
@ -31,9 +30,11 @@ import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.test.Fuzzed;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool;
import org.eclipse.jetty.websocket.common.test.RawFrameBuilder;
import org.eclipse.jetty.websocket.server.SimpleServletServer;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TestName;
@ -73,15 +74,17 @@ public abstract class AbstractABCase implements Fuzzed
protected static final byte[] MASK =
{ 0x12, 0x34, 0x56, 0x78 };
protected static Generator strictGenerator;
protected static Generator laxGenerator;
protected Generator strictGenerator;
protected Generator laxGenerator;
protected static SimpleServletServer server;
@BeforeClass
public static void initGenerators()
@Rule
public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool());
@Before
public void initGenerators()
{
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
ByteBufferPool bufferPool = new MappedByteBufferPool();
strictGenerator = new Generator(policy,bufferPool,true);
laxGenerator = new Generator(policy,bufferPool,false);
}