You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2013/01/07 11:50:12 UTC

svn commit: r1429745 - in /tomcat/trunk/test/org/apache/catalina: core/TestStandardContext.java startup/TomcatBaseTest.java

Author: kkolinko
Date: Mon Jan  7 10:50:11 2013
New Revision: 1429745

URL: http://svn.apache.org/viewvc?rev=1429745&view=rev
Log:
Amend the test for bug 46243:
Test that a context can be started again after a failed start. There is no need to redeploy it.

Modified:
    tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java
    tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java

Modified: tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java?rev=1429745&r1=1429744&r2=1429745&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java Mon Jan  7 10:50:11 2013
@@ -72,7 +72,9 @@ public class TestStandardContext extends
     @Test
     public void testBug46243() throws Exception {
         // This tests that if a Filter init() fails then the web application
-        // is not put into service.
+        // is not put into service. (BZ 46243)
+        // This also tests that if the cause of the failure is gone,
+        // the context can be started without a need to redeploy it.
 
         // Set up a container
         Tomcat tomcat = getTomcatInstance();
@@ -83,23 +85,7 @@ public class TestStandardContext extends
         }
 
         Context root = tomcat.addContext("", "ROOT");
-
-        // Add test a filter that fails
-        FilterDef filterDef = new FilterDef();
-        filterDef.setFilterClass(Bug46243Filter.class.getName());
-        filterDef.setFilterName("Bug46243");
-        root.addFilterDef(filterDef);
-        FilterMap filterMap = new FilterMap();
-        filterMap.setFilterName("Bug46243");
-        filterMap.addURLPattern("*");
-        root.addFilterMap(filterMap);
-
-        // Add a test servlet so there is something to generate a response if
-        // it works (although it shouldn't)
-        Tomcat.addServlet(root, "Bug46243", new HelloWorldServlet());
-        root.addServletMapping("/", "Bug46243");
-
-
+        configureTest46243Context(root, true);
         tomcat.start();
 
         // Configure the client
@@ -114,6 +100,37 @@ public class TestStandardContext extends
         // Context failed to start. This checks that automatic transition
         // from FAILED to STOPPED state was successful.
         assertEquals(LifecycleState.STOPPED, root.getState());
+
+        // Prepare context for the second attempt
+        // Configuration was cleared on stop() thanks to
+        // StandardContext.resetContext(), so we need to configure it again
+        // from scratch.
+        configureTest46243Context(root, false);
+        root.start();
+        // The same request is processed successfully
+        client.connect();
+        client.processRequest();
+        assertTrue(client.isResponse200());
+        assertEquals(Bug46243Filter.class.getName()
+                + HelloWorldServlet.RESPONSE_TEXT, client.getResponseBody());
+    }
+
+    private static void configureTest46243Context(Context context, boolean fail) {
+        // Add a test filter that fails
+        FilterDef filterDef = new FilterDef();
+        filterDef.setFilterClass(Bug46243Filter.class.getName());
+        filterDef.setFilterName("Bug46243");
+        filterDef.addInitParameter("fail", Boolean.toString(fail));
+        context.addFilterDef(filterDef);
+        FilterMap filterMap = new FilterMap();
+        filterMap.setFilterName("Bug46243");
+        filterMap.addURLPattern("*");
+        context.addFilterMap(filterMap);
+
+        // Add a test servlet so there is something to generate a response if
+        // it works (although it shouldn't)
+        Tomcat.addServlet(context, "Bug46243", new HelloWorldServlet());
+        context.addServletMapping("/", "Bug46243");
     }
 
     private static final class Bug46243Client extends SimpleHttpClient {
@@ -139,13 +156,19 @@ public class TestStandardContext extends
         @Override
         public void doFilter(ServletRequest request, ServletResponse response,
                 FilterChain chain) throws IOException, ServletException {
-            // If it works, do nothing
+            @SuppressWarnings("resource") // No need to close this writer
+            PrintWriter out = response.getWriter();
+            out.print(getClass().getName());
             chain.doFilter(request, response);
         }
 
         @Override
         public void init(FilterConfig filterConfig) throws ServletException {
-            throw new ServletException("Init fail", new ClassNotFoundException());
+            boolean fail = filterConfig.getInitParameter("fail").equals("true");
+            if (fail) {
+                throw new ServletException("Init fail",
+                        new ClassNotFoundException());
+            }
         }
 
     }

Modified: tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java?rev=1429745&r1=1429744&r2=1429745&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java Mon Jan  7 10:50:11 2013
@@ -182,6 +182,7 @@ public abstract class TomcatBaseTest ext
         @Override
         protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                 throws ServletException, IOException {
+            @SuppressWarnings("resource") // No need to close this writer
             PrintWriter out = resp.getWriter();
             out.print(RESPONSE_TEXT);
         }



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