You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2017/05/03 10:01:15 UTC

[4/5] brooklyn-server git commit: fix getResources() so it dedupes URLs, fixing test

fix getResources() so it dedupes URLs, fixing test

(exposed now that we load better things through osgi)


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/8a6fc6e2
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/8a6fc6e2
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/8a6fc6e2

Branch: refs/heads/master
Commit: 8a6fc6e21ff35331b10af7c626b7ce58b298f588
Parents: 400a32d
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Apr 28 17:20:04 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue May 2 11:43:47 2017 +0100

----------------------------------------------------------------------
 .../BrooklynClassLoadingContextSequential.java  |  8 ++---
 .../util/core/ClassLoaderUtilsTest.java         | 35 ++++++++++++++++----
 2 files changed, 32 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a6fc6e2/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/BrooklynClassLoadingContextSequential.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/BrooklynClassLoadingContextSequential.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/BrooklynClassLoadingContextSequential.java
index ee55ae9..50a0509 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/BrooklynClassLoadingContextSequential.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/BrooklynClassLoadingContextSequential.java
@@ -104,14 +104,14 @@ public final class BrooklynClassLoadingContextSequential extends AbstractBrookly
 
     @Override
     public Iterable<URL> getResources(String name) {
-        List<Iterable<URL>> resources = Lists.newArrayList();
+        MutableSet<URL> result = MutableSet.<URL>of();
         for (BrooklynClassLoadingContext target : primaries) {
-            resources.add(target.getResources(name));
+            result.addAll(target.getResources(name));
         }
         for (BrooklynClassLoadingContext target : secondaries) {
-            resources.add(target.getResources(name));
+            result.addAll(target.getResources(name));
         }
-        return Iterables.concat(resources);
+        return result;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a6fc6e2/core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java b/core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java
index dfe942b..a9ea938 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java
@@ -26,8 +26,6 @@ import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
 import java.net.URL;
 import java.util.jar.Attributes;
 import java.util.jar.JarOutputStream;
@@ -127,9 +125,32 @@ public class ClassLoaderUtilsTest {
         assertLoadSucceeds(bundle.getSymbolicName() + ":" + bundle.getVersion()+":" + classname, clazz, cluMgmt, cluClass, cluEntity);
     }
 
+    @Test
+    public void testLoadJustOneClassInOsgiWhiteList() throws Exception {
+        String bundlePath = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH;
+        String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
+        String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY;
+        
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), bundlePath);
+
+        mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build();
+        Bundle bundle = installBundle(mgmt, bundleUrl);
+        Class<?> clazz = bundle.loadClass(classname);
+        Entity entity = createSimpleEntity(bundleUrl, clazz);
+        
+        String whiteList = bundle.getSymbolicName()+":"+bundle.getVersion();
+        System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, whiteList);
+        
+        ClassLoaderUtils cluEntity = new ClassLoaderUtils(getClass(), entity);
+
+        BundledName resource = new BundledName(classname).toResource();
+        BundledName bn = new BundledName(resource.bundle, resource.version, "/" + resource.name);
+        Asserts.assertSize(cluEntity.getResources(bn.toString()), 1);
+    }
+    
 
     @Test
-    public void testLoadClassInOsgiWhiteList() throws Exception {
+    public void testVariousLoadersLoadClassInOsgiWhiteList() throws Exception {
         String bundlePath = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH;
         String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
         String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY;
@@ -141,8 +162,8 @@ public class ClassLoaderUtilsTest {
         Class<?> clazz = bundle.loadClass(classname);
         Entity entity = createSimpleEntity(bundleUrl, clazz);
         
-        String whileList = bundle.getSymbolicName()+":"+bundle.getVersion();
-        System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, whileList);
+        String whiteList = bundle.getSymbolicName()+":"+bundle.getVersion();
+        System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, whiteList);
         
         ClassLoaderUtils cluMgmt = new ClassLoaderUtils(getClass(), mgmt);
         ClassLoaderUtils cluClass = new ClassLoaderUtils(clazz);
@@ -160,7 +181,7 @@ public class ClassLoaderUtilsTest {
         
         TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), bundlePath);
 
-        mgmt = LocalManagementContextForTests.builder(true).disableOsgi(false).build();
+        mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build();
         Bundle bundle = installBundle(mgmt, bundleUrl);
         
         Manifest manifest = new Manifest();
@@ -328,7 +349,7 @@ public class ClassLoaderUtilsTest {
         String bundledResource = resource.toString();
         URL resourceUrl = cl.getResource(resource.name);
         assertEquals(clu.getResource(bundledResource), resourceUrl);
-        assertEquals(clu.getResources(bundledResource), ImmutableList.of(resourceUrl));
+        assertEquals(clu.getResources(bundledResource), ImmutableList.of(resourceUrl), "Loading with "+clu);
 
         BundledName rootResource = new BundledName(resource.bundle, resource.version, "/" + resource.name);
         String rootBundledResource = rootResource.toString();