camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1375019 - in /camel/trunk/components/camel-test-blueprint/src: main/java/org/apache/camel/test/blueprint/ test/java/org/apache/camel/test/blueprint/
Date Mon, 20 Aug 2012 13:49:04 GMT
Author: davsclaus
Date: Mon Aug 20 13:49:04 2012
New Revision: 1375019

URL: http://svn.apache.org/viewvc?rev=1375019&view=rev
Log:
CAMEL-5507: Improved blueprint test on windows by having test-bundle directory for the test
bundle that is created for testing that isnt deletable out of the box when the test terminates.
This avoids a 5 sec delete attempt that otherwise would fail on windows, making test slower.

Modified:
    camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
    camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
    camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/FilterTest.java

Modified: camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java?rev=1375019&r1=1375018&r2=1375019&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
(original)
+++ camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
Mon Aug 20 13:49:04 2012
@@ -16,21 +16,10 @@
  */
 package org.apache.camel.test.blueprint;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
+import java.io.*;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.jar.JarInputStream;
 
 import de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl;
@@ -46,13 +35,7 @@ import org.apache.camel.util.ObjectHelpe
 import org.apache.camel.util.ResourceHelper;
 import org.ops4j.pax.swissbox.tinybundles.core.TinyBundle;
 import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.*;
 import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -91,18 +74,23 @@ public final class CamelBlueprintHelper 
     }
 
     public static BundleContext createBundleContext(String name, String bundleFilter, TinyBundle
bundle) throws Exception {
-        deleteDirectory("target/bundles");
-        createDirectory("target/bundles");
-
         // ensure pojosr stores bundles in an unique target directory
-        System.setProperty("org.osgi.framework.storage", "target/bundles/" + System.currentTimeMillis());
+        String uid = "" + System.currentTimeMillis();
+        String tempDir = "target/bundles/" + uid;
+        System.setProperty("org.osgi.framework.storage", tempDir);
+        createDirectory(tempDir);
+
+        // use another directory for the jar of the bundle as it cannot be in the same directory
+        // as it has a file lock during running the tests which will cause the temp dir to
not be
+        // fully deleted between tests
+        createDirectory("target/test-bundles");
 
         // get the bundles
         List<BundleDescriptor> bundles = getBundleDescriptors(bundleFilter);
 
         if (bundle != null) {
-            String jarName = name.toLowerCase();
-            bundles.add(getBundleDescriptor("target/bundles/" + jarName + ".jar", bundle));
+            String jarName = name.toLowerCase(Locale.ENGLISH) + "-" + uid + ".jar";
+            bundles.add(getBundleDescriptor("target/test-bundles/" + jarName, bundle));
         }
 
         if (LOG.isDebugEnabled()) {
@@ -124,10 +112,22 @@ public final class CamelBlueprintHelper 
     public static void disposeBundleContext(BundleContext bundleContext) throws BundleException
{
         try {
             if (bundleContext != null) {
-                bundleContext.getBundle().stop();
+                List<Bundle> bundles = new ArrayList<Bundle>();
+                bundles.addAll(Arrays.asList(bundleContext.getBundles()));
+                Collections.reverse(bundles);
+                for (Bundle bundle : bundles) {
+                    LOG.debug("Stopping bundle {}", bundle);
+                    bundle.stop();
+                }
             }
+        } catch (Exception e) {
+            LOG.warn("Error during disposing BundleContext. This exception will be ignored.",
e);
         } finally {
-            System.clearProperty("org.osgi.framework.storage");
+            String tempDir = System.clearProperty("org.osgi.framework.storage");
+            if (tempDir != null) {
+                LOG.info("Deleting work directory {}", tempDir);
+                deleteDirectory(tempDir);
+            }
         }
     }
 
@@ -296,13 +296,19 @@ public final class CamelBlueprintHelper 
 
     private static BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws
Exception {
         File file = new File(path);
-        FileOutputStream fos = new FileOutputStream(file, true);
+        // tell the JVM its okay to delete this file on exit as its a temporary file
+        // the JVM may not successfully delete the file though
+        file.deleteOnExit();
+
+        FileOutputStream fos = new FileOutputStream(file, false);
+        InputStream is = bundle.build();
         try {
-            IOHelper.copyAndCloseInput(bundle.build(), fos);
+            IOHelper.copyAndCloseInput(is, fos);
         } finally {
-            IOHelper.close(fos);
+            IOHelper.close(is, fos);
         }
 
+        BundleDescriptor answer = null;
         FileInputStream fis = null;
         JarInputStream jis = null;
         try {
@@ -313,13 +319,15 @@ public final class CamelBlueprintHelper 
                 headers.put(entry.getKey().toString(), entry.getValue().toString());
             }
 
-            return new BundleDescriptor(
+            answer = new BundleDescriptor(
                     bundle.getClass().getClassLoader(),
                     new URL("jar:" + file.toURI().toString() + "!/"),
                     headers);
         } finally {
-            IOHelper.close(fis, jis);
+            IOHelper.close(jis, fis);
         }
+
+        return answer;
     }
 
 }

Modified: camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java?rev=1375019&r1=1375018&r2=1375019&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
(original)
+++ camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
Mon Aug 20 13:49:04 2012
@@ -63,7 +63,6 @@ public abstract class CamelBlueprintTest
 
     /**
      * Return the system bundle context
-     * @return
      */
     protected BundleContext getBundleContext() {
         return bundleContext;

Modified: camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/FilterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/FilterTest.java?rev=1375019&r1=1375018&r2=1375019&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/FilterTest.java
(original)
+++ camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/FilterTest.java
Mon Aug 20 13:49:04 2012
@@ -20,6 +20,7 @@ import org.apache.camel.EndpointInject;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**



Mime
View raw message