Author: davsclaus
Date: Tue May 22 18:18:30 2012
New Revision: 1341583

URL: http://svn.apache.org/viewvc?rev=1341583&view=rev
Log:
Use unique temp folder for osgi pax runner to avoid locking issue on windows.

Modified:
    
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java

Modified: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java?rev=1341583&r1=1341582&r2=1341583&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
 (original)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
 Tue May 22 18:18:30 2012
@@ -15,10 +15,15 @@
  * limitations under the License.
  */
 package org.apache.camel.itest.osgi;
+import java.io.File;
+import java.io.IOException;
 import java.net.URL;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.osgi.CamelContextFactory;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.FileUtil;
 import org.apache.karaf.testing.Helper;
 import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
@@ -37,6 +42,8 @@ import static org.ops4j.pax.exam.contain
 
 public class OSGiIntegrationTestSupport extends CamelTestSupport {
     protected static final transient Logger LOG = 
LoggerFactory.getLogger(OSGiIntegrationTestSupport.class);
+    protected static final AtomicInteger COUNTER = new AtomicInteger();
+    protected static String workDir = "target/paxrunner/";
     @Inject
     protected BundleContext bundleContext;
     
@@ -117,6 +124,21 @@ public class OSGiIntegrationTestSupport 
     }
     
     public static Option[] getDefaultCamelKarafOptions() {
+        // create temporary working directory that is unique to avoid windows 
issues
+        // lock files between tests, and causing tests to fail
+        deleteDirectory("target/paxrunner");
+
+        // check if file exists
+        int failsafe = 1000;
+        workDir = "target/paxrunner/work-" + COUNTER.getAndIncrement();
+        File dir = new File(workDir);
+        while (dir.exists() && failsafe-- > 0) {
+            workDir = "target/paxrunner/work-" + COUNTER.getAndIncrement();
+            dir = new File(workDir);
+        }
+        createDirectory(workDir);
+        System.out.println("Using working directory: " + workDir);
+
         Option[] options = combine(
             // Set the karaf environment with some customer configuration
             combine(
@@ -136,7 +158,7 @@ public class OSGiIntegrationTestSupport 
             scanFeatures(getCamelKarafFeatureUrl(),                         
                 "camel-core", "camel-spring", "camel-test"),
                                    
-            workingDirectory("target/paxrunner/"));
+            workingDirectory(workDir));
 
             //equinox(),
             //felix());


Reply via email to