Author: markt Date: Mon Jun 5 17:30:52 2017 New Revision: 1797678 URL: http://svn.apache.org/viewvc?rev=1797678&view=rev Log: Extract log message validation filter to a separate class where it can be used by any unit test.
Added: tomcat/trunk/test/org/apache/tomcat/unittest/TesterLogValidationFilter.java (with props) Modified: tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderThreadLocalMemoryLeak.java Modified: tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderThreadLocalMemoryLeak.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderThreadLocalMemoryLeak.java?rev=1797678&r1=1797677&r2=1797678&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderThreadLocalMemoryLeak.java (original) +++ tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderThreadLocalMemoryLeak.java Mon Jun 5 17:30:52 2017 @@ -18,10 +18,7 @@ package org.apache.catalina.loader; import java.io.InputStream; import java.util.concurrent.Executor; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Filter; import java.util.logging.LogManager; -import java.util.logging.LogRecord; import javax.servlet.http.HttpServletResponse; @@ -34,6 +31,7 @@ import org.apache.catalina.core.JreMemor import org.apache.catalina.core.StandardHost; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.unittest.TesterLogValidationFilter; import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.threads.ThreadPoolExecutor; @@ -76,7 +74,7 @@ public class TestWebappClassLoaderThread ((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1); // Configure logging filter to check leak message appears - LogValidationFilter f = new LogValidationFilter( + TesterLogValidationFilter f = new TesterLogValidationFilter( "The web application [ROOT] created a ThreadLocal with key of"); LogManager.getLogManager().getLogger( "org.apache.catalina.loader.WebappClassLoaderBase").setFilter(f); @@ -132,7 +130,7 @@ public class TestWebappClassLoaderThread ((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1); // Configure logging filter to check leak message appears - LogValidationFilter f = new LogValidationFilter( + TesterLogValidationFilter f = new TesterLogValidationFilter( "The web application [ROOT] created a ThreadLocal with key of"); LogManager.getLogManager().getLogger( "org.apache.catalina.loader.WebappClassLoaderBase").setFilter(f); @@ -205,32 +203,4 @@ public class TestWebappClassLoaderThread obj.toString(); } } - - - private class LogValidationFilter implements Filter { - - private String targetMessage; - private AtomicInteger messageCount = new AtomicInteger(0); - - - public LogValidationFilter(String targetMessage) { - this.targetMessage = targetMessage; - } - - - public int getMessageCount() { - return messageCount.get(); - } - - - @Override - public boolean isLoggable(LogRecord record) { - String msg = record.getMessage(); - if (msg != null && msg.contains(targetMessage)) { - messageCount.incrementAndGet(); - } - - return true; - } - } } \ No newline at end of file Added: tomcat/trunk/test/org/apache/tomcat/unittest/TesterLogValidationFilter.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/unittest/TesterLogValidationFilter.java?rev=1797678&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/unittest/TesterLogValidationFilter.java (added) +++ tomcat/trunk/test/org/apache/tomcat/unittest/TesterLogValidationFilter.java Mon Jun 5 17:30:52 2017 @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.unittest; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Filter; +import java.util.logging.LogRecord; + +public class TesterLogValidationFilter implements Filter { + + private String targetMessage; + private AtomicInteger messageCount = new AtomicInteger(0); + + + public TesterLogValidationFilter(String targetMessage) { + this.targetMessage = targetMessage; + } + + + public int getMessageCount() { + return messageCount.get(); + } + + + @Override + public boolean isLoggable(LogRecord record) { + String msg = record.getMessage(); + if (msg != null && msg.contains(targetMessage)) { + messageCount.incrementAndGet(); + } + + return true; + } +} Propchange: tomcat/trunk/test/org/apache/tomcat/unittest/TesterLogValidationFilter.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org