diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/LeakTrackingConnectionPool.java b/jetty-client/src/main/java/org/eclipse/jetty/client/LeakTrackingConnectionPool.java index a1b87344f85..37144a8de03 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/LeakTrackingConnectionPool.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/LeakTrackingConnectionPool.java @@ -25,18 +25,12 @@ import org.eclipse.jetty.util.Promise; public class LeakTrackingConnectionPool extends ConnectionPool { - private final LeakDetector leakDetector = new LeakDetector() - { - @Override - protected void leaked(LeakInfo leakInfo) - { - LeakTrackingConnectionPool.this.leaked(leakInfo); - } - }; + private final LeakDetector leakDetector; - public LeakTrackingConnectionPool(Destination destination, int maxConnections, Promise connectionPromise) + public LeakTrackingConnectionPool(Destination destination, int maxConnections, Promise connectionPromise, LeakDetector leakDetector) { super(destination, maxConnections, connectionPromise); + this.leakDetector = leakDetector; start(); } @@ -84,9 +78,4 @@ public class LeakTrackingConnectionPool extends ConnectionPool if (!leakDetector.released(connection)) LOG.info("Connection {}@{} released but not acquired", connection, System.identityHashCode(connection)); } - - protected void leaked(LeakDetector.LeakInfo leakInfo) - { - LOG.info("Connection " + leakInfo.getResourceDescription() + " leaked at:", leakInfo.getStackFrames()); - } } diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientLoadTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientLoadTest.java index 5f03a6e9f9e..5103b4191b1 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientLoadTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientLoadTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.client; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -28,7 +31,7 @@ import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -44,15 +47,12 @@ import org.eclipse.jetty.client.util.BytesContentProvider; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpScheme; -import org.eclipse.jetty.io.ArrayByteBufferPool; import org.eclipse.jetty.io.LeakTrackingByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.server.AbstractConnectionFactory; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.toolchain.test.annotation.Slow; -import org.eclipse.jetty.toolchain.test.annotation.Stress; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.LeakDetector; import org.eclipse.jetty.util.log.Log; @@ -71,31 +71,25 @@ public class HttpClientLoadTest extends AbstractHttpClientServerTest super(sslContextFactory); } - @Stress("High I/O, High CPU") - @Slow @Test public void testIterative() throws Exception { int cores = Runtime.getRuntime().availableProcessors(); - final AtomicLong leaks = new AtomicLong(); - start(new LoadHandler()); server.stop(); server.removeConnector(connector); + LeakTrackingByteBufferPool serverBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()); connector = new ServerConnector(server, connector.getExecutor(), connector.getScheduler(), - new LeakTrackingByteBufferPool(new ArrayByteBufferPool()) - { - @Override - protected void leaked(LeakDetector.LeakInfo leakInfo) - { - leaks.incrementAndGet(); - } - }, 1, Math.min(1, cores / 2), AbstractConnectionFactory.getFactories(sslContextFactory, new HttpConnectionFactory())); + serverBufferPool , 1, Math.min(1, cores / 2), + AbstractConnectionFactory.getFactories(sslContextFactory, new HttpConnectionFactory())); server.addConnector(connector); server.start(); client.stop(); + + final LeakDetector connectionLeakDetector = new LeakDetector(); + HttpClient newClient = new HttpClient(new HttpClientTransportOverHTTP() { @Override @@ -106,29 +100,15 @@ public class HttpClientLoadTest extends AbstractHttpClientServerTest @Override protected ConnectionPool newConnectionPool(HttpClient client) { - return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this) - { - @Override - protected void leaked(LeakDetector.LeakInfo resource) - { - leaks.incrementAndGet(); - } - }; + return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this, connectionLeakDetector); } }; } }, sslContextFactory); newClient.setExecutor(client.getExecutor()); client = newClient; - client.setByteBufferPool(new LeakTrackingByteBufferPool(new MappedByteBufferPool()) - { - @Override - protected void leaked(LeakDetector.LeakInfo leakInfo) - { - super.leaked(leakInfo); - leaks.incrementAndGet(); - } - }); + LeakTrackingByteBufferPool clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()); + client.setByteBufferPool(clientBufferPool); client.setMaxConnectionsPerDestination(32768); client.setMaxRequestsQueuedPerDestination(1024 * 1024); client.setDispatchIO(false); @@ -151,7 +131,15 @@ public class HttpClientLoadTest extends AbstractHttpClientServerTest run(random, iterations); } - Assert.assertEquals(0, leaks.get()); + assertThat("Server BufferPool - leaked acquires", serverBufferPool.getLeakedAcquires(), is(0L)); + assertThat("Server BufferPool - leaked releases", serverBufferPool.getLeakedReleases(), is(0L)); + assertThat("Server BufferPool - unreleased", serverBufferPool.getLeakedUnreleased(), is(0L)); + + assertThat("Client BufferPool - leaked acquires", clientBufferPool.getLeakedAcquires(), is(0L)); + assertThat("Client BufferPool - leaked releases", clientBufferPool.getLeakedReleases(), is(0L)); + assertThat("Client BufferPool - unreleased", clientBufferPool.getLeakedUnreleased(), is(0L)); + + assertThat("Connection Leaks", connectionLeakDetector.getUnreleasedCount(), is(0L)); } private void run(Random random, int iterations) throws InterruptedException diff --git a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/AbstractHttpClientServerTest.java b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/AbstractHttpClientServerTest.java index d553e04c44a..c0365733279 100644 --- a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/AbstractHttpClientServerTest.java +++ b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/AbstractHttpClientServerTest.java @@ -18,17 +18,18 @@ package org.eclipse.jetty.fcgi.server; -import java.util.concurrent.atomic.AtomicLong; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import org.eclipse.jetty.client.ConnectionPool; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpDestination; import org.eclipse.jetty.client.LeakTrackingConnectionPool; import org.eclipse.jetty.client.Origin; +import org.eclipse.jetty.client.api.Connection; import org.eclipse.jetty.fcgi.client.http.HttpClientTransportOverFCGI; import org.eclipse.jetty.fcgi.client.http.HttpDestinationOverFCGI; import org.eclipse.jetty.http.HttpScheme; -import org.eclipse.jetty.io.ArrayByteBufferPool; import org.eclipse.jetty.io.LeakTrackingByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.server.Handler; @@ -39,14 +40,15 @@ import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.util.LeakDetector; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.junit.After; -import org.junit.Assert; import org.junit.Rule; public abstract class AbstractHttpClientServerTest { @Rule public final TestTracker tracker = new TestTracker(); - private final AtomicLong leaks = new AtomicLong(); + private LeakTrackingByteBufferPool serverBufferPool; + private LeakTrackingByteBufferPool clientBufferPool; + private LeakDetector connectionLeakDetector; protected Server server; protected ServerConnector connector; protected HttpClient client; @@ -57,15 +59,9 @@ public abstract class AbstractHttpClientServerTest server = new Server(); ServerFCGIConnectionFactory fcgiConnectionFactory = new ServerFCGIConnectionFactory(new HttpConfiguration()); - connector = new ServerConnector(server, null, null, - new LeakTrackingByteBufferPool(new ArrayByteBufferPool()) - { - @Override - protected void leaked(LeakDetector.LeakInfo leakInfo) - { - leaks.incrementAndGet(); - } - }, 1, Math.max(1, Runtime.getRuntime().availableProcessors() / 2), fcgiConnectionFactory); + serverBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()); + connector = new ServerConnector(server, null, null, serverBufferPool, + 1, Math.max(1, Runtime.getRuntime().availableProcessors() / 2), fcgiConnectionFactory); // connector.setPort(9000); server.addConnector(connector); @@ -74,6 +70,8 @@ public abstract class AbstractHttpClientServerTest QueuedThreadPool executor = new QueuedThreadPool(); executor.setName(executor.getName() + "-client"); + + connectionLeakDetector = new LeakDetector(); client = new HttpClient(new HttpClientTransportOverFCGI(1, false, "") { @@ -85,27 +83,14 @@ public abstract class AbstractHttpClientServerTest @Override protected ConnectionPool newConnectionPool(HttpClient client) { - return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this) - { - @Override - protected void leaked(LeakDetector.LeakInfo leakInfo) - { - leaks.incrementAndGet(); - } - }; + return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this, connectionLeakDetector); } }; } }, null); client.setExecutor(executor); - client.setByteBufferPool(new LeakTrackingByteBufferPool(new MappedByteBufferPool()) - { - @Override - protected void leaked(LeakDetector.LeakInfo leakInfo) - { - leaks.incrementAndGet(); - } - }); + clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()); + client.setByteBufferPool(clientBufferPool); client.start(); } @@ -113,7 +98,15 @@ public abstract class AbstractHttpClientServerTest public void dispose() throws Exception { System.gc(); - Assert.assertEquals(0, leaks.get()); + assertThat("Server BufferPool - leaked acquires", serverBufferPool.getLeakedAcquires(), is(0L)); + assertThat("Server BufferPool - leaked releases", serverBufferPool.getLeakedReleases(), is(0L)); + assertThat("Server BufferPool - unreleased", serverBufferPool.getLeakedUnreleased(), is(0L)); + + assertThat("Client BufferPool - leaked acquires", clientBufferPool.getLeakedAcquires(), is(0L)); + assertThat("Client BufferPool - leaked releases", clientBufferPool.getLeakedReleases(), is(0L)); + assertThat("Client BufferPool - unreleased", clientBufferPool.getLeakedUnreleased(), is(0L)); + + assertThat("Connection Leaks", connectionLeakDetector.getUnreleasedCount(), is(0L)); if (client != null) client.stop(); diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/LeakTrackingByteBufferPool.java b/jetty-io/src/main/java/org/eclipse/jetty/io/LeakTrackingByteBufferPool.java index 4192c448e23..a84428801cb 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/LeakTrackingByteBufferPool.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/LeakTrackingByteBufferPool.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.io; import java.nio.ByteBuffer; +import java.util.concurrent.atomic.AtomicLong; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.LeakDetector; @@ -32,15 +33,16 @@ public class LeakTrackingByteBufferPool extends ContainerLifeCycle implements By private final LeakDetector leakDetector = new LeakDetector() { - @Override - protected void leaked(LeakInfo leakInfo) + public String id(ByteBuffer resource) { - LeakTrackingByteBufferPool.this.leaked(leakInfo); + return BufferUtil.toIDString(resource); } }; private final static boolean NOISY = Boolean.getBoolean(LeakTrackingByteBufferPool.class.getName() + ".NOISY"); private final ByteBufferPool delegate; + private final AtomicLong leakedReleases = new AtomicLong(0); + private final AtomicLong leakedAcquires = new AtomicLong(0); public LeakTrackingByteBufferPool(ByteBufferPool delegate) { @@ -53,10 +55,13 @@ public class LeakTrackingByteBufferPool extends ContainerLifeCycle implements By public ByteBuffer acquire(int size, boolean direct) { ByteBuffer buffer = delegate.acquire(size,direct); - boolean leakd = leakDetector.acquired(buffer); - if (NOISY || !leakd) - LOG.info(String.format("ByteBuffer acquire %s leakd.acquired=%s",BufferUtil.toIDString(buffer),leakd ? "normal" : "LEAK"), + boolean leaked = leakDetector.acquired(buffer); + if (NOISY || !leaked) + { + leakedAcquires.incrementAndGet(); + LOG.info(String.format("ByteBuffer acquire %s leaked.acquired=%s",leakDetector.id(buffer),leaked ? "normal" : "LEAK"), new Throwable("LeakStack.Acquire")); + } return buffer; } @@ -65,15 +70,47 @@ public class LeakTrackingByteBufferPool extends ContainerLifeCycle implements By { if (buffer == null) return; - boolean leakd = leakDetector.released(buffer); - if (NOISY || !leakd) - LOG.info(String.format("ByteBuffer release %s leakd.released=%s",BufferUtil.toIDString(buffer),leakd ? "normal" : "LEAK"), - new Throwable("LeakStack.Release")); + boolean leaked = leakDetector.released(buffer); + if (NOISY || !leaked) { + leakedReleases.incrementAndGet(); + LOG.info(String.format("ByteBuffer release %s leaked.released=%s",leakDetector.id(buffer),leaked ? "normal" : "LEAK"),new Throwable( + "LeakStack.Release")); + } delegate.release(buffer); } - - protected void leaked(LeakDetector.LeakInfo leakInfo) + + public void clearTracking() { - LOG.warn("ByteBuffer " + leakInfo.getResourceDescription() + " leaked at:",leakInfo.getStackFrames()); + leakDetector.clear(); + leakedAcquires.set(0); + leakedReleases.set(0); + } + + /** + * Get the count of BufferPool.acquire() calls that detected a leak + * @return count of BufferPool.acquire() calls that detected a leak + */ + public long getLeakedAcquires() + { + return leakedAcquires.get(); + } + + /** + * Get the count of BufferPool.release() calls that detected a leak + * @return count of BufferPool.release() calls that detected a leak + */ + public long getLeakedReleases() + { + return leakedReleases.get(); + } + + /** + * At the end of the run, when the LeakDetector runs, this reports the + * number of unreleased resources. + * @return count of resources that were acquired but not released (byt the end of the run) + */ + public long getLeakedUnreleased() + { + return leakDetector.getUnreleasedCount(); } } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java b/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java index 84073409ced..b3c08d34e75 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java @@ -57,7 +57,7 @@ public class MappedByteBufferPool implements ByteBufferPool if (result == null) { int capacity = bucket * factor; - result = direct ? createDirect(capacity) : createInDirect(capacity); + result = direct ? createDirect(capacity) : createIndirect(capacity); } BufferUtil.clear(result); @@ -69,12 +69,11 @@ public class MappedByteBufferPool implements ByteBufferPool return BufferUtil.allocateDirect(capacity); } - protected ByteBuffer createInDirect(int capacity) + public ByteBuffer createIndirect(int capacity) { return BufferUtil.allocate(capacity); } - @Override public void release(ByteBuffer buffer) { @@ -121,10 +120,11 @@ public class MappedByteBufferPool implements ByteBufferPool return direct ? directBuffers : heapBuffers; } - static AtomicInteger __tag = new AtomicInteger(); + private static AtomicInteger __tag = new AtomicInteger(); + public static class Tagged extends MappedByteBufferPool { - protected ByteBuffer createInDirect(int capacity) + public ByteBuffer createIndirect(int capacity) { ByteBuffer buffer = BufferUtil.allocate(capacity+4); buffer.limit(4); @@ -138,7 +138,7 @@ public class MappedByteBufferPool implements ByteBufferPool protected ByteBuffer createDirect(int capacity) { - return createInDirect(capacity); + return createIndirect(capacity); } } } diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java index 4ee6780826a..24b3811ec3e 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java @@ -54,7 +54,7 @@ import org.junit.Test; public class SslConnectionTest { private static SslContextFactory __sslCtxFactory=new SslContextFactory(); - private static ByteBufferPool __byteBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool()); + private static ByteBufferPool __byteBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()); protected volatile EndPoint _lastEndp; private volatile boolean _testFill=true; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java index 75189677718..5f931f58405 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java @@ -121,7 +121,7 @@ public class SelectChannelServerSslTest extends HttpServerTestBase sslContextFactory.setKeyManagerPassword("keypwd"); sslContextFactory.setTrustStorePath(keystorePath); sslContextFactory.setTrustStorePassword("storepwd"); - ByteBufferPool pool = new LeakTrackingByteBufferPool(new MappedByteBufferPool()); + ByteBufferPool pool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()); ServerConnector connector = new ServerConnector(_server,(Executor)null,(Scheduler)null,pool, 1, 1, AbstractConnectionFactory.getFactories(sslContextFactory,new HttpConnectionFactory())); diff --git a/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SynDataReplyDataLoadTest.java b/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SynDataReplyDataLoadTest.java index cc0f55b74e9..a7149102118 100644 --- a/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SynDataReplyDataLoadTest.java +++ b/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SynDataReplyDataLoadTest.java @@ -19,6 +19,9 @@ package org.eclipse.jetty.spdy.server; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; @@ -31,9 +34,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import org.eclipse.jetty.io.ArrayByteBufferPool; import org.eclipse.jetty.io.LeakTrackingByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.server.ServerConnector; @@ -50,7 +51,6 @@ import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.client.SPDYClient; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Fields; -import org.eclipse.jetty.util.LeakDetector; import org.eclipse.jetty.util.Promise; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -69,23 +69,8 @@ public class SynDataReplyDataLoadTest extends AbstractTest @Ignore("Test needs to be rewritten") public void testSynDataReplyDataLoad() throws Exception { - final AtomicLong leaks = new AtomicLong(); - LeakTrackingByteBufferPool serverBufferPool = new LeakTrackingByteBufferPool(new ArrayByteBufferPool()) - { - @Override - protected void leaked(LeakDetector.LeakInfo leakInfo) - { - leaks.incrementAndGet(); - } - }; - LeakTrackingByteBufferPool clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool()) - { - @Override - protected void leaked(LeakDetector.LeakInfo leakInfo) - { - leaks.incrementAndGet(); - } - }; + LeakTrackingByteBufferPool serverBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()); + LeakTrackingByteBufferPool clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()); ServerSessionFrameListener listener = new ServerSessionFrameListener.Adapter() { @@ -207,7 +192,13 @@ public class SynDataReplyDataLoadTest extends AbstractTest threadPool.shutdown(); - Assert.assertEquals(0, leaks.get()); + assertThat("Server BufferPool - leaked acquires", serverBufferPool.getLeakedAcquires(), is(0L)); + assertThat("Server BufferPool - leaked releases", serverBufferPool.getLeakedReleases(), is(0L)); + assertThat("Server BufferPool - unreleased", serverBufferPool.getLeakedUnreleased(), is(0L)); + + assertThat("Client BufferPool - leaked acquires", clientBufferPool.getLeakedAcquires(), is(0L)); + assertThat("Client BufferPool - leaked releases", clientBufferPool.getLeakedReleases(), is(0L)); + assertThat("Client BufferPool - unreleased", clientBufferPool.getLeakedUnreleased(), is(0L)); } private void synCompletedData(Session session, Fields headers, int iterations) throws Exception diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/LeakDetector.java b/jetty-util/src/main/java/org/eclipse/jetty/util/LeakDetector.java index 77851d9dd9b..b97b521d9ac 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/LeakDetector.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/LeakDetector.java @@ -22,6 +22,7 @@ import java.lang.ref.PhantomReference; import java.lang.ref.ReferenceQueue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.log.Log; @@ -63,6 +64,7 @@ public class LeakDetector extends AbstractLifeCycle implements Runnable private final ReferenceQueue queue = new ReferenceQueue<>(); private final ConcurrentMap resources = new ConcurrentHashMap<>(); + private final AtomicLong unreleasedCount = new AtomicLong(0); private Thread thread; /** @@ -81,7 +83,6 @@ public class LeakDetector extends AbstractLifeCycle implements Runnable if (info != null) { // leak detected, prior acquire exists (not released) - LOG.warn("Prior Acquire from Stack",info.getStackFrames()); return false; } // normal behavior @@ -103,7 +104,7 @@ public class LeakDetector extends AbstractLifeCycle implements Runnable LeakInfo info = resources.remove(id); if (info != null) { - // normal path + // normal behavior return true; } @@ -118,7 +119,7 @@ public class LeakDetector extends AbstractLifeCycle implements Runnable * the resource to generate the unique ID for * @return the unique ID of the given resource */ - protected String id(T resource) + public String id(T resource) { return String.valueOf(System.identityHashCode(resource)); } @@ -169,6 +170,17 @@ public class LeakDetector extends AbstractLifeCycle implements Runnable protected void leaked(LeakInfo leakInfo) { LOG.warn("Resource leaked: " + leakInfo.description,leakInfo.stackFrames); + unreleasedCount.incrementAndGet(); + } + + public void clear() + { + unreleasedCount.set(0); + } + + public long getUnreleasedCount() + { + return unreleasedCount.get(); } /** 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 ac3eb197445..2c510e5d8c7 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,13 +26,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.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.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; @@ -49,7 +48,7 @@ import org.junit.Test; public class AnnotatedServerEndpointTest { @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); 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 7bf641c43ef..05f7284fb14 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,12 +23,11 @@ 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.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; @@ -45,7 +44,7 @@ public class BasicEndpointTest public TestingDir testdir = new TestingDir(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); @Test public void testEcho() throws Exception diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/IdleTimeoutTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/IdleTimeoutTest.java index b0c56076002..101ddfbdee4 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/IdleTimeoutTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/IdleTimeoutTest.java @@ -26,7 +26,6 @@ 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; @@ -34,7 +33,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.common.test.LeakTrackingBufferPoolRule; 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; @@ -55,7 +54,7 @@ public class IdleTimeoutTest public TestingDir testdir = new TestingDir(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); private static WSServer server; 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 2b3df901334..8208c00365e 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,12 +25,11 @@ 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.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoConfiguredSocket; import org.junit.Assert; import org.junit.Rule; @@ -45,7 +44,7 @@ public class LargeAnnotatedTest public TestingDir testdir = new TestingDir(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); @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 9a5fd74809b..97d28882391 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,12 +25,11 @@ 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.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoDefaultSocket; import org.junit.Assert; import org.junit.Rule; @@ -45,7 +44,7 @@ public class LargeContainerTest public TestingDir testdir = new TestingDir(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); @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 158cd699f4e..d63bb84a4bb 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,12 +23,11 @@ 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.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoReturnEndpoint; import org.junit.Assert; import org.junit.Rule; @@ -40,7 +39,7 @@ public class OnMessageReturnTest public TestingDir testdir = new TestingDir(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); @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 98828fc8032..06a4600aa58 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,13 +29,12 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -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.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -100,7 +99,7 @@ public class SessionTest } @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); 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 fb18359aa96..ff965616c2c 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 @@ -32,6 +32,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; + import javax.websocket.ClientEndpoint; import javax.websocket.CloseReason; import javax.websocket.CloseReason.CloseCode; @@ -50,7 +51,6 @@ import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpointConfig; -import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; @@ -59,7 +59,7 @@ 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.LeakTrackingBufferPool; +import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.util.Hex; import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; import org.junit.AfterClass; @@ -76,7 +76,7 @@ public class StreamTest private static final Logger LOG = Log.getLogger(StreamTest.class); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); 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 e02f4235683..4aa4c630679 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,13 +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.BlockheadServer.ServerConnection; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool; +import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -43,7 +42,7 @@ public class BadNetworkTest public TestTracker tt = new TestTracker(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); 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 c9f8c532787..3801c034572 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 @@ -30,7 +30,6 @@ 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; @@ -38,7 +37,7 @@ 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.BlockheadServer.ServerConnection; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool; +import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -54,7 +53,7 @@ public class ClientConnectTest public TestTracker tt = new TestTracker(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); 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 56fa6e84bb8..e65290d6ffe 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,13 +29,12 @@ 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; +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. @@ -97,7 +96,7 @@ public class TestClient private static final Random __random = new Random(); - private static LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("TestClient",new MappedByteBufferPool()); + private static LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("TestClient"); private final String _host; private final int _port; diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java index db1ccb0a476..6a9fef094dd 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java @@ -140,8 +140,6 @@ public class MessageOutputStream extends OutputStream closed = fin; BufferUtil.flipToFlush(buffer, 0); - if (LOG.isDebugEnabled()) - LOG.debug("flush({}): {}", fin, BufferUtil.toDetailString(buffer)); frame.setPayload(buffer); frame.setFin(fin); 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 bf11b149b31..e9ff59e8c7e 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,12 +23,11 @@ import static org.hamcrest.Matchers.*; import java.nio.ByteBuffer; import java.util.Arrays; -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.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -36,7 +35,7 @@ import org.junit.Test; public class GeneratorParserRoundtripTest { @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("GeneratorParserRoundtrip"); @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 e1728ae7779..0240021dd86 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 @@ -18,9 +18,10 @@ package org.eclipse.jetty.websocket.common; +import static org.hamcrest.Matchers.*; + import java.nio.ByteBuffer; -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; @@ -28,19 +29,17 @@ 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.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; -import static org.hamcrest.Matchers.is; - public class WebSocketFrameTest { @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("WebSocketFrameTest"); 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 9acbea482c9..258c2b2b850 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 @@ -18,27 +18,26 @@ package org.eclipse.jetty.websocket.common; +import static org.hamcrest.Matchers.*; + 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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; -import static org.hamcrest.Matchers.containsString; - public class WebSocketRemoteEndpointTest { @Rule public TestName testname = new TestName(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("WebSocketRemoteEndpoint"); @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 15ce898ef87..e0276144697 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,7 +21,6 @@ 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; @@ -31,7 +30,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.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -49,7 +48,7 @@ public class EventDriverTest public TestName testname = new TestName(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); private Frame makeBinaryFrame(String content, boolean fin) { 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 017be5347f9..9155a3aac10 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,9 +18,8 @@ package org.eclipse.jetty.websocket.common.extensions; -import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.websocket.api.WebSocketPolicy; -import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPool; +import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestName; @@ -31,7 +30,7 @@ public abstract class AbstractExtensionTest public TestName testname = new TestName(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); 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 3651f776f74..18bdb4debb8 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,7 +23,6 @@ import static org.hamcrest.Matchers.*; import java.util.ArrayList; import java.util.List; -import org.eclipse.jetty.io.ArrayByteBufferPool; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.api.WebSocketPolicy; @@ -31,7 +30,7 @@ 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.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -41,7 +40,7 @@ public class ExtensionStackTest private static final Logger LOG = Log.getLogger(ExtensionStackTest.class); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new ArrayByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); @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 e100cf9f0b7..4274cb371bd 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 @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -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; @@ -39,7 +38,7 @@ 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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture; import org.junit.Assert; import org.junit.Rule; @@ -50,7 +49,7 @@ import static org.hamcrest.Matchers.is; public class FragmentExtensionTest { @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test", new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); /** * 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 eb80251decc..7de53b53397 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 @@ -28,7 +28,6 @@ import java.util.Random; import java.util.zip.Deflater; import java.util.zip.Inflater; -import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.RuntimeIOException; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; @@ -50,7 +49,7 @@ 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.LeakTrackingBufferPool; +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; @@ -64,7 +63,7 @@ import static org.hamcrest.Matchers.is; public class DeflateFrameExtensionTest extends AbstractExtensionTest { @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test", new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); 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 d233fa6244b..b39d4c89e43 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 @@ -24,7 +24,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -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; @@ -39,7 +38,7 @@ 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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture; import org.junit.Assert; import org.junit.Rule; @@ -55,7 +54,7 @@ import static org.hamcrest.Matchers.is; public class PerMessageDeflateExtensionTest extends AbstractExtensionTest { @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test", new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); /** * Decode payload example as seen in draft-ietf-hybi-permessage-compression-15. 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 5804f5a87e2..54de967cdc4 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,9 +27,8 @@ 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.test.LeakTrackingBufferPool; +import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -41,7 +40,7 @@ public class MessageInputStreamTest public TestName testname = new TestName(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); @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 796046d2abf..868a20d9f41 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,7 +24,6 @@ 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; @@ -34,7 +33,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.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -53,7 +52,7 @@ public class MessageOutputStreamTest public TestName testname = new TestName(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); private WebSocketPolicy policy; private TrackingSocket socket; @@ -124,7 +123,7 @@ public class MessageOutputStreamTest { int bufsize = (int)(policy.getMaxBinaryMessageBufferSize() * 2.5); byte buf[] = new byte[bufsize]; - LOG.debug("Buffer size: {}",bufsize); + LOG.debug("Buffer sizes: max:{}, test:{}",policy.getMaxBinaryMessageBufferSize(),bufsize); Arrays.fill(buf,(byte)'x'); buf[bufsize - 1] = (byte)'o'; // mark last entry for debugging 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 df1fcad22c3..7b0dac0a47f 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 @@ -20,7 +20,6 @@ package org.eclipse.jetty.websocket.common.message; 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; @@ -30,7 +29,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.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -51,7 +50,7 @@ public class MessageWriterTest public TestName testname = new TestName(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); private WebSocketPolicy policy; private TrackingSocket socket; diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPool.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPoolRule.java similarity index 59% rename from jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPool.java rename to jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPoolRule.java index 8a5fc6ca654..a6c7a5c377c 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPool.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/LeakTrackingBufferPoolRule.java @@ -19,48 +19,29 @@ package org.eclipse.jetty.websocket.common.test; import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; -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.eclipse.jetty.io.MappedByteBufferPool; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; -public class LeakTrackingBufferPool extends LeakTrackingByteBufferPool implements TestRule +public class LeakTrackingBufferPoolRule 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) + public LeakTrackingBufferPoolRule(String id) { - super(delegate); + super(new MappedByteBufferPool.Tagged()); this.id = id; } - @Override - protected void leaked(LeakDetector.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); + assertThat("Leaked Acquires Count for [" + id + "]",getLeakedAcquires(),is(0L)); + assertThat("Leaked Releases Count for [" + id + "]",getLeakedReleases(),is(0L)); + assertThat("Leaked Unrelesed Count for [" + id + "]",getLeakedUnreleased(),is(0L)); } @Override diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitGenerator.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitGenerator.java index 2b525462078..df9f8414c9d 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitGenerator.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitGenerator.java @@ -22,6 +22,7 @@ import java.nio.ByteBuffer; import java.util.List; import org.eclipse.jetty.io.ByteBufferPool; +import org.eclipse.jetty.io.LeakTrackingByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.log.Log; @@ -123,7 +124,7 @@ public class UnitGenerator extends Generator public UnitGenerator() { - super(WebSocketPolicy.newServerPolicy(),new LeakTrackingBufferPool("UnitGenerator",new MappedByteBufferPool())); + super(WebSocketPolicy.newServerPolicy(),new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged())); } public UnitGenerator(ByteBufferPool bufferPool) diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitParser.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitParser.java index 9379748e5d7..b93776cac3c 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitParser.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/UnitParser.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.common.test; import java.nio.ByteBuffer; +import org.eclipse.jetty.io.LeakTrackingByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.api.WebSocketPolicy; @@ -34,7 +35,7 @@ public class UnitParser extends Parser public UnitParser(WebSocketPolicy policy) { - super(policy,new LeakTrackingBufferPool("UnitParser",new MappedByteBufferPool())); + super(policy,new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged())); } private void parsePartial(ByteBuffer buf, int numBytes) 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 af13f03a1e6..930f92c0416 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 @@ -24,7 +24,6 @@ import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; -import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.toolchain.test.EventQueue; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.websocket.api.WebSocketPolicy; @@ -32,7 +31,7 @@ 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.LeakTrackingBufferPool; +import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.server.examples.MyEchoServlet; import org.junit.AfterClass; import org.junit.Assert; @@ -83,7 +82,7 @@ public class TooFastClientTest // Add text frames Generator generator = new Generator(WebSocketPolicy.newClientPolicy(), - new LeakTrackingBufferPool("Generator",new MappedByteBufferPool())); + new LeakTrackingBufferPoolRule("Generator")); 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 250c410a3df..b76212532d2 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 @@ -22,14 +22,13 @@ 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.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.LeakTrackingBufferPool; +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; @@ -46,7 +45,7 @@ public class WebSocketOverSSLTest public TestTracker tracker = new TestTracker(); @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); 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 04be06a9eed..7d3f5b46900 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,7 +22,6 @@ import java.net.URI; import java.nio.ByteBuffer; import java.util.Arrays; -import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.StdErrLog; @@ -31,7 +30,7 @@ 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.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.RawFrameBuilder; import org.eclipse.jetty.websocket.server.SimpleServletServer; import org.junit.AfterClass; @@ -80,7 +79,7 @@ public abstract class AbstractABCase implements Fuzzed protected static SimpleServletServer server; @Rule - public LeakTrackingBufferPool bufferPool = new LeakTrackingBufferPool("Test",new MappedByteBufferPool()); + public LeakTrackingBufferPoolRule bufferPool = new LeakTrackingBufferPoolRule("Test"); @Before public void initGenerators()