You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2013/02/13 21:11:40 UTC

svn commit: r1445895 - in /activemq/activemq-apollo/trunk: apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala apollo-stomp/src/test/resources/log4j.properties apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala

Author: chirino
Date: Wed Feb 13 20:11:40 2013
New Revision: 1445895

URL: http://svn.apache.org/r1445895
Log:
Dump the status of the broker to the log file when a test fails.

Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/log4j.properties
    activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala?rev=1445895&r1=1445894&r2=1445895&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala Wed Feb 13 20:11:40 2013
@@ -26,6 +26,10 @@ import collection.immutable.HashMap
 import java.io.File
 import org.scalatest.{ParallelTestExecution, OneInstancePerTest}
 import java.util
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.fusesource.hawtbuf.{ByteArrayOutputStream, Buffer}
+import com.fasterxml.jackson.annotation.JsonInclude
+import util.concurrent.CountDownLatch
 
 object BrokerTestSupport {
   import FutureResult._
@@ -166,6 +170,51 @@ class BrokerFunSuiteSupport extends FunS
     super.afterAll()
   }
 
+  override def onTestFailure(e:Throwable) = {
+    info("====== broker state dump start ======")
+    val c = new CountDownLatch(1)
+    broker.dispatch_queue {
+      info(" -- Connections -- ")
+      for(connection <- broker.connections.values) {
+        info(json(connection.get_connection_status))
+      }
+
+      val router = broker.default_virtual_host.local_router
+      router.dispatch_queue {
+        info(" -- Topics -- ")
+        router.topic_domain.destination_by_id.map {
+          case (id, d: Topic) =>
+            d.dispatch_queue.future {
+              info(id+"="+json(d.status(true, true)))
+            }
+        }
+        info(" -- Queues -- ")
+        Future.all(
+          router.queue_domain.destination_by_id.map {
+            case (id, d: Queue) =>
+              d.dispatch_queue.future {
+                info(id+"="+json(d.status(true, true, true)))
+              }
+          }
+        ).onComplete { x=>
+          info(" -- DSubs -- ")
+          Future.all(
+            router.dsub_domain.destination_by_id.map {
+              case (id, d: Queue) =>
+                d.dispatch_queue.future {
+                  info(id+"="+json(d.status(true, true, true)))
+                }
+            }
+          ).onComplete { x=>
+            c.countDown()
+          }
+        }
+      }
+    }
+    c.await()
+    info("====== broker state dump emd ======")
+  }
+
   def connector_port(connector: String) = BrokerTestSupport.connector_port(broker, connector)
   def queue_exists(name: String) = BrokerTestSupport.queue_exists(broker, name)
   def delete_queue(name: String) = BrokerTestSupport.delete_queue(broker, name)
@@ -179,7 +228,12 @@ class BrokerFunSuiteSupport extends FunS
   def dsub_status(name: String) = BrokerTestSupport.dsub_status(broker, name)
   def webadmin_uri(scheme:String = "http") = BrokerTestSupport.webadmin_uri(broker, scheme)
 
-  def json(value:Any) = org.apache.activemq.apollo.dto.JsonCodec.encode(value).ascii().toString;
+
+  def json(value:Any) = {
+    val mapper: ObjectMapper = new ObjectMapper
+    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+    mapper.writerWithDefaultPrettyPrinter().writeValueAsString(value)
+  }
 
 }
 

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/log4j.properties?rev=1445895&r1=1445894&r2=1445895&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/log4j.properties (original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/log4j.properties Wed Feb 13 20:11:40 2013
@@ -32,7 +32,7 @@ log4j.logger.org.apache.activemq.apollo=
 # Console Settings
 log4j.appender.console=org.apache.log4j.ConsoleAppender
 log4j.appender.console.layout=org.apache.log4j.PatternLayout
-log4j.appender.console.layout.ConversionPattern=%-5p | %m%n
+log4j.appender.console.layout.ConversionPattern=%40.40c{2} | %-5p | %m%n
 log4j.appender.console.threshold=INFO
 
 # File Settings
@@ -42,4 +42,4 @@ log4j.appender.logfile.maxFileSize=5MB
 log4j.appender.logfile.maxBackupIndex=5
 log4j.appender.logfile.append=true
 log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
-log4j.appender.logfile.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n
+log4j.appender.logfile.layout.ConversionPattern=%c{2} | %d | %-5p | %m | %c | %t%n

Modified: activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala?rev=1445895&r1=1445894&r2=1445895&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala Wed Feb 13 20:11:40 2013
@@ -58,16 +58,34 @@ abstract class FunSuiteSupport extends F
 
   def skip(check:Boolean=true):Unit = if(check) throw new SkipTestException()
 
+
+  var _log:Log = null
+  override protected def log: Log = {
+    if( _log == null ) {
+      super.log
+    } else {
+      _log
+    }
+  }
+
   override protected def test(testName: String, testTags: Tag*)(testFun: => Unit) {
     super.test(testName, testTags:_*) {
       try {
+        _log = Log(getClass.getName.stripSuffix("$")+":"+testName)
         testFun
       } catch {
         case e:SkipTestException =>
+        case e:Throwable =>
+          onTestFailure(e)
+          throw e
+      } finally {
+        _log = null
       }
     }
   }
 
+  def onTestFailure(e:Throwable) = {}
+
   /**
    * Returns the base directory of the current project
    */