camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/3] camel git commit: CAMEL-8656: camel-test - Add option to dump route stats to files.
Date Sat, 18 Apr 2015 09:03:44 GMT
CAMEL-8656: camel-test - Add option to dump route stats to files.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b6bdbc24
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b6bdbc24
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b6bdbc24

Branch: refs/heads/master
Commit: b6bdbc24159eae45e2e4042c456c8d4a294fdbd9
Parents: f911084
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Apr 18 11:06:29 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Apr 18 11:06:29 2015 +0200

----------------------------------------------------------------------
 .../mbean/RouteCoverageXmlParser.java           | 14 ++++++++++++--
 .../camel/test/junit4/CamelTestSupport.java     | 20 ++++++++++----------
 .../apache/camel/test/patterns/FilterTest.java  |  2 +-
 3 files changed, 23 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b6bdbc24/camel-core/src/main/java/org/apache/camel/management/mbean/RouteCoverageXmlParser.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/RouteCoverageXmlParser.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/RouteCoverageXmlParser.java
index 5dc9702..fa8d389 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/RouteCoverageXmlParser.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/RouteCoverageXmlParser.java
@@ -36,14 +36,22 @@ import org.xml.sax.helpers.DefaultHandler;
 
 /**
  * An XML parser that uses SAX to enrich route stats in the route dump.
+ * <p/>
+ * The coverage details:
+ * <ul>
+ *     <li>exchangesTotal - Total number of exchanges</li>
+ *     <li>totalProcessingTime - Total processing time in millis</li>
+ * </ul>
+ * Is included as attributes on the route nodes.
  */
 public final class RouteCoverageXmlParser {
 
     /**
      * Parses the XML.
      *
-     * @param is the XML content as an input stream
-     * @return the DOM model
+     * @param camelContext the CamelContext
+     * @param is           the XML content as an input stream
+     * @return the DOM model of the routes with coverage information stored as attributes
      * @throws Exception is thrown if error parsing
      */
     public static Document parseXml(final CamelContext camelContext, final InputStream is)
throws Exception {
@@ -86,6 +94,8 @@ public final class RouteCoverageXmlParser {
                                 long totalTime = route.getTotalProcessingTime();
                                 el.setAttribute("totalProcessingTime", "" + totalTime);
                             }
+                        } else if ("from".equals(qName)) {
+                            // TODO: include the stats from the route mbean as that would
be the same
                         } else {
                             ManagedProcessorMBean processor = camelContext.getManagedProcessor(id,
ManagedProcessorMBean.class);
                             if (processor != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/b6bdbc24/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
index 9154ac9..b6931de 100644
--- a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
+++ b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
@@ -102,14 +102,14 @@ public abstract class CamelTestSupport extends TestSupport {
     }
 
     /**
-     * Whether to dump route utilization stats at the end of the test.
+     * Whether to dump route coverage stats at the end of the test.
      * <p/>
      * This allows tooling or manual inspection of the stats, so you can generate a route
trace diagram of which EIPs
      * have been in use and which have not. Similar concepts as a code coverage report.
      *
-     * @return <tt>true</tt> to write route stats in an xml file in the <tt>target</tt>
directory after the test has finished.
+     * @return <tt>true</tt> to write route coverage status in an xml file in
the <tt>target/camel-route-coverage</tt> directory after the test has finished.
      */
-    public boolean isDumpRouteStats() {
+    public boolean isDumpRouteCoverage() {
         return false;
     }
 
@@ -257,8 +257,8 @@ public abstract class CamelTestSupport extends TestSupport {
 
     private void doSetUp() throws Exception {
         log.debug("setUp test");
-        // jmx is enabled if we have configured to use it, or if dump route stats is enabled
(it requires JMX)
-        boolean jmx = useJmx() || isDumpRouteStats();
+        // jmx is enabled if we have configured to use it, or if dump route coverage is enabled
(it requires JMX)
+        boolean jmx = useJmx() || isDumpRouteCoverage();
         if (jmx) {
             enableJMX();
         } else {
@@ -362,21 +362,21 @@ public abstract class CamelTestSupport extends TestSupport {
         log.info("Took: " + TimeUtils.printDuration(time) + " (" + time + " millis)");
 
         // if we should dump route stats, then write that to a file
-        if (isDumpRouteStats()) {
+        if (isDumpRouteCoverage()) {
             String className = this.getClass().getSimpleName();
-            String dir = "target/camel-route-stats";
+            String dir = "target/camel-route-coverage";
             String name = className + "-" + getTestMethodName() + ".xml";
 
             ManagedCamelContextMBean managedCamelContext = context.getManagedCamelContext();
             if (managedCamelContext == null) {
-                log.warn("Cannot dump route stats to file as JMX is not enabled. Override
useJmx() method to enable JMX in the unit test classes.");
+                log.warn("Cannot dump route coverage to file as JMX is not enabled. Override
useJmx() method to enable JMX in the unit test classes.");
             } else {
-                String xml = managedCamelContext.dumpRoutesStatsAsXml(false, true);
+                String xml = managedCamelContext.dumpRoutesCoverageAsXml();
                 File file = new File(dir);
                 // ensure dir exists
                 file.mkdirs();
                 file = new File(dir, name);
-                log.info("Dumping route stats to file: " + file);
+                log.info("Dumping route coverage to file: " + file);
                 InputStream is = new ByteArrayInputStream(xml.getBytes());
                 OutputStream os = new FileOutputStream(file, false);
                 IOHelper.copyAndCloseInput(is, os);

http://git-wip-us.apache.org/repos/asf/camel/blob/b6bdbc24/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java
b/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java
index ce56986..65ef132 100644
--- a/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java
+++ b/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java
@@ -39,7 +39,7 @@ public class FilterTest extends CamelTestSupport {
     protected ProducerTemplate template;
 
     @Override
-    public boolean isDumpRouteStats() {
+    public boolean isDumpRouteCoverage() {
         return true;
     }
 


Mime
View raw message