camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-10345: camel-test has route coverage summary. Work in progress.
Date Thu, 06 Oct 2016 02:36:31 GMT
Repository: camel
Updated Branches:
  refs/heads/10345 [created] 202c1b2a4


CAMEL-10345: camel-test has route coverage summary. Work in progress.


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

Branch: refs/heads/10345
Commit: 202c1b2a4c442dfb6a6f3f8a784ad3b037fdd4d0
Parents: bb57091
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Oct 5 22:35:36 2016 -0400
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Oct 5 22:35:36 2016 -0400

----------------------------------------------------------------------
 .../camel/test/junit4/CamelTestSupport.java     | 44 ++++++++++++++++++++
 .../camel/test/patterns/SimpleMockTest.java     |  5 +++
 .../src/test/resources/log4j2.properties        |  1 +
 3 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/202c1b2a/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 1ac6918..15b6164 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
@@ -25,7 +25,10 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 
@@ -40,10 +43,13 @@ import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.Route;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.Service;
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
+import org.apache.camel.api.management.mbean.ManagedProcessMBean;
+import org.apache.camel.api.management.mbean.ManagedRouteMBean;
 import org.apache.camel.builder.AdviceWithRouteBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -387,11 +393,49 @@ public abstract class CamelTestSupport extends TestSupport {
                 String xml = managedCamelContext.dumpRoutesCoverageAsXml();
                 String combined = "<camelRouteCoverage>\n" + gatherTestDetailsAsXml()
+ xml + "\n</camelRouteCoverage>";
 
+
+
                 File file = new File(dir);
                 // ensure dir exists
                 file.mkdirs();
                 file = new File(dir, name);
 
+                // gather summary of number of routes and whether any routes was missing
+                long total = managedCamelContext.getExchangesTotal();
+
+                StringBuffer sb = new StringBuffer();
+                sb.append("Coverage Summary\n");
+                sb.append("\tCamelContext: ").append(managedCamelContext.getCamelId()).append("
Total: ").append(total).append("\n");
+
+                // loop routes and get their total counter
+                for (Route route : context.getRoutes()) {
+                    String id = route.getId();
+                    ManagedRouteMBean managedRoute = context.getManagedRoute(id, ManagedRouteMBean.class);
+                    Long routeTotal = managedRoute.getExchangesTotal();
+                    int routePercentage = Math.round(total / routeTotal * 100);
+                    sb.append("\tRoute: ").append(id).append(" Total: ").append(routeTotal).append("
Percentage: ").append(routePercentage).append("%\n");
+                    // find all the processors
+
+                    MBeanServer server = context.getManagementStrategy().getManagementAgent().getMBeanServer();
+                    if (server != null) {
+                        String domain = context.getManagementStrategy().getManagementAgent().getMBeanServerDefaultDomain();
+                        ObjectName on = new ObjectName(domain + ":context=" + context.getManagementName()
+ ",type=processors,name=*");
+                        Set<ObjectName> names = server.queryNames(on, null);
+                        for (ObjectName o : names) {
+                            String pName = o.getKeyProperty("name");
+                            pName = ObjectName.unquote(pName);
+                            ManagedProcessMBean managedProcessor = context.getManagedProcessor(pName,
ManagedProcessMBean.class);
+                            if (managedProcessor != null) {
+                                String pid = managedProcessor.getProcessorId();
+                                Long pTotal = managedProcessor.getExchangesTotal();
+                                int pPercentage = Math.round(total / pTotal * 100);
+                                sb.append("\tProcessor: ").append(pid).append(" Total: ").append(pTotal).append("
Percentage: ").append(pPercentage).append("%\n");
+                            }
+                        }
+                    }
+                }
+                log.info(sb.toString());
+
                 log.info("Dumping route coverage to file: " + file);
                 InputStream is = new ByteArrayInputStream(combined.getBytes());
                 OutputStream os = new FileOutputStream(file, false);

http://git-wip-us.apache.org/repos/asf/camel/blob/202c1b2a/components/camel-test/src/test/java/org/apache/camel/test/patterns/SimpleMockTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test/src/test/java/org/apache/camel/test/patterns/SimpleMockTest.java
b/components/camel-test/src/test/java/org/apache/camel/test/patterns/SimpleMockTest.java
index 1c3e00b..a1582a6 100644
--- a/components/camel-test/src/test/java/org/apache/camel/test/patterns/SimpleMockTest.java
+++ b/components/camel-test/src/test/java/org/apache/camel/test/patterns/SimpleMockTest.java
@@ -23,6 +23,11 @@ import org.junit.Test;
 
 public class SimpleMockTest extends CamelTestSupport {
 
+    @Override
+    public boolean isDumpRouteCoverage() {
+        return true;
+    }
+
     @Test
     public void testMock() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");

http://git-wip-us.apache.org/repos/asf/camel/blob/202c1b2a/components/camel-test/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-test/src/test/resources/log4j2.properties b/components/camel-test/src/test/resources/log4j2.properties
index 3cd5cc7..50d9866 100644
--- a/components/camel-test/src/test/resources/log4j2.properties
+++ b/components/camel-test/src/test/resources/log4j2.properties
@@ -28,3 +28,4 @@ logger.springframework.name = org.springframework
 logger.springframework.level = WARN
 rootLogger.level = INFO
 rootLogger.appenderRef.file.ref = file
+rootLogger.appenderRef.out.ref = out


Mime
View raw message