#12041 add leak tracking in tests
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
576b7d7446
commit
2aec6cbbc8
|
@ -38,6 +38,11 @@
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.awaitility</groupId>
|
||||||
|
<artifactId>awaitility</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-slf4j-impl</artifactId>
|
<artifactId>jetty-slf4j-impl</artifactId>
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.net.URISyntaxException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -28,11 +29,13 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.eclipse.jetty.http.HttpTester;
|
import org.eclipse.jetty.http.HttpTester;
|
||||||
import org.eclipse.jetty.http.HttpVersion;
|
import org.eclipse.jetty.http.HttpVersion;
|
||||||
import org.eclipse.jetty.io.ArrayByteBufferPool;
|
import org.eclipse.jetty.io.ArrayByteBufferPool;
|
||||||
|
import org.eclipse.jetty.io.ArrayRetainableByteBufferPool;
|
||||||
import org.eclipse.jetty.logging.StacklessLogging;
|
import org.eclipse.jetty.logging.StacklessLogging;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
||||||
|
import static org.awaitility.Awaitility.await;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
|
@ -43,12 +46,15 @@ public abstract class AbstractHttpTest
|
||||||
protected static Server server;
|
protected static Server server;
|
||||||
protected static ServerConnector connector;
|
protected static ServerConnector connector;
|
||||||
private StacklessLogging stacklessChannelLogging;
|
private StacklessLogging stacklessChannelLogging;
|
||||||
|
private ArrayRetainableByteBufferPool.Tracking retainableByteBufferPool;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
server = new Server();
|
server = new Server();
|
||||||
connector = new ServerConnector(server, null, null, new ArrayByteBufferPool(64, 2048, 64 * 1024), 1, 1, new HttpConnectionFactory());
|
ArrayByteBufferPool.Tracking bufferPool = new ArrayByteBufferPool.Tracking(64, 2048, 64 * 1024);
|
||||||
|
retainableByteBufferPool = (ArrayRetainableByteBufferPool.Tracking)bufferPool.asRetainableByteBufferPool();
|
||||||
|
connector = new ServerConnector(server, null, null, bufferPool, 1, 1, new HttpConnectionFactory());
|
||||||
connector.setIdleTimeout(100000);
|
connector.setIdleTimeout(100000);
|
||||||
|
|
||||||
server.addConnector(connector);
|
server.addConnector(connector);
|
||||||
|
@ -58,8 +64,15 @@ public abstract class AbstractHttpTest
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws Exception
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
server.stop();
|
try
|
||||||
stacklessChannelLogging.close();
|
{
|
||||||
|
await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertThat("Server leaks: " + retainableByteBufferPool.dumpLeaks(), retainableByteBufferPool.getLeaks().size(), is(0)));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
server.stop();
|
||||||
|
stacklessChannelLogging.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpTester.Response executeRequest(HttpVersion httpVersion) throws URISyntaxException, IOException
|
protected HttpTester.Response executeRequest(HttpVersion httpVersion) throws URISyntaxException, IOException
|
||||||
|
|
Loading…
Reference in New Issue