You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2011/07/29 13:16:39 UTC

svn commit: r1152166 - in /camel/trunk/components: camel-spring/src/main/java/org/apache/camel/spring/ camel-test/src/main/java/org/apache/camel/test/ camel-test/src/main/java/org/apache/camel/test/junit4/

Author: dkulp
Date: Fri Jul 29 11:16:38 2011
New Revision: 1152166

URL: http://svn.apache.org/viewvc?rev=1152166&view=rev
Log:
More fixes to get the junit4 test support stuff to be parallel=classes
safe

Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
    camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/CamelSpringTestSupport.java
    camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java?rev=1152166&r1=1152165&r2=1152166&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java Fri Jul 29 11:16:38 2011
@@ -55,6 +55,9 @@ public class SpringCamelContext extends 
         ApplicationContextAware {
 
     private static final transient Logger LOG = LoggerFactory.getLogger(SpringCamelContext.class);
+    
+    private static final ThreadLocal<Boolean> NO_START = new ThreadLocal<Boolean>();
+    
     private ApplicationContext applicationContext;
     private EventEndpoint eventEndpoint;
 
@@ -64,7 +67,13 @@ public class SpringCamelContext extends 
     public SpringCamelContext(ApplicationContext applicationContext) {
         setApplicationContext(applicationContext);
     }
-
+    public static void setNoStart(boolean b) {
+        if (b) {
+            NO_START.set(b);
+        } else {
+            NO_START.remove();
+        }
+    }
     public static SpringCamelContext springCamelContext(ApplicationContext applicationContext) throws Exception {
         // lets try and look up a configured camel context in the context
         String[] names = applicationContext.getBeanNamesForType(SpringCamelContext.class);
@@ -197,9 +206,8 @@ public class SpringCamelContext extends 
     private void maybeStart() throws Exception {
         // for example from unit testing we want to start Camel later and not when Spring framework
         // publish a ContextRefreshedEvent
-        String maybeStart = System.getProperty("maybeStartCamelContext", "true");
 
-        if ("true".equals(maybeStart)) {
+        if (NO_START.get() == null) {
             if (!isStarted() && !isStarting()) {
                 start();
             } else {
@@ -207,7 +215,7 @@ public class SpringCamelContext extends 
                 LOG.trace("Ignoring maybeStart() as Apache Camel is already started");
             }
         } else {
-            LOG.trace("Ignoring maybeStart() as System property maybeStartCamelContext is false");
+            LOG.trace("Ignoring maybeStart() as NO_START is false");
         }
     }
 

Modified: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/CamelSpringTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/CamelSpringTestSupport.java?rev=1152166&r1=1152165&r2=1152166&view=diff
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/CamelSpringTestSupport.java (original)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/CamelSpringTestSupport.java Fri Jul 29 11:16:38 2011
@@ -47,11 +47,11 @@ public abstract class CamelSpringTestSup
         if (!"true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"))) {
             // tell camel-spring it should not trigger starting CamelContext, since we do that later
             // after we are finished setting up the unit test
-            System.setProperty("maybeStartCamelContext", "false");
+            SpringCamelContext.setNoStart(true);
             applicationContext = createApplicationContext();
             assertNotNull("Should have created a valid spring context", applicationContext);
             super.setUp();
-            System.clearProperty("maybeStartCamelContext");
+            SpringCamelContext.setNoStart(false);
         } else {
             log.info("Skipping starting CamelContext as system property skipStartingCamelContext is set to be true.");
         }

Modified: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java?rev=1152166&r1=1152165&r2=1152166&view=diff
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java (original)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java Fri Jul 29 11:16:38 2011
@@ -66,7 +66,7 @@ public abstract class CamelSpringTestSup
             // tell camel-spring it should not trigger starting CamelContext, since we do that later
             // after we are finished setting up the unit test
             synchronized (lock) {
-                System.setProperty("maybeStartCamelContext", "false");
+                SpringCamelContext.setNoStart(true);
                 if (isCreateCamelContextPerClass()) {
                     applicationContext = threadAppContext.get();
                     if (applicationContext == null) {
@@ -77,7 +77,7 @@ public abstract class CamelSpringTestSup
                     applicationContext = createApplicationContext();
                 }
                 assertNotNull("Should have created a valid spring context", applicationContext);
-                System.clearProperty("maybeStartCamelContext");
+                SpringCamelContext.setNoStart(false);
             }
         } else {
             log.info("Skipping starting CamelContext as system property skipStartingCamelContext is set to be true.");