activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1211533 - in /activemq/trunk/activemq-core/src/test/java/org/apache/activemq: bugs/AMQ2902Test.java bugs/AMQ3567Test.java util/DefaultTestAppender.java
Date Wed, 07 Dec 2011 16:56:50 GMT
Author: gtully
Date: Wed Dec  7 16:56:50 2011
New Revision: 1211533

URL: http://svn.apache.org/viewvc?rev=1211533&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3623 - Add DefaultTestAppender utility abstract
class. patch applied with thanks

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DefaultTestAppender.java
  (with props)
Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2902Test.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3567Test.java

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2902Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2902Test.java?rev=1211533&r1=1211532&r2=1211533&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2902Test.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2902Test.java Wed
Dec  7 16:56:50 2011
@@ -24,6 +24,7 @@ import junit.framework.TestCase;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.TransportConnection;
 import org.apache.activemq.transport.TransportDisposedIOException;
+import org.apache.activemq.util.DefaultTestAppender;
 import org.apache.log4j.Appender;
 import org.apache.log4j.Layout;
 import org.apache.log4j.Level;
@@ -35,21 +36,9 @@ import org.apache.log4j.spi.LoggingEvent
 public class AMQ2902Test extends TestCase {
     final AtomicBoolean gotExceptionInLog = new AtomicBoolean(Boolean.FALSE);
     final AtomicBoolean failedToFindMDC = new AtomicBoolean(Boolean.FALSE);
-
-    Appender appender = new Appender() {
-        public void addFilter(Filter newFilter) {
-        }
-
-        public Filter getFilter() {
-            return null;
-        }
-
-        public void clearFilters() {
-        }
-
-        public void close() {
-        }
-
+    
+    Appender appender = new DefaultTestAppender() {
+        @Override
         public void doAppend(LoggingEvent event) {
             if (event.getThrowableInformation() != null
                     && event.getThrowableInformation().getThrowable() instanceof
TransportDisposedIOException) {
@@ -60,31 +49,6 @@ public class AMQ2902Test extends TestCas
             }
             return;
         }
-
-        public String getName() {
-            return "AMQ2902TestAppender";
-        }
-
-        public void setErrorHandler(ErrorHandler errorHandler) {
-        }
-
-        public ErrorHandler getErrorHandler() {
-            return null;
-        }
-
-        public void setLayout(Layout layout) {
-        }
-
-        public Layout getLayout() {
-            return null;
-        }
-
-        public void setName(String name) {
-        }
-
-        public boolean requiresLayout() {
-            return false;
-        }
     };
 
     public void testNoExceptionOnClosewithStartStop() throws JMSException {

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3567Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3567Test.java?rev=1211533&r1=1211532&r2=1211533&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3567Test.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3567Test.java Wed
Dec  7 16:56:50 2011
@@ -22,6 +22,7 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileReader;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.jms.Connection;
 import javax.jms.Destination;
@@ -35,10 +36,12 @@ import javax.jms.Session;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.util.DefaultTestAppender;
 import org.apache.log4j.Layout;
 import org.apache.log4j.Level;
 import org.apache.log4j.PatternLayout;
 import org.apache.log4j.WriterAppender;
+import org.apache.log4j.spi.LoggingEvent;
 import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -74,12 +77,24 @@ public class AMQ3567Test {
     @Test
     public void runTest() throws Exception {
         produceSingleMessage();
-        File file = File.createTempFile("whatever", null);
-        FileOutputStream fos = new FileOutputStream(file);
         org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger("org.apache.activemq.util.ServiceSupport");
-        Layout layout = new PatternLayout("%d | %-5p | %c - %m%n");
-        WriterAppender appender = new WriterAppender(layout, fos);
-        log4jLogger.addAppender(appender);
+        final AtomicBoolean failed = new AtomicBoolean(false);
+
+        log4jLogger.addAppender(new DefaultTestAppender() {
+            @Override
+            public void doAppend(LoggingEvent event) {
+                if (event.getThrowableInformation() != null) {
+                    if (event.getThrowableInformation().getThrowable() instanceof InterruptedException)
{
+                        InterruptedException ie = (InterruptedException)event.getThrowableInformation().getThrowable();
+                        if (ie.getMessage().startsWith("Could not stop service:")) {
+                            logger.info("Received an interrupted exception : ", ie);
+                            failed.set(true);
+                        }
+                    }
+                }
+            }
+        });
+        
         Level level = log4jLogger.getLevel();
         log4jLogger.setLevel(Level.DEBUG);
 
@@ -88,27 +103,12 @@ public class AMQ3567Test {
         try {
             stopConsumer();
             stopBroker();
-            log4jLogger.removeAppender(appender);
-            fos.close();
-            read = new BufferedReader(new FileReader(file));
-            String line;
-
-            while ((line = read.readLine()) != null) {
-                if (line.indexOf("InterruptedException") > -1) {
-                    if (line.indexOf("Could not stop service:") > -1) {
-                        logger.info("Received an interrupted exception {}", line);
-                        fail("An Interrupt exception was generated");
-                    }
-                }
+            if (failed.get()) {
+                fail("An Interrupt exception was generated");
             }
 
         } finally {
             log4jLogger.setLevel(level);
-
-            if (read != null)
-                read.close();
-
-            file.deleteOnExit();
         }
     }
 

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DefaultTestAppender.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DefaultTestAppender.java?rev=1211533&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DefaultTestAppender.java
(added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DefaultTestAppender.java
Wed Dec  7 16:56:50 2011
@@ -0,0 +1,83 @@
+/**
+ * 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.activemq.util;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.Layout;
+import org.apache.log4j.spi.ErrorHandler;
+import org.apache.log4j.spi.Filter;
+
+public abstract class DefaultTestAppender implements Appender {
+    
+    String name = this.getClass().getSimpleName();
+    
+    @Override
+    public void addFilter(Filter newFilter) {
+
+    }
+
+    @Override
+    public Filter getFilter() {
+        return null;
+    }
+
+    @Override
+    public void clearFilters() {
+
+    }
+
+    @Override
+    public void close() {
+
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public void setErrorHandler(ErrorHandler errorHandler) {
+
+    }
+
+    @Override
+    public ErrorHandler getErrorHandler() {
+        return null;
+    }
+
+    @Override
+    public void setLayout(Layout layout) {
+
+    }
+
+    @Override
+    public Layout getLayout() {
+        return null;
+    }
+
+    @Override
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public boolean requiresLayout() {
+        return false;
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DefaultTestAppender.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/DefaultTestAppender.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message