Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 11957 invoked from network); 29 Sep 2006 08:50:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 Sep 2006 08:50:05 -0000 Received: (qmail 30464 invoked by uid 500); 29 Sep 2006 08:50:04 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 30445 invoked by uid 500); 29 Sep 2006 08:50:04 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 30435 invoked by uid 99); 29 Sep 2006 08:50:04 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Sep 2006 01:50:04 -0700 X-ASF-Spam-Status: No, hits=-8.6 required=5.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:49457] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id FF/64-10102-B3EDC154 for ; Fri, 29 Sep 2006 01:50:03 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 203AD1A984E; Fri, 29 Sep 2006 01:50:01 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r451170 - in /incubator/activemq/trunk/activemq-optional/src/test: java/org/apache/activemq/util/JmsLogAppenderTest.java resources/jndi.properties resources/org/apache/activemq/util/test-log4j.properties Date: Fri, 29 Sep 2006 08:50:00 -0000 To: activemq-commits@geronimo.apache.org From: aco@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060929085001.203AD1A984E@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: aco Date: Fri Sep 29 01:49:59 2006 New Revision: 451170 URL: http://svn.apache.org/viewvc?view=rev&rev=451170 Log: Added test case for JmsLogAppender For: https://issues.apache.org/activemq/browse/AMQ-935 Added: incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties (with props) Modified: incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties Modified: incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java?view=diff&rev=451170&r1=451169&r2=451170 ============================================================================== --- incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java (original) +++ incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java Fri Sep 29 01:49:59 2006 @@ -24,23 +24,89 @@ import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; +import org.apache.log4j.Level; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.command.ActiveMQTopic; + +import javax.jms.JMSException; +import javax.jms.Connection; +import javax.jms.MessageConsumer; +import javax.jms.Session; +import javax.jms.TextMessage; -/** - * @version $Revision$ - */ public class JmsLogAppenderTest extends TestCase { + protected BrokerService broker; + public void testLoggingWithJMS() throws IOException, JMSException { + // Setup the consumers + MessageConsumer info, debug, warn; + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost"); + Connection conn = factory.createConnection(); + conn.start(); + + warn = conn.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(new ActiveMQTopic("log4j.MAIN.WARN")); + info = conn.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(new ActiveMQTopic("log4j.MAIN.INFO")); + debug = conn.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(new ActiveMQTopic("log4j.MAIN.DEBUG")); + + // lets try configure log4j + Properties properties = new Properties(); + properties.load(getClass().getResourceAsStream("test-log4j.properties")); + PropertyConfigurator.configure(properties); + + Logger warnLog, infoLog, debugLog; + + warnLog = Logger.getLogger("MAIN.WARN"); + warnLog.setLevel(Level.WARN); + warnLog.warn("Warn Message"); + warnLog.info("Info Message"); + warnLog.debug("Debug Message"); + + infoLog = Logger.getLogger("MAIN.INFO"); + infoLog.setLevel(Level.INFO); + infoLog.warn("Warn Message"); + infoLog.info("Info Message"); + infoLog.debug("Debug Message"); + + debugLog = Logger.getLogger("MAIN.DEBUG"); + debugLog.setLevel(Level.DEBUG); + debugLog.warn("Warn Message"); + debugLog.info("Info Message"); + debugLog.debug("Debug Message"); + + TextMessage msg; + + // Test warn level + msg = (TextMessage)warn.receive(1000); + assertNotNull(msg); + assertEquals("Warn Message", msg.getText()); + + msg = (TextMessage)warn.receive(1000); + assertNull(msg); // We should not receive anymore message because our level is warning only + + // Test info level + msg = (TextMessage)info.receive(1000); + assertNotNull(msg); + assertEquals("Warn Message", msg.getText()); + + msg = (TextMessage)info.receive(1000); + assertNotNull(msg); + assertEquals("Info Message", msg.getText()); + + msg = (TextMessage)info.receive(1000); + assertNull(msg); // We should not receive the debug message + + // Test debug level + msg = (TextMessage)debug.receive(1000); + assertNotNull(msg); + assertEquals("Warn Message", msg.getText()); + + msg = (TextMessage)debug.receive(1000); + assertNotNull(msg); + assertEquals("Info Message", msg.getText()); - public void testLoggingWithJMS() throws IOException { - - // lets try configure log4j - Properties properties = new Properties(); - properties.load(getClass().getResourceAsStream("test-log4j.properties")); - PropertyConfigurator.configure(properties); - - Logger.getLogger("FOO.BAR").info("Hello"); - Logger.getLogger("FOO.BAR.WHATNOT").debug("A debug message"); - Logger.getLogger("FOO.BAR.WHATNOT.ANOTHER").warn("Some warnings"); - + msg = (TextMessage)debug.receive(1000); + assertNotNull(msg); } + } Added: incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties?view=auto&rev=451170 ============================================================================== --- incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties (added) +++ incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties Fri Sep 29 01:49:59 2006 @@ -0,0 +1,25 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# START SNIPPET: jndi + +java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory + +# use the following property to configure the default connector +java.naming.provider.url = vm://localhost + +# END SNIPPET: jndi Propchange: incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties?view=diff&rev=451170&r1=451169&r2=451170 ============================================================================== --- incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties (original) +++ incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties Fri Sep 29 01:49:59 2006 @@ -1,3 +1,5 @@ -log4j.rootLogger=info, jms +# Make level to fatal so it would not affect the test case +log4j.rootLogger=fatal, jms -log4j.appender.jms=org.apache.activemq.util.JmsLogAppender +log4j.appender.jms=org.apache.activemq.util.JndiJmsLogAppender +log4j.appender.jms.jndiName=ConnectionFactory