Author: ritchiem Date: Mon Aug 3 13:33:05 2009 New Revision: 800374 URL: http://svn.apache.org/viewvc?rev=800374&view=rev Log: QPID-2002 : Updates to integrate Logging with test ant test runs. MaxChannelsTest/AMQProtoSessionMBean - Ensured CurrentActor is correctly set and removed. Log4jMessageLogger - Correctly Set log level to ensure messages are logged. AbstractActor - Null validation of RootLogger Log4jMessasgeLoggerTest - Updated and removed erroneous tests that were based on inherited log levels. AbstractTestLogSubject - Updated to correctly parse IP given by the use of InternalTestProtocolSession TestApplicationRegistry - Created RootMessageLogger
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractActor.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLogger.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLoggerTest.java qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractActor.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractActor.java?rev=800374&r1=800373&r2=800374&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractActor.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractActor.java Mon Aug 3 13:33:05 2009 @@ -32,6 +32,10 @@ public AbstractActor(RootMessageLogger rootLogger) { + if(rootLogger == null) + { + throw new NullPointerException("RootMessageLogger cannot be null"); + } _rootLogger = rootLogger; } Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLogger.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLogger.java?rev=800374&r1=800373&r2=800374&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLogger.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLogger.java Mon Aug 3 13:33:05 2009 @@ -41,6 +41,7 @@ _level = Level.toLevel(level); _rawMessageLogger = Logger.getLogger(logger); + _rawMessageLogger.setLevel(_level); } public void rawMessage(String message) Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java?rev=800374&r1=800373&r2=800374&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java Mon Aug 3 13:33:05 2009 @@ -65,6 +65,8 @@ import org.apache.qpid.management.common.mbeans.annotations.MBeanDescription; import org.apache.qpid.protocol.AMQConstant; import org.apache.qpid.server.AMQChannel; +import org.apache.qpid.server.logging.actors.CurrentActor; +import org.apache.qpid.server.logging.LogActor; import org.apache.qpid.server.management.AMQManagedObject; import org.apache.qpid.server.management.ManagedObject; @@ -185,6 +187,7 @@ */ public void commitTransactions(int channelId) throws JMException { + CurrentActor.set(getLogActor()); try { AMQChannel channel = _session.getChannel(channelId); @@ -199,6 +202,10 @@ { throw new MBeanException(ex, ex.toString()); } + finally + { + CurrentActor.remove(); + } } /** @@ -209,6 +216,7 @@ */ public void rollbackTransactions(int channelId) throws JMException { + CurrentActor.set(getLogActor()); try { AMQChannel channel = _session.getChannel(channelId); @@ -223,6 +231,10 @@ { throw new MBeanException(ex, ex.toString()); } + finally + { + CurrentActor.remove(); + } } /** @@ -269,18 +281,38 @@ 0, 0); - _session.writeFrame(responseBody.generateFrame(0)); - + CurrentActor.set(getLogActor()); try { - _session.closeSession(); + _session.writeFrame(responseBody.generateFrame(0)); + + try + { + + _session.closeSession(); + } + catch (AMQException ex) + { + throw new MBeanException(ex, ex.toString()); + } } - catch (AMQException ex) + finally { - throw new MBeanException(ex, ex.toString()); + CurrentActor.remove(); } } + /** + * Return the LogActor for this MBean Session + * //fixme currently simply returning the managed sessions LogActor, should + * be the ManagementActor + * @return + */ + private LogActor getLogActor() + { + return _session.getLogActor(); + } + @Override public MBeanNotificationInfo[] getNotificationInfo() { Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLoggerTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLoggerTest.java?rev=800374&r1=800373&r2=800374&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLoggerTest.java (original) +++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/rawloggers/Log4jMessageLoggerTest.java Mon Aug 3 13:33:05 2009 @@ -77,10 +77,8 @@ * Verify that the default configuraion of Log4jMessageLogger will * log a message. * - * @throws IOException - * @throws InterruptedException */ - public void testDefaultLogsMessage() throws IOException, InterruptedException + public void testDefaultLogsMessage() { // Create a logger to test Log4jMessageLogger logger = new Log4jMessageLogger(); @@ -95,28 +93,17 @@ } /** - * This test checks that if the Root Logger level is set such that the INFO - * messages would not be logged then the Log4jMessageLogger default of INFO - * will result in logging not being presented. + * This test verifies that the Log4jMessageLogger does not inherit a logging + * level from the RootLogger. The Log4jMessageLogger default of INFO + * will result in logging being presented. * - * @throws IOException - * @throws InterruptedException */ - public void testDefaultsLogsAtInfo() throws IOException, InterruptedException + public void testLoggerDoesNotInheritRootLevel() { - // Create a logger to test - Log4jMessageLogger logger = new Log4jMessageLogger(); - - //Create Message for test - String message = "testDefaults"; - //Set default logger level to off - Logger.getRootLogger().setLevel(Level.WARN); + Logger.getRootLogger().setLevel(Level.OFF); - // Log the message - logger.rawMessage(message); - - verifyNoLog(message); + testDefaultLogsMessage(); } /** @@ -125,10 +112,8 @@ * Test this by setting the default logger level to off which has been * verified to work by test 'testDefaultsLevelObeyed' * - * @throws IOException - * @throws InterruptedException */ - public void testDefaultLoggerAdjustment() throws IOException, InterruptedException + public void testDefaultLoggerAdjustment() { String loggerName = "TestLogger"; // Create a logger to test @@ -150,41 +135,6 @@ Logger.getLogger(Log4jMessageLogger.DEFAULT_LOGGER).setLevel(originalLevel); } - /** - * Test that changing the log level has an effect. - * Set the level to be debug - * but only set the logger to log at INFO - * there should be no data printed - * subsequently changing the root logger to allow DEBUG should - * show the message - * - * @throws IOException - * @throws InterruptedException - */ - public void testDefaultsLevelObeyed() throws IOException, InterruptedException - { - // Create a logger to test - Log4jMessageLogger logger = new Log4jMessageLogger("DEBUG", Log4jMessageLogger.DEFAULT_LOGGER); - - //Create Message for test - String message = "testDefaults"; - - //Set root logger to INFO only - Logger.getRootLogger().setLevel(Level.INFO); - - // Log the message - logger.rawMessage(message); - - verifyNoLog(message); - - //Set root logger to INFO only - Logger.getRootLogger().setLevel(Level.DEBUG); - - // Log the message - logger.rawMessage(message); - - verifyLogPresent(message); - } /** * Check that the Log Message reached log4j Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java?rev=800374&r1=800373&r2=800374&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java (original) +++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java Mon Aug 3 13:33:05 2009 @@ -112,15 +112,19 @@ assertEquals("Username not as expected", userNameParts[0], user); // Extract IP. + // The connection will be of the format - guest@/127.0.0.1:1/test + // and so our userNamePart will be '/127.0.0.1:1/test' String[] ipParts = userNameParts[1].split("/"); + // We will have three sections assertEquals("Unable to split IP from rest of Connection:" - + userNameParts[1], 2, ipParts.length); + + userNameParts[1], 3, ipParts.length); - assertEquals("IP not as expected", ipParts[0], ipString); + // We need to skip the first '/' split will be empty so validate 1 as IP + assertEquals("IP not as expected", ipString, ipParts[1]); - //Finally check vhost - assertEquals("Virtualhost name not as expected.", vhost, ipParts[1]); + //Finally check vhost which is section 2 + assertEquals("Virtualhost name not as expected.", vhost, ipParts[2]); } /** Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java?rev=800374&r1=800373&r2=800374&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java (original) +++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java Mon Aug 3 13:33:05 2009 @@ -25,6 +25,7 @@ import org.apache.qpid.codec.AMQCodecFactory; import org.apache.qpid.protocol.AMQConstant; import org.apache.qpid.server.AMQChannel; +import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.registry.IApplicationRegistry; import org.apache.qpid.AMQException; @@ -43,6 +44,9 @@ _session = new AMQMinaProtocolSession(new TestIoSession(), _appRegistry .getVirtualHostRegistry(), new AMQCodecFactory(true)); + // Set the current Actor for these tests + CurrentActor.set(_session.getLogActor()); + // Need to authenticate session for it to work, (well for logging to work) _session.setAuthorizedID(new Principal() { @@ -92,6 +96,11 @@ // Yikes fail(e.getMessage()); } + finally + { + //Remove the actor set during the test + CurrentActor.remove(); + } ApplicationRegistry.remove(1); } Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java?rev=800374&r1=800373&r2=800374&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java (original) +++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java Mon Aug 3 13:33:05 2009 @@ -39,6 +39,8 @@ import org.apache.qpid.server.store.TestableMemoryMessageStore; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; +import org.apache.qpid.server.logging.RootMessageLoggerImpl; +import org.apache.qpid.server.logging.rawloggers.Log4jMessageLogger; import java.util.Collection; import java.util.HashMap; @@ -73,6 +75,9 @@ public void initialise() throws Exception { + _rootMessageLogger = new RootMessageLoggerImpl(_configuration, + new Log4jMessageLogger()); + Properties users = new Properties(); users.put("guest", "guest"); --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscr...@qpid.apache.org