You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/11/29 08:21:52 UTC

[3/6] brooklyn-server git commit: A test to check rebind when bundle prefixes are used to load classes in catalog items

A test to check rebind when bundle prefixes are used to load classes in catalog items


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

Branch: refs/heads/master
Commit: cd9447a35156ca110b8bd2e8290dfe3323b7c9d0
Parents: 870986b
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Mon Oct 31 17:22:37 2016 +0200
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Nov 25 23:28:19 2016 +0000

----------------------------------------------------------------------
 .../brooklyn/catalog/CatalogYamlRebindTest.java |  73 +++++++++++++++----
 .../core/mgmt/osgi/OsgiStandaloneTest.java      |   1 +
 .../entities/SimpleEffectorInitializer.java     |  48 ++++++++++++
 .../brooklyn/util/osgi/OsgiTestResources.java   |   4 +
 .../osgi/brooklyn-test-osgi-entities.jar        | Bin 19168 -> 20814 bytes
 5 files changed, 111 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cd9447a3/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
index 692a45b..4cac9af 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
@@ -83,9 +83,11 @@ public class CatalogYamlRebindTest extends AbstractYamlRebindTest {
     //   - config/attribute cannot be instantiated (e.g. because class no longer on classpath)
     //   - entity file corrupt
 
+    private static final String OSGI_BUNDLE_SYMBOLID_NAME_FULL = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FULL;
     private static final String OSGI_BUNDLE_URL = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
     private static final String OSGI_SIMPLE_ENTITY_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY;
     private static final String OSGI_SIMPLE_POLICY_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_POLICY;
+    private static final String OSGI_SIMPLE_EFFECTOR_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_EFFECTOR;
 
     enum RebindWithCatalogTestMode {
         NO_OP,
@@ -96,6 +98,12 @@ public class CatalogYamlRebindTest extends AbstractYamlRebindTest {
         REPLACE_CATALOG_WITH_NEWER_VERSION;
     }
     
+    enum OsgiMode {
+        NONE,
+        LIBRARY,
+        PREFIX
+    }
+    
     private Boolean defaultEnablementOfFeatureAutoFixatalogRefOnRebind;
     
     @BeforeMethod(alwaysRun=true)
@@ -121,36 +129,43 @@ public class CatalogYamlRebindTest extends AbstractYamlRebindTest {
     @DataProvider
     public Object[][] dataProvider() {
         return new Object[][] {
-            {RebindWithCatalogTestMode.NO_OP, false},
-            {RebindWithCatalogTestMode.NO_OP, true},
+            {RebindWithCatalogTestMode.NO_OP, OsgiMode.NONE},
+            {RebindWithCatalogTestMode.NO_OP, OsgiMode.LIBRARY},
+            {RebindWithCatalogTestMode.NO_OP, OsgiMode.PREFIX},
             
-            {RebindWithCatalogTestMode.STRIP_DEPRECATION_AND_ENABLEMENT_FROM_CATALOG_ITEM, false},
-            {RebindWithCatalogTestMode.STRIP_DEPRECATION_AND_ENABLEMENT_FROM_CATALOG_ITEM, true},
+            {RebindWithCatalogTestMode.STRIP_DEPRECATION_AND_ENABLEMENT_FROM_CATALOG_ITEM, OsgiMode.NONE},
+            {RebindWithCatalogTestMode.STRIP_DEPRECATION_AND_ENABLEMENT_FROM_CATALOG_ITEM, OsgiMode.LIBRARY},
+            {RebindWithCatalogTestMode.STRIP_DEPRECATION_AND_ENABLEMENT_FROM_CATALOG_ITEM, OsgiMode.PREFIX},
             
-            {RebindWithCatalogTestMode.DEPRECATE_CATALOG, false},
-            {RebindWithCatalogTestMode.DEPRECATE_CATALOG, true},
+            {RebindWithCatalogTestMode.DEPRECATE_CATALOG, OsgiMode.NONE},
+            {RebindWithCatalogTestMode.DEPRECATE_CATALOG, OsgiMode.LIBRARY},
+            {RebindWithCatalogTestMode.DEPRECATE_CATALOG, OsgiMode.PREFIX},
             
-            {RebindWithCatalogTestMode.DISABLE_CATALOG, false},
-            {RebindWithCatalogTestMode.DISABLE_CATALOG, true},
+            {RebindWithCatalogTestMode.DISABLE_CATALOG, OsgiMode.NONE},
+            {RebindWithCatalogTestMode.DISABLE_CATALOG, OsgiMode.LIBRARY},
+            {RebindWithCatalogTestMode.DISABLE_CATALOG, OsgiMode.PREFIX},
             
             // For DELETE_CATALOG, see https://issues.apache.org/jira/browse/BROOKLYN-149.
             // Deletes the catalog item before rebind, but the referenced types are still on the 
             // default classpath. Will fallback to loading from classpath.
             //
             // Does not work for OSGi, because our bundle will no longer be available.
-            {RebindWithCatalogTestMode.DELETE_CATALOG, false},
+            {RebindWithCatalogTestMode.DELETE_CATALOG, OsgiMode.NONE},
             
             // Upgrades the catalog item before rebind, deleting the old version.
             // Will automatically upgrade. Test will enable "FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND"
-            {RebindWithCatalogTestMode.REPLACE_CATALOG_WITH_NEWER_VERSION, false},
-            {RebindWithCatalogTestMode.REPLACE_CATALOG_WITH_NEWER_VERSION, true},
+            {RebindWithCatalogTestMode.REPLACE_CATALOG_WITH_NEWER_VERSION, OsgiMode.NONE},
+            {RebindWithCatalogTestMode.REPLACE_CATALOG_WITH_NEWER_VERSION, OsgiMode.LIBRARY},
+            {RebindWithCatalogTestMode.REPLACE_CATALOG_WITH_NEWER_VERSION, OsgiMode.PREFIX},
         };
     }
 
     @Test(dataProvider = "dataProvider")
     @SuppressWarnings({ "deprecation", "unused" })
-    public void testRebindWithCatalogAndApp(RebindWithCatalogTestMode mode, boolean useOsgi) throws Exception {
-        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+    public void testRebindWithCatalogAndApp(RebindWithCatalogTestMode mode, OsgiMode osgiMode) throws Exception {
+        if (osgiMode != OsgiMode.NONE) {
+            TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+        }
 
         if (mode == RebindWithCatalogTestMode.REPLACE_CATALOG_WITH_NEWER_VERSION) {
             BrooklynFeatureEnablement.enable(BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND);
@@ -160,7 +175,7 @@ public class CatalogYamlRebindTest extends AbstractYamlRebindTest {
         String appVersion = "0.1.0";
         
         String appCatalogFormat;
-        if (useOsgi) {
+        if (osgiMode == OsgiMode.LIBRARY) {
             appCatalogFormat = Joiner.on("\n").join(
                     "brooklyn.catalog:",
                     "  id: " + appSymbolicName,
@@ -173,7 +188,35 @@ public class CatalogYamlRebindTest extends AbstractYamlRebindTest {
                     "    brooklyn.enrichers:",
                     "    - type: " + TestEnricher.class.getName(),
                     "    brooklyn.policies:",
-                    "    - type: " + OSGI_SIMPLE_POLICY_TYPE);
+                    "    - type: " + OSGI_SIMPLE_POLICY_TYPE,
+                    "    brooklyn.initializers:",
+                    "    - type: " + OSGI_SIMPLE_EFFECTOR_TYPE);
+        } else if (osgiMode == OsgiMode.PREFIX) {
+            // This catalog item is just meant to load the bundle in the OSGi environment. Its content is irrelevant.
+            String libraryItem = Joiner.on("\n").join(
+                    "brooklyn.catalog:",
+                    "  id: dummy",
+                    "  version: %s",
+                    "  itemType: entity",
+                    "  libraries:",
+                    "  - url: " + OSGI_BUNDLE_URL,
+                    "  item: " + BasicEntity.class.getName());
+            addCatalogItems(String.format(libraryItem, appVersion));
+
+            // Use bundle prefixes here, pointing to the bundle already loaded above
+            appCatalogFormat = Joiner.on("\n").join(
+                    "brooklyn.catalog:",
+                    "  id: " + appSymbolicName,
+                    "  version: %s",
+                    "  itemType: entity",
+                    "  item:",
+                    "    type: " + OSGI_BUNDLE_SYMBOLID_NAME_FULL + ":" + OSGI_SIMPLE_ENTITY_TYPE,
+                    "    brooklyn.enrichers:",
+                    "    - type: " + TestEnricher.class.getName(),
+                    "    brooklyn.policies:",
+                    "    - type: " + OSGI_BUNDLE_SYMBOLID_NAME_FULL + ":" + OSGI_SIMPLE_POLICY_TYPE,
+                    "    brooklyn.initializers:",
+                    "    - type: " + OSGI_BUNDLE_SYMBOLID_NAME_FULL + ":" + OSGI_SIMPLE_EFFECTOR_TYPE);
         } else {
             appCatalogFormat = Joiner.on("\n").join(
                     "brooklyn.catalog:",

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cd9447a3/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiStandaloneTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiStandaloneTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiStandaloneTest.java
index b399d60..96830bf 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiStandaloneTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/osgi/OsgiStandaloneTest.java
@@ -49,6 +49,7 @@ public class OsgiStandaloneTest extends OsgiTestBase {
     public static final String BROOKLYN_OSGI_TEST_A_0_1_0_URL = "classpath:"+BROOKLYN_OSGI_TEST_A_0_1_0_PATH;
 
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_PATH = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH;
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FULL = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FULL;
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_URL = "classpath:"+BROOKLYN_TEST_OSGI_ENTITIES_PATH;
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_NAME = "org.apache.brooklyn.test.resources.osgi.brooklyn-test-osgi-entities";
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_VERSION = "0.1.0";

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cd9447a3/utils/common/dependencies/osgi/entities/src/main/java/org/apache/brooklyn/test/osgi/entities/SimpleEffectorInitializer.java
----------------------------------------------------------------------
diff --git a/utils/common/dependencies/osgi/entities/src/main/java/org/apache/brooklyn/test/osgi/entities/SimpleEffectorInitializer.java b/utils/common/dependencies/osgi/entities/src/main/java/org/apache/brooklyn/test/osgi/entities/SimpleEffectorInitializer.java
new file mode 100644
index 0000000..bbe23c1
--- /dev/null
+++ b/utils/common/dependencies/osgi/entities/src/main/java/org/apache/brooklyn/test/osgi/entities/SimpleEffectorInitializer.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.brooklyn.test.osgi.entities;
+
+import org.apache.brooklyn.core.effector.AddEffector;
+import org.apache.brooklyn.core.effector.EffectorBody;
+import org.apache.brooklyn.core.effector.Effectors;
+import org.apache.brooklyn.util.core.config.ConfigBag;
+
+public class SimpleEffectorInitializer extends AddEffector {
+
+    public SimpleEffectorInitializer() {
+        super(newEffectorBuilder().build());
+    }
+
+    public static Effectors.EffectorBuilder<Void> newEffectorBuilder() {
+        ConfigBag bag = ConfigBag.newInstance();
+        bag.put(EFFECTOR_NAME, SimpleEffectorInitializer.class.getSimpleName());
+
+        return AddEffector.newEffectorBuilder(Void.class, bag)
+                .description("A bare-bones effector")
+                .impl(new Body());
+    }
+
+
+    public static class Body extends EffectorBody<Void> {
+
+        @Override
+        public Void call(ConfigBag parameters) {
+            return null;
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cd9447a3/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java
index 181849d..574316d 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java
@@ -40,10 +40,14 @@ public class OsgiTestResources {
      * brooklyn-test-osgi-entities (v 0.1.0) -
      * defines an entity and an application, to confirm it can be read and used by brooklyn
      */
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FINAL_PART = "brooklyn-test-osgi-entities";
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FULL =
+        "org.apache.brooklyn.test.resources.osgi."+BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FINAL_PART;
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_PATH = "/brooklyn/osgi/brooklyn-test-osgi-entities.jar";
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_APPLICATION = "org.apache.brooklyn.test.osgi.entities.SimpleApplication";
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY = "org.apache.brooklyn.test.osgi.entities.SimpleEntity";
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_POLICY = "org.apache.brooklyn.test.osgi.entities.SimplePolicy";
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_EFFECTOR = "org.apache.brooklyn.test.osgi.entities.SimpleEffectorInitializer";
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_OBJECT = "org.apache.brooklyn.test.osgi.entities.SimpleObject";
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY_CONFIG_NAME = "simple.config";
     public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY_SENSOR_NAME = "simple.sensor";

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cd9447a3/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
----------------------------------------------------------------------
diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
index 42ba7ca..51d57bb 100644
Binary files a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar differ