fix mount leaks

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2022-08-03 19:51:15 +02:00
parent ae56240423
commit d50aa39549
1 changed files with 16 additions and 2 deletions

View File

@ -27,14 +27,18 @@ import java.util.List;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.resource.FileSystemPool;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.eclipse.jetty.toolchain.test.ExtraMatchers.ordered;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@ -53,11 +57,12 @@ public class WebAppClassLoaderTest
@BeforeEach
public void init() throws Exception
{
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
this.testWebappDir = MavenTestingUtils.getProjectDirPath("src/test/webapp");
Resource webapp = ResourceFactory.root().newResource(testWebappDir);
_context = new WebAppContext();
_context.setBaseResource(webapp.getPath());
Resource webapp = ResourceFactory.of(_context).newResource(testWebappDir);
_context.setBaseResource(webapp);
_context.setContextPath("/test");
_context.setExtraClasspath("src/test/resources/ext/*");
@ -67,6 +72,15 @@ public class WebAppClassLoaderTest
_loader.setName("test");
_context.setServer(new Server());
LifeCycle.start(_context);
}
@AfterEach
public void tearDown()
{
IO.close(_loader);
LifeCycle.stop(_context);
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
}
public void assertCanLoadClass(String clazz) throws ClassNotFoundException