brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [01/11] git commit: Fix failing tests on Windows
Date Mon, 14 Jul 2014 15:35:57 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 342a33679 -> d6ef743c0


Fix failing tests on Windows

  * brooklyn.util.ResourceUtilsTest.testGetResourceViaClasspathWithoutPrefix() fails on windows
paths when OSGi is used
  * Explicitly wait for osgi framework shutdown before deleting the cache folder so all files
are unlocked


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/3bdba4f3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/3bdba4f3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/3bdba4f3

Branch: refs/heads/master
Commit: 3bdba4f37c74a466b3119a32c8532a46fd99b1aa
Parents: d767d78
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Thu Jul 10 12:18:32 2014 +0300
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Thu Jul 10 12:18:32 2014 +0300

----------------------------------------------------------------------
 .../main/java/brooklyn/util/ResourceUtils.java  | 14 ++++++++++---
 .../management/osgi/OsgiStandaloneTest.java     | 21 +++++++++++++++++++-
 2 files changed, 31 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3bdba4f3/core/src/main/java/brooklyn/util/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/ResourceUtils.java b/core/src/main/java/brooklyn/util/ResourceUtils.java
index 347ecbb..5aacfb3 100644
--- a/core/src/main/java/brooklyn/util/ResourceUtils.java
+++ b/core/src/main/java/brooklyn/util/ResourceUtils.java
@@ -227,13 +227,21 @@ public class ResourceUtils {
 
             try {
                 //try as classpath reference, then as file
-                URL u = getLoader().getResource(url);
-                if (u!=null) return u.openStream();
+                try {
+                    URL u = getLoader().getResource(url);
+                    if (u!=null) return u.openStream();
+                } catch (IllegalArgumentException e) {
+                    //Felix installs an additional URL to the system classloader
+                    //which throws an IllegalArgumentException when passed a
+                    //windows path. See ExtensionManager.java static initializer.
+
+                    //ignore, not a classpath resource
+                }
                 if (url.startsWith("/")) {
                     //some getResource calls fail if argument starts with /
                     String urlNoSlash = url;
                     while (urlNoSlash.startsWith("/")) urlNoSlash = urlNoSlash.substring(1);
-                    u = getLoader().getResource(urlNoSlash);
+                    URL u = getLoader().getResource(urlNoSlash);
                     if (u!=null) return u.openStream();
 //                    //Class.getResource can require a /  (else it attempts to be relative)
but Class.getClassLoader doesn't
 //                    u = getLoader().getResource("/"+urlNoSlash);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3bdba4f3/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java b/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java
index e5d60a1..1f55e26 100644
--- a/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java
+++ b/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java
@@ -29,6 +29,7 @@ import java.util.jar.JarInputStream;
 import org.apache.commons.io.FileUtils;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.launch.Framework;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,6 +38,7 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.util.ResourceUtils;
 import brooklyn.util.collections.MutableSet;
 import brooklyn.util.os.Os;
 import brooklyn.util.osgi.Osgis;
@@ -72,9 +74,10 @@ public class OsgiStandaloneTest {
     }
 
     @AfterMethod
-    public void tearDown() throws BundleException, IOException {
+    public void tearDown() throws BundleException, IOException, InterruptedException {
         if (framework!=null) {
             framework.stop();
+            Assert.assertEquals(framework.waitForStop(1000).getType(), FrameworkEvent.STOPPED);
             framework = null;
         }
         if (storageTempDir!=null) {
@@ -186,4 +189,20 @@ public class OsgiStandaloneTest {
         Assert.assertNotNull(aInst);
     }
     
+    @Test
+    public void testLoadAbsoluteWindowsResourceWithInstalledOSGi() {
+        //Felix installs an additional URL to the system classloader
+        //which throws an IllegalArgumentException when passed a
+        //windows path. See ExtensionManager.java static initializer.
+        String context = "mycontext";
+        String dummyPath = "C:\\dummypath";
+        ResourceUtils utils = ResourceUtils.create(this, context);
+        try {
+            utils.getResourceFromUrl(dummyPath);
+            Assert.fail("Non-reachable, should throw an exception for non-existing resource.");
+        } catch (RuntimeException e) {
+            Assert.assertTrue(e.getMessage().startsWith("Error getting resource '"+dummyPath+"'
for "+context));
+        }
+    }
+    
 }


Mime
View raw message