You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/08/19 12:36:20 UTC

[tomcat] 01/02: Add debug logging

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit d2c3c86d9443d70b451b26e7b9efa8333dde303f
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Aug 19 13:34:59 2020 +0100

    Add debug logging
---
 .../apache/catalina/loader/TestVirtualContext.java | 385 +++++++++++----------
 1 file changed, 198 insertions(+), 187 deletions(-)

diff --git a/test/org/apache/catalina/loader/TestVirtualContext.java b/test/org/apache/catalina/loader/TestVirtualContext.java
index 30ef536..7c1ccb8 100644
--- a/test/org/apache/catalina/loader/TestVirtualContext.java
+++ b/test/org/apache/catalina/loader/TestVirtualContext.java
@@ -22,6 +22,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -55,194 +57,203 @@ public class TestVirtualContext extends TomcatBaseTest {
 
     @Test
     public void testVirtualClassLoader() throws Exception {
-        Tomcat tomcat = getTomcatInstance();
-
-        File appDir = new File("test/webapp-virtual-webapp/src/main/webapp");
-        // app dir is relative to server home
-        StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test",
-            appDir.getAbsolutePath());
-
-        ctx.setResources(new StandardRoot(ctx));
-        File f1 = new File("test/webapp-virtual-webapp/target/classes");
-        File f2 = new File("test/webapp-virtual-library/target/WEB-INF");
-        File f3 = new File(
-                "test/webapp-virtual-webapp/src/main/webapp/WEB-INF/classes");
-        File f4 = new File(
-                "test/webapp-virtual-webapp/src/main/webapp2/WEB-INF/classes");
-        File f5 = new File("test/webapp-virtual-webapp/src/main/misc");
-        File f6 = new File("test/webapp-virtual-webapp/src/main/webapp2");
-        ctx.getResources().createWebResourceSet(
-                WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes",
-                f1.getAbsolutePath(), null, "/");
-        ctx.getResources().createWebResourceSet(
-                WebResourceRoot.ResourceSetType.POST, "/WEB-INF",
-                f2.getAbsolutePath(), null, "/");
-        ctx.getResources().createWebResourceSet(
-                WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes",
-                f3.getAbsolutePath(), null, "/");
-        ctx.getResources().createWebResourceSet(
-                WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes",
-                f4.getAbsolutePath(), null, "/");
-        ctx.getResources().createWebResourceSet(
-                WebResourceRoot.ResourceSetType.POST, "/other",
-                f5.getAbsolutePath(), null, "/");
-        ctx.getResources().createWebResourceSet(
-                WebResourceRoot.ResourceSetType.POST, "/",
-                f6.getAbsolutePath(), null, "/");
-
-        StandardJarScanner jarScanner = new StandardJarScanner();
-        jarScanner.setScanAllDirectories(true);
-        ctx.setJarScanner(jarScanner);
-        ctx.setAddWebinfClassesResources(true);
 
-        tomcat.start();
-
-        assertPageContains("/test/classpathGetResourceAsStream.jsp?path=nonexistent",
-            "resourceAInWebInfClasses=true", 404);
-
-        assertPageContains(
-            "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceA.properties",
-            "resourceAInWebInfClasses=true");
-        assertPageContains(
-            "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceA.properties",
-            "resourceAInWebInfClasses=true");
-
-        assertPageContains(
-            "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceB.properties",
-            "resourceBInTargetClasses=true");
-        assertPageContains(
-            "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceB.properties",
-            "resourceBInTargetClasses=true");
-
-        assertPageContains(
-            "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceC.properties",
-            "resourceCInDependentLibraryTargetClasses=true");
-        assertPageContains(
-            "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceC.properties",
-            "resourceCInDependentLibraryTargetClasses=true");
-
-        assertPageContains(
-            "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceD.properties",
-            "resourceDInPackagedJarInWebInfLib=true");
-        assertPageContains(
-            "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceD.properties",
-            "resourceDInPackagedJarInWebInfLib=true");
-
-        assertPageContains(
-            "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceG.properties",
-            "resourceGInWebInfClasses=true");
-        assertPageContains(
-            "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceG.properties",
-            "resourceGInWebInfClasses=true");
-
-        // test listing all possible paths for a classpath resource
-        String allUrls =
-            getUrl(
-                "http://localhost:" + getPort() +
-                    "/test/classpathGetResources.jsp?path=rsrc/").toString();
-        Assert.assertTrue(
-            allUrls,
-            allUrls.indexOf("/test/webapp-virtual-webapp/src/main/webapp/WEB-INF/classes/rsrc") > 0);
-        Assert.assertTrue(
-            allUrls,
-            allUrls.indexOf("/test/webapp-virtual-webapp/src/main/webapp2/WEB-INF/classes/rsrc") > 0);
-        Assert.assertTrue(
-            allUrls,
-            allUrls.indexOf("/test/webapp-virtual-webapp/src/main/webapp/WEB-INF/lib/rsrc.jar!/rsrc") > 0);
-        Assert.assertTrue(
-            allUrls,
-            allUrls.indexOf("/test/webapp-virtual-webapp/target/classes/rsrc") > 0);
-        Assert.assertTrue(
-            allUrls,
-            allUrls.indexOf("/test/webapp-virtual-library/target/WEB-INF/classes/rsrc") > 0);
-
-        // check that there's no duplicate in the URLs
-        String[] allUrlsArray = allUrls.split("\\s+");
-        Assert.assertEquals(new HashSet<>(Arrays.asList(allUrlsArray)).size(),
-            allUrlsArray.length);
-
-        String allRsrsc2ClasspathUrls =
-            getUrl(
-                "http://localhost:" + getPort() +
-                    "/test/classpathGetResources.jsp?path=rsrc2/").toString();
-        Assert.assertTrue(
-            allRsrsc2ClasspathUrls,
-            allRsrsc2ClasspathUrls.indexOf("/test/webapp-virtual-webapp/src/main/webapp2/WEB-INF/classes/rsrc2") > 0);
-
-        // tests context.getRealPath
-
-        // the following fails because getRealPath always return a non-null path
-        // even if there's no such resource
-        // assertPageContains("/test/contextGetRealPath.jsp?path=nonexistent",
-        // "resourceAInWebInfClasses=true", 404);
-
-        // Real paths depend on the OS and this test has to work on all
-        // platforms so use File to convert the path to a platform specific form
-        File f = new File(
-            "test/webapp-virtual-webapp/src/main/webapp/rsrc/resourceF.properties");
-        assertPageContains(
-            "/test/contextGetRealPath.jsp?path=/rsrc/resourceF.properties",
-            f.getPath());
-
-        // tests context.getResource then the content
-
-        assertPageContains("/test/contextGetResource.jsp?path=/nonexistent",
-            "resourceAInWebInfClasses=true", 404);
-        assertPageContains(
-            "/test/contextGetResource.jsp?path=/WEB-INF/classes/rsrc/resourceA.properties",
-            "resourceAInWebInfClasses=true");
-        assertPageContains(
-            "/test/contextGetResource.jsp?path=/WEB-INF/classes/rsrc/resourceG.properties",
-            "resourceGInWebInfClasses=true");
-        assertPageContains(
-            "/test/contextGetResource.jsp?path=/rsrc/resourceE.properties",
-            "resourceEInDependentLibraryTargetClasses=true");
-        assertPageContains(
-            "/test/contextGetResource.jsp?path=/other/resourceI.properties",
-            "resourceIInWebapp=true");
-        assertPageContains(
-            "/test/contextGetResource.jsp?path=/rsrc2/resourceJ.properties",
-            "resourceJInWebapp=true");
-
-        String allRsrcPaths =
-            getUrl(
-                "http://localhost:" + getPort() +
-                    "/test/contextGetResourcePaths.jsp?path=/rsrc/").toString();
-        Assert.assertTrue(
-            allRsrcPaths,
-            allRsrcPaths.indexOf("/rsrc/resourceF.properties") > 0);
-        Assert.assertTrue(
-            allRsrcPaths,
-            allRsrcPaths.indexOf("/rsrc/resourceE.properties") > 0);
-        Assert.assertTrue(
-            allRsrcPaths,
-            allRsrcPaths.indexOf("/rsrc/resourceH.properties") > 0);
-
-        // check that there's no duplicate in the URLs
-        String[] allRsrcPathsArray = allRsrcPaths.split("\\s+");
-        Assert.assertEquals(new HashSet<>(Arrays.asList(allRsrcPathsArray)).size(),
-            allRsrcPathsArray.length);
-
-        String allRsrc2Paths =
-            getUrl(
-                "http://localhost:" + getPort() +
-                    "/test/contextGetResourcePaths.jsp?path=/rsrc2/").toString();
-        Assert.assertTrue(
-            allRsrc2Paths,
-            allRsrc2Paths.indexOf("/rsrc2/resourceJ.properties") > 0);
-
-        assertPageContains(
-            "/test/testTlds.jsp",
-            "worldA");
-        assertPageContains(
-            "/test/testTlds.jsp",
-            "worldB");
-        assertPageContains(
-            "/test/testTlds.jsp",
-            "worldC");
-        assertPageContains(
-            "/test/testTlds.jsp",
-            "worldD");
+        // debug logging for intermittent CI failures
+        LogManager.getLogManager().getLogger("org.apache.coyote").setLevel(Level.ALL);
+        LogManager.getLogManager().getLogger("org.apache.tomcat.util.net").setLevel(Level.ALL);
+        try {
+            Tomcat tomcat = getTomcatInstance();
+
+            File appDir = new File("test/webapp-virtual-webapp/src/main/webapp");
+            // app dir is relative to server home
+            StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test",
+                appDir.getAbsolutePath());
+
+            ctx.setResources(new StandardRoot(ctx));
+            File f1 = new File("test/webapp-virtual-webapp/target/classes");
+            File f2 = new File("test/webapp-virtual-library/target/WEB-INF");
+            File f3 = new File(
+                    "test/webapp-virtual-webapp/src/main/webapp/WEB-INF/classes");
+            File f4 = new File(
+                    "test/webapp-virtual-webapp/src/main/webapp2/WEB-INF/classes");
+            File f5 = new File("test/webapp-virtual-webapp/src/main/misc");
+            File f6 = new File("test/webapp-virtual-webapp/src/main/webapp2");
+            ctx.getResources().createWebResourceSet(
+                    WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes",
+                    f1.getAbsolutePath(), null, "/");
+            ctx.getResources().createWebResourceSet(
+                    WebResourceRoot.ResourceSetType.POST, "/WEB-INF",
+                    f2.getAbsolutePath(), null, "/");
+            ctx.getResources().createWebResourceSet(
+                    WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes",
+                    f3.getAbsolutePath(), null, "/");
+            ctx.getResources().createWebResourceSet(
+                    WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes",
+                    f4.getAbsolutePath(), null, "/");
+            ctx.getResources().createWebResourceSet(
+                    WebResourceRoot.ResourceSetType.POST, "/other",
+                    f5.getAbsolutePath(), null, "/");
+            ctx.getResources().createWebResourceSet(
+                    WebResourceRoot.ResourceSetType.POST, "/",
+                    f6.getAbsolutePath(), null, "/");
+
+            StandardJarScanner jarScanner = new StandardJarScanner();
+            jarScanner.setScanAllDirectories(true);
+            ctx.setJarScanner(jarScanner);
+            ctx.setAddWebinfClassesResources(true);
+
+            tomcat.start();
+
+            assertPageContains("/test/classpathGetResourceAsStream.jsp?path=nonexistent",
+                "resourceAInWebInfClasses=true", 404);
+
+            assertPageContains(
+                "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceA.properties",
+                "resourceAInWebInfClasses=true");
+            assertPageContains(
+                "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceA.properties",
+                "resourceAInWebInfClasses=true");
+
+            assertPageContains(
+                "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceB.properties",
+                "resourceBInTargetClasses=true");
+            assertPageContains(
+                "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceB.properties",
+                "resourceBInTargetClasses=true");
+
+            assertPageContains(
+                "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceC.properties",
+                "resourceCInDependentLibraryTargetClasses=true");
+            assertPageContains(
+                "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceC.properties",
+                "resourceCInDependentLibraryTargetClasses=true");
+
+            assertPageContains(
+                "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceD.properties",
+                "resourceDInPackagedJarInWebInfLib=true");
+            assertPageContains(
+                "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceD.properties",
+                "resourceDInPackagedJarInWebInfLib=true");
+
+            assertPageContains(
+                "/test/classpathGetResourceAsStream.jsp?path=rsrc/resourceG.properties",
+                "resourceGInWebInfClasses=true");
+            assertPageContains(
+                "/test/classpathGetResourceUrlThenGetStream.jsp?path=rsrc/resourceG.properties",
+                "resourceGInWebInfClasses=true");
+
+            // test listing all possible paths for a classpath resource
+            String allUrls =
+                getUrl(
+                    "http://localhost:" + getPort() +
+                        "/test/classpathGetResources.jsp?path=rsrc/").toString();
+            Assert.assertTrue(
+                allUrls,
+                allUrls.indexOf("/test/webapp-virtual-webapp/src/main/webapp/WEB-INF/classes/rsrc") > 0);
+            Assert.assertTrue(
+                allUrls,
+                allUrls.indexOf("/test/webapp-virtual-webapp/src/main/webapp2/WEB-INF/classes/rsrc") > 0);
+            Assert.assertTrue(
+                allUrls,
+                allUrls.indexOf("/test/webapp-virtual-webapp/src/main/webapp/WEB-INF/lib/rsrc.jar!/rsrc") > 0);
+            Assert.assertTrue(
+                allUrls,
+                allUrls.indexOf("/test/webapp-virtual-webapp/target/classes/rsrc") > 0);
+            Assert.assertTrue(
+                allUrls,
+                allUrls.indexOf("/test/webapp-virtual-library/target/WEB-INF/classes/rsrc") > 0);
+
+            // check that there's no duplicate in the URLs
+            String[] allUrlsArray = allUrls.split("\\s+");
+            Assert.assertEquals(new HashSet<>(Arrays.asList(allUrlsArray)).size(),
+                allUrlsArray.length);
+
+            String allRsrsc2ClasspathUrls =
+                getUrl(
+                    "http://localhost:" + getPort() +
+                        "/test/classpathGetResources.jsp?path=rsrc2/").toString();
+            Assert.assertTrue(
+                allRsrsc2ClasspathUrls,
+                allRsrsc2ClasspathUrls.indexOf("/test/webapp-virtual-webapp/src/main/webapp2/WEB-INF/classes/rsrc2") > 0);
+
+            // tests context.getRealPath
+
+            // the following fails because getRealPath always return a non-null path
+            // even if there's no such resource
+            // assertPageContains("/test/contextGetRealPath.jsp?path=nonexistent",
+            // "resourceAInWebInfClasses=true", 404);
+
+            // Real paths depend on the OS and this test has to work on all
+            // platforms so use File to convert the path to a platform specific form
+            File f = new File(
+                "test/webapp-virtual-webapp/src/main/webapp/rsrc/resourceF.properties");
+            assertPageContains(
+                "/test/contextGetRealPath.jsp?path=/rsrc/resourceF.properties",
+                f.getPath());
+
+            // tests context.getResource then the content
+
+            assertPageContains("/test/contextGetResource.jsp?path=/nonexistent",
+                "resourceAInWebInfClasses=true", 404);
+            assertPageContains(
+                "/test/contextGetResource.jsp?path=/WEB-INF/classes/rsrc/resourceA.properties",
+                "resourceAInWebInfClasses=true");
+            assertPageContains(
+                "/test/contextGetResource.jsp?path=/WEB-INF/classes/rsrc/resourceG.properties",
+                "resourceGInWebInfClasses=true");
+            assertPageContains(
+                "/test/contextGetResource.jsp?path=/rsrc/resourceE.properties",
+                "resourceEInDependentLibraryTargetClasses=true");
+            assertPageContains(
+                "/test/contextGetResource.jsp?path=/other/resourceI.properties",
+                "resourceIInWebapp=true");
+            assertPageContains(
+                "/test/contextGetResource.jsp?path=/rsrc2/resourceJ.properties",
+                "resourceJInWebapp=true");
+
+            String allRsrcPaths =
+                getUrl(
+                    "http://localhost:" + getPort() +
+                        "/test/contextGetResourcePaths.jsp?path=/rsrc/").toString();
+            Assert.assertTrue(
+                allRsrcPaths,
+                allRsrcPaths.indexOf("/rsrc/resourceF.properties") > 0);
+            Assert.assertTrue(
+                allRsrcPaths,
+                allRsrcPaths.indexOf("/rsrc/resourceE.properties") > 0);
+            Assert.assertTrue(
+                allRsrcPaths,
+                allRsrcPaths.indexOf("/rsrc/resourceH.properties") > 0);
+
+            // check that there's no duplicate in the URLs
+            String[] allRsrcPathsArray = allRsrcPaths.split("\\s+");
+            Assert.assertEquals(new HashSet<>(Arrays.asList(allRsrcPathsArray)).size(),
+                allRsrcPathsArray.length);
+
+            String allRsrc2Paths =
+                getUrl(
+                    "http://localhost:" + getPort() +
+                        "/test/contextGetResourcePaths.jsp?path=/rsrc2/").toString();
+            Assert.assertTrue(
+                allRsrc2Paths,
+                allRsrc2Paths.indexOf("/rsrc2/resourceJ.properties") > 0);
+
+            assertPageContains(
+                "/test/testTlds.jsp",
+                "worldA");
+            assertPageContains(
+                "/test/testTlds.jsp",
+                "worldB");
+            assertPageContains(
+                "/test/testTlds.jsp",
+                "worldC");
+            assertPageContains(
+                "/test/testTlds.jsp",
+                "worldD");
+        } finally {
+            LogManager.getLogManager().getLogger("org.apache.coyote").setLevel(Level.INFO);
+            LogManager.getLogManager().getLogger("org.apache.tomcat.util.net").setLevel(Level.INFO);
+        }
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org