You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by aledsage <gi...@git.apache.org> on 2016/07/06 15:07:19 UTC

[GitHub] brooklyn-server pull request #236: Adds OSGi classloading/rebind tests

GitHub user aledsage opened a pull request:

    https://github.com/apache/brooklyn-server/pull/236

    Adds OSGi classloading/rebind tests

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/aledsage/brooklyn-server tests/osgi-classloading

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/236.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #236
    
----
commit c68bfd5ac500f5e9f24fa87bf73edacb19e80490
Author: Aled Sage <al...@gmail.com>
Date:   2016-07-06T15:06:24Z

    Adds OSGi classloading/rebind tests

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #236: Adds OSGi classloading/rebind tests

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/236#discussion_r69895917
  
    --- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java ---
    @@ -85,63 +95,97 @@
             REPLACE_CATALOG_WITH_NEWER_VERSION;
         }
         
    -    @Test
    -    public void testRebindWithCatalogAndApp() throws Exception {
    -        runRebindWithCatalogAndApp(RebindWithCatalogTestMode.NO_OP);
    -    }
    +    private Boolean defaultEnablementOfFeatureAutoFixatalogRefOnRebind;
         
    -    @Test
    -    public void testRebindWithCatalogDeprecatedAndAppExisting() throws Exception {
    -        runRebindWithCatalogAndApp(RebindWithCatalogTestMode.DEPRECATE_CATALOG);
    +    @BeforeMethod(alwaysRun=true)
    +    @Override
    +    public void setUp() throws Exception {
    +        defaultEnablementOfFeatureAutoFixatalogRefOnRebind = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND);
    +        super.setUp();
         }
         
    -    @Test
    -    public void testRebindWithCatalogDisabledAndAppExisting() throws Exception {
    -        runRebindWithCatalogAndApp(RebindWithCatalogTestMode.DISABLE_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.
    -    @Test
    -    public void testRebindWithCatalogDeletedAndAppExisting() throws Exception {
    -        runRebindWithCatalogAndApp(RebindWithCatalogTestMode.DELETE_CATALOG);
    +    @AfterMethod(alwaysRun=true)
    +    @Override
    +    public void tearDown() throws Exception {
    +        if (defaultEnablementOfFeatureAutoFixatalogRefOnRebind != null) {
    +            BrooklynFeatureEnablement.setEnablement(BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND, defaultEnablementOfFeatureAutoFixatalogRefOnRebind);
    +        }
    +        super.tearDown();
         }
         
    -    // Upgrades the catalog item before rebind, deleting the old version.
    -    // Will automatically upgrade.
    -    @Test
    -    public void testRebindWithCatalogUpgradedWithOldDeletedAndAppExisting() throws Exception {
    -        BrooklynFeatureEnablement.enable(BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND);
    -        runRebindWithCatalogAndApp(RebindWithCatalogTestMode.REPLACE_CATALOG_WITH_NEWER_VERSION);
    +    protected boolean useOsgi() {
    +        return true;
         }
    -    
    -    /**
    -     * Old persisted state for catalog items may not have a "deprecated" or "disabled"
    -     * value. Need to check that their absence will default to false.
    -     */
    -    @Test
    -    public void testRebindWithCatalogPropertiesForDeprecationAndEnablementAbsent() throws Exception {
    -        runRebindWithCatalogAndApp(RebindWithCatalogTestMode.STRIP_DEPRECATION_AND_ENABLEMENT_FROM_CATALOG_ITEM);
    +
    +    @DataProvider
    +    public Object[][] dataProvider() {
    +        return new Object[][] {
    +            {RebindWithCatalogTestMode.NO_OP, false},
    +            {RebindWithCatalogTestMode.NO_OP, true},
    +            
    +            {RebindWithCatalogTestMode.STRIP_DEPRECATION_AND_ENABLEMENT_FROM_CATALOG_ITEM, false},
    +            {RebindWithCatalogTestMode.STRIP_DEPRECATION_AND_ENABLEMENT_FROM_CATALOG_ITEM, true},
    +            
    +            {RebindWithCatalogTestMode.DEPRECATE_CATALOG, false},
    +            {RebindWithCatalogTestMode.DEPRECATE_CATALOG, true},
    +            
    +            {RebindWithCatalogTestMode.DISABLE_CATALOG, false},
    +            {RebindWithCatalogTestMode.DISABLE_CATALOG, true},
    +            
    +            // 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},
    +            
    +            // 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},
    +        };
         }
     
    -    @SuppressWarnings({ "unused", "deprecation" })
    -    protected void runRebindWithCatalogAndApp(RebindWithCatalogTestMode mode) throws Exception {
    +    @Test(dataProvider = "dataProvider")
    +    @SuppressWarnings("deprecation")
    +    public void testRebindWithCatalogAndApp(RebindWithCatalogTestMode mode, boolean useOsgi) throws Exception {
    +        if (mode == RebindWithCatalogTestMode.REPLACE_CATALOG_WITH_NEWER_VERSION) {
    +            BrooklynFeatureEnablement.enable(BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND);
    +        }
    +
             String appSymbolicName = "my.catalog.app.id.load";
             String appVersion = "0.1.0";
    -        String appCatalogFormat = Joiner.on("\n").join(
    -                "brooklyn.catalog:",
    -                "  id: " + appSymbolicName,
    -                "  version: %s",
    -                "  itemType: entity",
    -                "  item:",
    -                "    type: "+ BasicEntity.class.getName(),
    -                "    brooklyn.enrichers:",
    -                "    - type: "+TestEnricher.class.getName(),
    -                "    brooklyn.policies:",
    -                "    - type: "+TestPolicy.class.getName());
             
    +        String appCatalogFormat;
    +        if (useOsgi) {
    --- End diff --
    
    Add a `TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OSGI_BUNDLE_URL);` for this case



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #236: Adds OSGi classloading/rebind tests

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/236


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #236: Adds OSGi classloading/rebind tests

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/236#discussion_r69895207
  
    --- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java ---
    @@ -85,63 +95,97 @@
             REPLACE_CATALOG_WITH_NEWER_VERSION;
         }
         
    -    @Test
    -    public void testRebindWithCatalogAndApp() throws Exception {
    -        runRebindWithCatalogAndApp(RebindWithCatalogTestMode.NO_OP);
    -    }
    +    private Boolean defaultEnablementOfFeatureAutoFixatalogRefOnRebind;
    --- End diff --
    
    Missing C in `defaultEnablementOfFeatureAutoFix(C)atalogRefOnRebind`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #236: Adds OSGi classloading/rebind tests

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/236#discussion_r69896431
  
    --- Diff: core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java ---
    @@ -0,0 +1,158 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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.util.core;
    +
    +import static org.testng.Assert.assertEquals;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.mgmt.ManagementContext;
    +import org.apache.brooklyn.core.entity.Entities;
    +import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
    +import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
    +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
    +import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
    +import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.core.osgi.Osgis;
    +import org.apache.brooklyn.util.guava.Maybe;
    +import org.apache.brooklyn.util.osgi.OsgiTestResources;
    +import org.dom4j.tree.AbstractEntity;
    +import org.osgi.framework.Bundle;
    +import org.osgi.framework.launch.Framework;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +public class ClassLoaderUtilsTest {
    +
    +    private LocalManagementContext mgmt;
    +    
    +    private String origWhiteListKey;
    +    
    +    @BeforeMethod(alwaysRun=true)
    +    public void setUp() throws Exception {
    +        origWhiteListKey = System.getProperty(ClassLoaderUtils.WHITE_LIST_KEY);
    +    }
    +    
    +    @AfterMethod(alwaysRun=true)
    +    public void tearDown() throws Exception {
    +        if (origWhiteListKey != null) {
    +            System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, origWhiteListKey);
    +        } else {
    +            System.clearProperty(ClassLoaderUtils.WHITE_LIST_KEY);
    +        }
    +        if (mgmt != null) {
    +            Entities.destroyAll(mgmt);
    +        }
    +    }
    +    
    +    @Test
    +    public void testLoadClassNotInOsgi() throws Exception {
    +        ClassLoaderUtils clu = new ClassLoaderUtils(getClass());
    +        assertEquals(clu.loadClass(getClass().getName()), getClass());
    +        assertEquals(clu.loadClass(Entity.class.getName()), Entity.class);
    +        assertEquals(clu.loadClass(AbstractEntity.class.getName()), AbstractEntity.class);
    +        assertLoadFails(clu, "org.apache.brooklyn.this.name.does.not.Exist");
    +    }
    +    
    +    @Test
    +    public void testLoadClassInOsgi() throws Exception {
    +        String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
    +        String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY;
    +        
    +        mgmt = LocalManagementContextForTests.builder(true).disableOsgi(false).build();
    +        Bundle bundle = installBundle(mgmt, bundleUrl);
    +        
    +        ClassLoaderUtils clu = new ClassLoaderUtils(getClass(), mgmt);
    +        
    +        assertLoadFails(clu, classname);
    --- End diff --
    
    Shouldn't this succeed through the white list fallback?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #236: Adds OSGi classloading/rebind tests

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:

    https://github.com/apache/brooklyn-server/pull/236
  
    Merging, comments can be addressed in a subsequent PR.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #236: Adds OSGi classloading/rebind tests

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/236#discussion_r69895990
  
    --- Diff: core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java ---
    @@ -0,0 +1,158 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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.util.core;
    +
    +import static org.testng.Assert.assertEquals;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.mgmt.ManagementContext;
    +import org.apache.brooklyn.core.entity.Entities;
    +import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
    +import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
    +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
    +import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
    +import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.core.osgi.Osgis;
    +import org.apache.brooklyn.util.guava.Maybe;
    +import org.apache.brooklyn.util.osgi.OsgiTestResources;
    +import org.dom4j.tree.AbstractEntity;
    +import org.osgi.framework.Bundle;
    +import org.osgi.framework.launch.Framework;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +public class ClassLoaderUtilsTest {
    +
    +    private LocalManagementContext mgmt;
    +    
    +    private String origWhiteListKey;
    +    
    +    @BeforeMethod(alwaysRun=true)
    +    public void setUp() throws Exception {
    +        origWhiteListKey = System.getProperty(ClassLoaderUtils.WHITE_LIST_KEY);
    +    }
    +    
    +    @AfterMethod(alwaysRun=true)
    +    public void tearDown() throws Exception {
    +        if (origWhiteListKey != null) {
    +            System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, origWhiteListKey);
    +        } else {
    +            System.clearProperty(ClassLoaderUtils.WHITE_LIST_KEY);
    +        }
    +        if (mgmt != null) {
    +            Entities.destroyAll(mgmt);
    +        }
    +    }
    +    
    +    @Test
    +    public void testLoadClassNotInOsgi() throws Exception {
    +        ClassLoaderUtils clu = new ClassLoaderUtils(getClass());
    +        assertEquals(clu.loadClass(getClass().getName()), getClass());
    +        assertEquals(clu.loadClass(Entity.class.getName()), Entity.class);
    +        assertEquals(clu.loadClass(AbstractEntity.class.getName()), AbstractEntity.class);
    +        assertLoadFails(clu, "org.apache.brooklyn.this.name.does.not.Exist");
    +    }
    +    
    +    @Test
    +    public void testLoadClassInOsgi() throws Exception {
    +        String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
    --- End diff --
    
    Same here and following tests.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---