From 752fda19b9edcf9ea82e0d964261c45323f961c7 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 6 Sep 2017 10:14:49 -0700 Subject: [PATCH 1/5] Fixes #1767 - removing debug output from testing --- .../jetty/websocket/jsr356/DelayedStartClientTest.java | 4 ---- .../eclipse/jetty/websocket/jsr356/decoders/TimeDecoder.java | 1 - .../jsr356/server/DelayedStartClientOnServerTest.java | 4 ---- 3 files changed, 9 deletions(-) diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java index a62b1841a04..f35cb6436cf 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java @@ -97,10 +97,6 @@ public class DelayedStartClientTest QueuedThreadPool qtp = (QueuedThreadPool) executor; threadNames.add(qtp.getName()); } - else - { - System.err.println("### Executor: " + executor); - } } for (ContainerLifeCycle child : container.getBeans(ContainerLifeCycle.class)) diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/decoders/TimeDecoder.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/decoders/TimeDecoder.java index cfd43d2ca17..69e04354778 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/decoders/TimeDecoder.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/decoders/TimeDecoder.java @@ -52,7 +52,6 @@ public class TimeDecoder implements Decoder.Text @Override public void init(EndpointConfig config) { - System.out.println("#### INIT ####"); } @Override diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java index 602e8920a6d..f703177962a 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java @@ -380,10 +380,6 @@ public class DelayedStartClientOnServerTest QueuedThreadPool qtp = (QueuedThreadPool) executor; threadNames.add(qtp.getName()); } - else - { - System.err.println("### Executor: " + executor); - } } for (ContainerLifeCycle child : container.getBeans(ContainerLifeCycle.class)) From acc7c97969de94b3f64c8644e8271f7721bfa6f3 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 6 Sep 2017 10:16:32 -0700 Subject: [PATCH 2/5] Removing @Rule LeakTrackingBufferPoolRule - bad threading behavior / false positives --- .../jsr356/server/AltFilterTest.java | 6 +- .../server/AnnotatedServerEndpointTest.java | 6 +- .../jsr356/server/BasicEndpointTest.java | 6 +- .../jsr356/server/LargeAnnotatedTest.java | 6 +- .../jsr356/server/LargeContainerTest.java | 6 +- .../jsr356/server/OnMessageReturnTest.java | 6 +- .../websocket/jsr356/server/SessionTest.java | 11 ++-- .../websocket/jsr356/server/StreamTest.java | 6 +- .../websocket/client/BadNetworkTest.java | 6 +- .../websocket/client/ClientConnectTest.java | 6 +- .../websocket/client/examples/TestClient.java | 6 +- .../common/GeneratorParserRoundtripTest.java | 7 +-- .../websocket/common/WebSocketFrameTest.java | 7 +-- .../common/WebSocketRemoteEndpointTest.java | 6 +- .../common/events/EventDriverTest.java | 6 +- .../extensions/AbstractExtensionTest.java | 8 +-- .../common/extensions/ExtensionStackTest.java | 9 ++- .../extensions/FragmentExtensionTest.java | 7 +-- .../compress/DeflateFrameExtensionTest.java | 9 ++- .../PerMessageDeflateExtensionTest.java | 9 ++- .../message/MessageInputStreamTest.java | 6 +- .../message/MessageOutputStreamTest.java | 6 +- .../common/message/MessageWriterTest.java | 6 +- .../test/LeakTrackingBufferPoolRule.java | 61 ------------------- .../websocket/server/TooFastClientTest.java | 5 +- .../server/WebSocketOverSSLTest.java | 10 ++- .../websocket/server/ab/AbstractABCase.java | 6 +- 27 files changed, 85 insertions(+), 154 deletions(-) delete mode 100644 jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPoolRule.java diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/AltFilterTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/AltFilterTest.java index 734f7581022..e3335c405c8 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/AltFilterTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/AltFilterTest.java @@ -27,12 +27,13 @@ import java.util.Queue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.io.ByteBufferPool; +import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.servlet.FilterHolder; 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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoSocket; import org.junit.Assert; import org.junit.Rule; @@ -47,8 +48,7 @@ public class AltFilterTest @Rule public TestingDir testdir = new TestingDir(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @Test public void testEcho() throws Exception diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/AnnotatedServerEndpointTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/AnnotatedServerEndpointTest.java index 139e46e0278..609896a4fd4 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/AnnotatedServerEndpointTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/AnnotatedServerEndpointTest.java @@ -26,12 +26,13 @@ import java.util.Queue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.io.ByteBufferPool; +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.LeakTrackingBufferPoolRule; 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; @@ -47,8 +48,7 @@ import org.junit.Test; */ public class AnnotatedServerEndpointTest { - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private static WSServer server; diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/BasicEndpointTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/BasicEndpointTest.java index b581c41c66e..5bac0c41070 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/BasicEndpointTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/BasicEndpointTest.java @@ -23,11 +23,12 @@ import java.util.Queue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.io.ByteBufferPool; +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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoEndpoint; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoEndpointConfigContextListener; import org.junit.Assert; @@ -43,8 +44,7 @@ public class BasicEndpointTest @Rule public TestingDir testdir = new TestingDir(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @Test public void testEcho() throws Exception diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeAnnotatedTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeAnnotatedTest.java index 345ae7cebdf..6ea43d17ae4 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeAnnotatedTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeAnnotatedTest.java @@ -25,11 +25,12 @@ import java.util.Queue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.io.ByteBufferPool; +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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoConfiguredSocket; import org.junit.Assert; import org.junit.Ignore; @@ -45,8 +46,7 @@ public class LargeAnnotatedTest @Rule public TestingDir testdir = new TestingDir(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @Test public void testEcho() throws Exception diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeContainerTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeContainerTest.java index cc79c5a2a6d..732940bab91 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeContainerTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeContainerTest.java @@ -25,11 +25,12 @@ import java.util.Queue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.io.ByteBufferPool; +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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoDefaultSocket; import org.junit.Assert; import org.junit.Ignore; @@ -45,8 +46,7 @@ public class LargeContainerTest @Rule public TestingDir testdir = new TestingDir(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @Test public void testEcho() throws Exception diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/OnMessageReturnTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/OnMessageReturnTest.java index d3ceed86e03..831322c2504 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/OnMessageReturnTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/OnMessageReturnTest.java @@ -23,11 +23,12 @@ import java.util.Queue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.io.ByteBufferPool; +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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoReturnEndpoint; import org.junit.Assert; import org.junit.Rule; @@ -38,8 +39,7 @@ public class OnMessageReturnTest @Rule public TestingDir testdir = new TestingDir(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @Test public void testEchoReturn() throws Exception diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionTest.java index 2d685294b61..d36b56a1213 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionTest.java @@ -29,16 +29,16 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import org.eclipse.jetty.io.ByteBufferPool; +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.LeakTrackingBufferPoolRule; 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; @@ -47,9 +47,9 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class SessionTest { - private static interface Case + private interface Case { - public void customize(WebAppContext context); + void customize(WebAppContext context); } @Parameters @@ -98,8 +98,7 @@ public class SessionTest return cases; } - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private final Case testcase; private final static AtomicInteger ID = new AtomicInteger(0); diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/StreamTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/StreamTest.java index 8b7ac25ba8d..c1d972fe39a 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/StreamTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/StreamTest.java @@ -50,6 +50,8 @@ import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpointConfig; +import org.eclipse.jetty.io.ByteBufferPool; +import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; @@ -58,7 +60,6 @@ import org.eclipse.jetty.toolchain.test.IO; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.util.Sha1Sum; import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; import org.junit.AfterClass; @@ -71,8 +72,7 @@ public class StreamTest { private static final Logger LOG = Log.getLogger(StreamTest.class); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private static File outputDir; private static Server server; diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java index e21b11d660e..338f5e718a6 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java @@ -22,12 +22,13 @@ import java.net.URI; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.io.ByteBufferPool; +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.IBlockheadServerConnection; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -41,8 +42,7 @@ public class BadNetworkTest @Rule public TestTracker tt = new TestTracker(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private BlockheadServer server; private WebSocketClient client; diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java index 77647fe59e9..5af08c4deeb 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java @@ -37,13 +37,14 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.io.ByteBufferPool; +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.UpgradeException; 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.LeakTrackingBufferPoolRule; import org.hamcrest.Matcher; import org.junit.After; import org.junit.Assert; @@ -60,8 +61,7 @@ public class ClientConnectTest @Rule public TestTracker tt = new TestTracker(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private final int timeout = 500; private BlockheadServer server; diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java index def25cf9134..0cd6c323728 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java @@ -29,12 +29,14 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; +import org.eclipse.jetty.io.ByteBufferPool; +import org.eclipse.jetty.io.LeakTrackingByteBufferPool; +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.LeakTrackingBufferPoolRule; /** * 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. @@ -96,7 +98,7 @@ public class TestClient private static final Random __random = new Random(); - private static LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("TestClient"); + private static LeakTrackingByteBufferPool bufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool()); private final String _host; private final int _port; diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/GeneratorParserRoundtripTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/GeneratorParserRoundtripTest.java index b8d915af057..1c7c5c3acaa 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/GeneratorParserRoundtripTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/GeneratorParserRoundtripTest.java @@ -23,19 +23,18 @@ import static org.hamcrest.Matchers.is; 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.IncomingFramesCapture; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.Assert; -import org.junit.Rule; import org.junit.Test; public class GeneratorParserRoundtripTest { - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("GeneratorParserRoundtrip"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @Test public void testParserAndGenerator() throws Exception diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/WebSocketFrameTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/WebSocketFrameTest.java index 04f2b98f368..bada1e4556c 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/WebSocketFrameTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/WebSocketFrameTest.java @@ -22,6 +22,8 @@ import static org.hamcrest.Matchers.is; 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; import org.eclipse.jetty.websocket.api.WebSocketPolicy; @@ -29,17 +31,14 @@ 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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.util.Hex; import org.junit.Assert; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; public class WebSocketFrameTest { - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("WebSocketFrameTest"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private Generator strictGenerator; private Generator laxGenerator; diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/WebSocketRemoteEndpointTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/WebSocketRemoteEndpointTest.java index 854cb126fbe..8507c48d32c 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/WebSocketRemoteEndpointTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/WebSocketRemoteEndpointTest.java @@ -23,8 +23,9 @@ import static org.hamcrest.Matchers.containsString; import java.io.IOException; import java.nio.ByteBuffer; +import org.eclipse.jetty.io.ByteBufferPool; +import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture; import org.junit.Assert; import org.junit.Rule; @@ -36,8 +37,7 @@ public class WebSocketRemoteEndpointTest @Rule public TestName testname = new TestName(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("WebSocketRemoteEndpoint"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @Test public void testTextBinaryText() throws IOException diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/events/EventDriverTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/events/EventDriverTest.java index 563359d404e..d6a8fbccb9c 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/events/EventDriverTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/events/EventDriverTest.java @@ -21,6 +21,8 @@ package org.eclipse.jetty.websocket.common.events; import java.io.IOException; import java.util.concurrent.TimeoutException; +import org.eclipse.jetty.io.ByteBufferPool; +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; @@ -34,7 +36,6 @@ import org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession; import org.eclipse.jetty.websocket.common.io.LocalWebSocketSession; import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope; import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -53,8 +54,7 @@ public class EventDriverTest @Rule public TestName testname = new TestName(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private WebSocketContainerScope container; diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtensionTest.java index a3ea02505c6..112d9ee221c 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtensionTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtensionTest.java @@ -18,8 +18,9 @@ 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.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestName; @@ -28,9 +29,8 @@ public abstract class AbstractExtensionTest { @Rule public TestName testname = new TestName(); - - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + + public ByteBufferPool bufferPool = new MappedByteBufferPool(); protected ExtensionTool clientExtensions; protected ExtensionTool serverExtensions; diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/ExtensionStackTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/ExtensionStackTest.java index 5ac1b7474da..6b0036aceb5 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/ExtensionStackTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/ExtensionStackTest.java @@ -23,6 +23,8 @@ import static org.hamcrest.Matchers.is; import java.util.ArrayList; import java.util.List; +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.websocket.api.WebSocketPolicy; @@ -31,17 +33,14 @@ import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; import org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension; import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope; import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; 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 LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @SuppressWarnings("unchecked") private T assertIsExtension(String msg, Object obj, Class clazz) diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/FragmentExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/FragmentExtensionTest.java index 7e3898b7895..bed16555594 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/FragmentExtensionTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/FragmentExtensionTest.java @@ -27,6 +27,8 @@ import java.util.ArrayList; import java.util.LinkedList; 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.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.WebSocketPolicy; @@ -40,16 +42,13 @@ 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.LeakTrackingBufferPoolRule; 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 LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); /** * Verify that incoming frames are passed thru without modification diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java index e930452d2d4..31d0cd088ca 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java @@ -32,6 +32,8 @@ import java.util.Random; 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.io.RuntimeIOException; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; @@ -55,19 +57,16 @@ import org.eclipse.jetty.websocket.common.frames.BinaryFrame; 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.LeakTrackingBufferPoolRule; 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 { private static final Logger LOG = Log.getLogger(DeflateFrameExtensionTest.class); - - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private void assertIncoming(byte[] raw, String... expectedTextDatas) { diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java index 3486a4b9998..4c3b0a71b66 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java @@ -19,7 +19,7 @@ package org.eclipse.jetty.websocket.common.extensions.compress; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; import java.io.IOException; import java.nio.ByteBuffer; @@ -27,6 +27,8 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; 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.TypeUtil; import org.eclipse.jetty.websocket.api.BatchMode; @@ -42,10 +44,8 @@ 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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture; import org.junit.Assert; -import org.junit.Rule; import org.junit.Test; /** @@ -55,8 +55,7 @@ import org.junit.Test; */ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest { - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private void assertEndsWithTail(String hexStr, boolean expectedResult) { diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageInputStreamTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageInputStreamTest.java index 2254ae2a777..b875cb58118 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageInputStreamTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageInputStreamTest.java @@ -27,8 +27,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import org.eclipse.jetty.io.ByteBufferPool; +import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -39,8 +40,7 @@ public class MessageInputStreamTest @Rule public TestName testname = new TestName(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @Test(timeout=10000) public void testBasicAppendRead() throws IOException diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageOutputStreamTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageOutputStreamTest.java index a4a1bda7eed..69dbcbc0c4f 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageOutputStreamTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageOutputStreamTest.java @@ -24,6 +24,8 @@ import static org.hamcrest.Matchers.is; import java.util.Arrays; +import org.eclipse.jetty.io.ByteBufferPool; +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; @@ -35,7 +37,6 @@ import org.eclipse.jetty.websocket.common.io.FramePipes; import org.eclipse.jetty.websocket.common.io.LocalWebSocketSession; import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope; import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -53,8 +54,7 @@ public class MessageOutputStreamTest @Rule public TestName testname = new TestName(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private WebSocketPolicy policy; private TrackingSocket socket; diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageWriterTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageWriterTest.java index 24ac2898cc9..a094557819d 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageWriterTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageWriterTest.java @@ -22,6 +22,8 @@ import static org.hamcrest.Matchers.is; import java.util.Arrays; +import org.eclipse.jetty.io.ByteBufferPool; +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,7 +35,6 @@ import org.eclipse.jetty.websocket.common.io.FramePipes; import org.eclipse.jetty.websocket.common.io.LocalWebSocketSession; import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope; import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -51,8 +52,7 @@ public class MessageWriterTest @Rule public TestName testname = new TestName(); - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private WebSocketPolicy policy; private TrackingSocket socket; diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPoolRule.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPoolRule.java deleted file mode 100644 index f5d381f724b..00000000000 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPoolRule.java +++ /dev/null @@ -1,61 +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.common.test; - -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(); - } - }; - } -} diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/TooFastClientTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/TooFastClientTest.java index 8337ddcc1c9..424f0c7cd13 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/TooFastClientTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/TooFastClientTest.java @@ -34,13 +34,12 @@ import org.eclipse.jetty.websocket.common.Generator; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.frames.TextFrame; import org.eclipse.jetty.websocket.common.test.BlockheadClient; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; -import org.junit.Test; import org.junit.Ignore; +import org.junit.Test; /** * Test simulating a client that talks too quickly. @@ -85,7 +84,7 @@ public class TooFastClientTest // Add text frames Generator generator = new Generator(WebSocketPolicy.newClientPolicy(), - new LeakTrackingBufferPoolRule("Generator")); + new MappedByteBufferPool()); String msg1 = "Echo 1"; String msg2 = "This is also an echooooo!"; diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java index bfeb1fa4581..d8c69dfb738 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java @@ -19,20 +19,19 @@ package org.eclipse.jetty.websocket.server; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; import java.net.URI; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.io.ByteBufferPool; +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.BatchMode; import org.eclipse.jetty.websocket.api.RemoteEndpoint; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.client.WebSocketClient; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.server.helper.CaptureSocket; import org.eclipse.jetty.websocket.server.helper.SessionServlet; import org.junit.AfterClass; @@ -47,9 +46,8 @@ public class WebSocketOverSSLTest public static final int FUTURE_TIMEOUT_SEC = 30; @Rule public TestTracker tracker = new TestTracker(); - - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + + public ByteBufferPool bufferPool = new MappedByteBufferPool(); private static SimpleServletServer server; diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/AbstractABCase.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/AbstractABCase.java index 5dea3e36a44..ef5c7023e30 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/AbstractABCase.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/AbstractABCase.java @@ -22,6 +22,8 @@ import java.net.URI; 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.util.StringUtil; import org.eclipse.jetty.util.log.StacklessLogging; @@ -31,7 +33,6 @@ 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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.RawFrameBuilder; import org.eclipse.jetty.websocket.server.SimpleServletServer; import org.junit.AfterClass; @@ -79,8 +80,7 @@ public abstract class AbstractABCase implements Fuzzed protected Generator laxGenerator; protected static SimpleServletServer server; - @Rule - public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); + public ByteBufferPool bufferPool = new MappedByteBufferPool(); @Before public void initGenerators() From db773055502593f7e0209de167ac67d2fe1a2532 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 6 Sep 2017 10:22:12 -0700 Subject: [PATCH 3/5] Fixes #1756 - improving javadoc for WebSocketPolicy max text/binary message size --- .../jetty/websocket/api/WebSocketPolicy.java | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPolicy.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPolicy.java index a7d0ebfd882..aaeec58bd7d 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPolicy.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPolicy.java @@ -205,9 +205,15 @@ public class WebSocketPolicy } /** - * Get the maximum size of a binary message during parsing/generating. + * Get the maximum size of a binary message during parsing. *

- * Binary messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} + * This is a memory conservation option, memory over this limit will not be + * allocated by Jetty for handling binary messages. This applies to individual frames, + * whole message handling, and partial message handling. + *

+ *

+ * Binary messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} + *

* * @return the maximum size of a binary message */ @@ -227,9 +233,15 @@ public class WebSocketPolicy } /** - * Get the maximum size of a text message during parsing/generating. + * Get the maximum size of a text message during parsing. *

- * Text messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} + * This is a memory conservation option, memory over this limit will not be + * allocated by Jetty for handling text messages. This applies to individual frames, + * whole message handling, and partial message handling. + *

+ *

+ * Text messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} + *

* * @return the maximum size of a text message. */ @@ -279,7 +291,7 @@ public class WebSocketPolicy /** * The maximum size of a binary message buffer. *

- * Used ONLY for stream based message writing. + * Used ONLY for stream based binary message writing. * * @param size * the maximum size of the binary message buffer @@ -292,9 +304,15 @@ public class WebSocketPolicy } /** - * The maximum size of a binary message during parsing/generating. + * The maximum size of a binary message during parsing. *

- * Binary messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} + * This is a memory conservation option, memory over this limit will not be + * allocated by Jetty for handling binary messages. This applies to individual frames, + * whole message handling, and partial message handling. + *

+ *

+ * Binary messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} + *

* * @param size * the maximum allowed size of a binary message. @@ -309,7 +327,7 @@ public class WebSocketPolicy /** * The maximum size of a text message buffer. *

- * Used ONLY for stream based message writing. + * Used ONLY for stream based text message writing. * * @param size * the maximum size of the text message buffer @@ -322,9 +340,15 @@ public class WebSocketPolicy } /** - * The maximum size of a text message during parsing/generating. + * The maximum size of a text message during parsing. *

- * Text messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} + * This is a memory conservation option, memory over this limit will not be + * allocated by Jetty for handling text messages. This applies to individual frames, + * whole message handling, and partial message handling. + *

+ *

+ * Text messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} + *

* * @param size * the maximum allowed size of a text message. From 28d2f30769391d20d3e71337b40a1c587559c215 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 6 Sep 2017 10:24:47 -0700 Subject: [PATCH 4/5] Fixing compilation error --- .../org/eclipse/jetty/websocket/client/examples/TestClient.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java index 0cd6c323728..7cc612b04fc 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java @@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.LeakTrackingByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.websocket.api.Session; @@ -255,7 +254,6 @@ public class TestClient wsclient.stop(); } - bufferPool.assertNoLeaks(); } private static void usage(String[] args) From 45a4b87a33ffe9e2115a0fc5db9bd5bef473288c Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 6 Sep 2017 10:57:28 -0700 Subject: [PATCH 5/5] Fixes #1662 - Removing harmless NPE on websocket compress with null frame payload --- .../common/extensions/compress/CompressExtension.java | 8 ++++++-- .../extensions/compress/DeflateFrameExtensionTest.java | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java index 3ed6848ddf0..9a60ac39693 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java @@ -264,7 +264,7 @@ public abstract class CompressExtension extends AbstractExtension private static boolean supplyInput(Inflater inflater, ByteBuffer buf) { - if (buf.remaining() <= 0) + if (buf == null || buf.remaining() <= 0) { if (LOG.isDebugEnabled()) { @@ -304,7 +304,7 @@ public abstract class CompressExtension extends AbstractExtension private static boolean supplyInput(Deflater deflater, ByteBuffer buf) { - if (buf.remaining() <= 0) + if (buf == null || buf.remaining() <= 0) { if (LOG.isDebugEnabled()) { @@ -457,6 +457,10 @@ public abstract class CompressExtension extends AbstractExtension // the heap if the payload is a huge mapped file. Frame frame = entry.frame; ByteBuffer data = frame.getPayload(); + + if(data == null) + data = BufferUtil.EMPTY_BUFFER; + int remaining = data.remaining(); int outputLength = Math.max(256,data.remaining()); if (LOG.isDebugEnabled()) diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java index 31d0cd088ca..0c9d9eed19e 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java @@ -312,6 +312,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest ext.setNextOutgoingFrames(capture); ext.outgoingFrame(new TextFrame().setPayload("Hello"), null, BatchMode.OFF); + ext.outgoingFrame(new TextFrame(), null, BatchMode.OFF); ext.outgoingFrame(new TextFrame().setPayload("There"), null, BatchMode.OFF); capture.assertBytes(0, "c107f248cdc9c90700");