You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/10/14 12:24:42 UTC
[2/6] camel git commit: Allow to turn on dumping route coverage
globally via JVM system property.
Allow to turn on dumping route coverage globally via JVM system property.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f5851a37
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f5851a37
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f5851a37
Branch: refs/heads/master
Commit: f5851a37693a93a2936702e47354d1f65c8ab501
Parents: a750723
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Oct 13 10:24:40 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 14 14:09:42 2017 +0200
----------------------------------------------------------------------
.../test/spring/CamelAnnotationsHandler.java | 3 ++-
.../spring/CamelSpringTestContextLoader.java | 3 ++-
.../camel/test/spring/EnableRouteCoverage.java | 2 ++
.../camel/test/junit4/CamelTestSupport.java | 19 +++++++++++++++----
4 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f5851a37/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
index 071891f..70f768a 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
@@ -33,6 +33,7 @@ import org.apache.camel.spi.Breakpoint;
import org.apache.camel.spi.Debugger;
import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
@@ -79,7 +80,7 @@ public final class CamelAnnotationsHandler {
*/
public static void handleRouteCoverage(ConfigurableApplicationContext context, Class<?> testClass, Function testMethod) throws Exception {
if (testClass.isAnnotationPresent(EnableRouteCoverage.class)) {
- System.setProperty("CamelTestRouteCoverage", "true");
+ System.setProperty(CamelTestSupport.ROUTE_COVERAGE_ENABLED, "true");
CamelSpringTestHelper.doToSpringCamelContexts(context, new CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {
http://git-wip-us.apache.org/repos/asf/camel/blob/f5851a37/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
index 434f188..049bc7c 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
@@ -35,6 +35,7 @@ import org.apache.camel.spi.Debugger;
import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spring.SpringCamelContext;
import org.apache.camel.test.ExcludingPackageScanClassResolver;
+import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -283,7 +284,7 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader {
*/
private void handleRouteCoverage(GenericApplicationContext context, Class<?> testClass) throws Exception {
if (testClass.isAnnotationPresent(EnableRouteCoverage.class)) {
- System.setProperty("CamelTestRouteCoverage", "true");
+ System.setProperty(CamelTestSupport.ROUTE_COVERAGE_ENABLED, "true");
CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() {
http://git-wip-us.apache.org/repos/asf/camel/blob/f5851a37/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java
index 13c8514..44523da 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java
@@ -29,6 +29,8 @@ import java.lang.annotation.Target;
* <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.
+ * <p/>
+ * You can also turn on route coverage globally via setting JVM system property <tt>CamelTestRouteCoverage=true</tt>.
*/
@Documented
@Inherited
http://git-wip-us.apache.org/repos/asf/camel/blob/f5851a37/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 2206822..9157d55 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
@@ -91,6 +91,12 @@ import org.slf4j.LoggerFactory;
* @version
*/
public abstract class CamelTestSupport extends TestSupport {
+
+ /**
+ * JVM system property which can be set to true to turn on dumping route coverage statistics.
+ */
+ public static final String ROUTE_COVERAGE_ENABLED = "CamelTestRouteCoverage";
+
private static final Logger LOG = LoggerFactory.getLogger(CamelTestSupport.class);
private static final ThreadLocal<Boolean> INIT = new ThreadLocal<Boolean>();
private static ThreadLocal<ModelCamelContext> threadCamelContext = new ThreadLocal<ModelCamelContext>();
@@ -128,6 +134,8 @@ public abstract class CamelTestSupport extends TestSupport {
* <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.
+ * <p/>
+ * You can also turn on route coverage globally via setting JVM system property <tt>CamelTestRouteCoverage=true</tt>.
*
* @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.
*/
@@ -284,7 +292,7 @@ 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 coverage is enabled (it requires JMX)
- boolean jmx = useJmx() || isDumpRouteCoverage();
+ boolean jmx = useJmx() || isRouteCoverageEnabled();
if (jmx) {
enableJMX();
} else {
@@ -382,6 +390,10 @@ public abstract class CamelTestSupport extends TestSupport {
}
}
+ private boolean isRouteCoverageEnabled() {
+ return System.getProperty(ROUTE_COVERAGE_ENABLED, "false").equalsIgnoreCase("true") || isDumpRouteCoverage();
+ }
+
@After
public void tearDown() throws Exception {
long time = watch.stop();
@@ -391,8 +403,7 @@ 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
- boolean coverage = System.getProperty("CamelTestRouteCoverage", "false").equalsIgnoreCase("true") || isDumpRouteCoverage();
- if (coverage) {
+ if (isRouteCoverageEnabled()) {
String className = this.getClass().getSimpleName();
String dir = "target/camel-route-coverage";
String name = className + "-" + getTestMethodName() + ".xml";
@@ -411,7 +422,7 @@ public abstract class CamelTestSupport extends TestSupport {
file.mkdirs();
file = new File(dir, name);
- log.info("Dumping route coverage to file: " + file);
+ log.info("Dumping route coverage to file: {}", file);
InputStream is = new ByteArrayInputStream(combined.getBytes());
OutputStream os = new FileOutputStream(file, false);
IOHelper.copyAndCloseInput(is, os);