brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/3] brooklyn-server git commit: Create a new management context for rebind test
Date Fri, 04 Nov 2016 16:41:43 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 01140cd23 -> 59cbcc593


Create a new management context for rebind test

The tests in RebindManagerExceptionHandlerTest were reusing the same management context on
rebind - create a new management context instead to make sure we are rebinding against the
on-disk persisted state.


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

Branch: refs/heads/master
Commit: adb0173a73a36e9186b972de26e0ba03ad78e6a5
Parents: c4cc0d1
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Thu Nov 3 09:48:13 2016 +0200
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Thu Nov 3 09:48:13 2016 +0200

----------------------------------------------------------------------
 .../AbstractJcloudsRebindStubYamlTest.java      |  5 +-
 .../brooklyn/camp/brooklyn/RebindOsgiTest.java  |  5 +-
 .../core/mgmt/rebind/RebindCatalogItemTest.java |  3 +-
 ...talogWhenCatalogPersistenceDisabledTest.java | 22 ++------
 .../RebindManagerExceptionHandlerTest.java      | 55 ++++----------------
 .../core/mgmt/rebind/RebindOptions.java         |  8 ++-
 .../core/mgmt/rebind/RebindTestFixture.java     | 23 ++++----
 ...ClockerDynamicLocationPatternRebindTest.java |  4 +-
 8 files changed, 46 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/adb0173a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsRebindStubYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsRebindStubYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsRebindStubYamlTest.java
index d12b885..f273db7 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsRebindStubYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsRebindStubYamlTest.java
@@ -19,6 +19,7 @@
 package org.apache.brooklyn.camp.brooklyn;
 
 import java.io.File;
+import java.util.Map;
 
 import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.camp.brooklyn.AbstractJcloudsStubYamlTest.ByonComputeServiceStaticRef;
@@ -91,11 +92,11 @@ public abstract class AbstractJcloudsRebindStubYamlTest extends JcloudsRebindStu
     }
 
     @Override
-    protected LocalManagementContext createNewManagementContext(final File mementoDir, final
HighAvailabilityMode haMode) {
+    protected LocalManagementContext createNewManagementContext(final File mementoDir, final
HighAvailabilityMode haMode, final Map<?, ?> additionalProperties) {
         newLauncher = new BrooklynCampPlatformLauncherNoServer() {
             @Override
             protected LocalManagementContext newMgmtContext() {
-                return AbstractJcloudsRebindStubYamlTest.super.createNewManagementContext(mementoDir,
haMode);
+                return AbstractJcloudsRebindStubYamlTest.super.createNewManagementContext(mementoDir,
haMode, additionalProperties);
             }
         };
         newLauncher.launch();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/adb0173a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java
index 5d7bd0f..fe071a5 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java
@@ -25,6 +25,7 @@ import static org.testng.Assert.assertNull;
 
 import java.io.File;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
@@ -91,8 +92,8 @@ public class RebindOsgiTest extends AbstractYamlRebindTest {
     }
     
     @Override
-    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode
haMode) {
-        LocalManagementContext result = super.createNewManagementContext(mementoDir, haMode);
+    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode
haMode, Map<?, ?> additionalProperties) {
+        LocalManagementContext result = super.createNewManagementContext(mementoDir, haMode,
additionalProperties);
         for (String bundleUrl : bundleUrlsToInstallOnRebind) {
             try {
                 installBundle(result, bundleUrl);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/adb0173a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
index 624e733..6fbffdd 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
@@ -24,6 +24,7 @@ import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
 import java.io.File;
+import java.util.Map;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
@@ -93,7 +94,7 @@ public class RebindCatalogItemTest extends RebindTestFixtureWithApp {
     }
 
     @Override
-    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode
haMode) {
+    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode
haMode, Map<?, ?> additionalProperties) {
         BrooklynProperties properties = BrooklynProperties.Factory.newDefault();
         properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, "classpath://brooklyn/entity/rebind/rebind-catalog-item-test-catalog.xml");
         return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/adb0173a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java
index 70d5a16..902770d 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java
@@ -21,6 +21,7 @@ package org.apache.brooklyn.core.mgmt.rebind;
 import static org.testng.Assert.assertEquals;
 
 import java.io.File;
+import java.util.Map;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.EntitySpec;
@@ -58,25 +59,10 @@ public class RebindCatalogWhenCatalogPersistenceDisabledTest extends RebindTestF
     }
 
     @Override
-    protected LocalManagementContext createOrigManagementContext() {
-        BrooklynProperties properties = BrooklynProperties.Factory.newDefault();
+    protected BrooklynProperties createBrooklynProperties() {
+        BrooklynProperties properties = super.createBrooklynProperties();
         properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, TEST_CATALOG);
-        return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
-                .properties(properties)
-                .persistPeriodMillis(getPersistPeriodMillis())
-                .forLive(useLiveManagementContext())
-                .buildStarted();
-    }
-
-    @Override
-    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode
haMode) {
-        BrooklynProperties properties = BrooklynProperties.Factory.newDefault();
-        properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, TEST_CATALOG);
-        return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
-                .properties(properties)
-                .forLive(useLiveManagementContext())
-                .haMode(haMode)
-                .buildUnstarted();
+        return properties;
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/adb0173a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerExceptionHandlerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerExceptionHandlerTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerExceptionHandlerTest.java
index 14b2a16..33583fa 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerExceptionHandlerTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerExceptionHandlerTest.java
@@ -19,12 +19,8 @@
 package org.apache.brooklyn.core.mgmt.rebind;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.internal.BrooklynProperties;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestApplicationNoEnrichersImpl;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.test.Asserts;
 import org.testng.annotations.Test;
@@ -33,19 +29,20 @@ import com.google.common.collect.ImmutableMap;
 
 public class RebindManagerExceptionHandlerTest extends RebindTestFixtureWithApp {
 
-    @Test
-    public void testAddConfigFailure() throws Throwable {
-        origApp.createAndManageChild(EntitySpec.create(TestEntity.class)
+    @Override
+    protected TestApplication createApp() {
+        TestApplication app = super.createApp();
+        app.createAndManageChild(EntitySpec.create(TestEntity.class)
                 .configure(TestEntity.CONF_MAP_THING.getName(), 
+                     // misconfigured map value, should be a string key, but forced (by using
a flag) so failure won't be enforced until persist/rebind
                     ImmutableMap.of("keyWithMapValue", ImmutableMap.of("minRam", 4))));
-        // above misconfigured, should be a string key, but forced above so failure won't
be enforced until persist/rebind
+        return app;
+    }
 
+    @Test
+    public void testAddConfigFailure() throws Throwable {
         try {
-            RebindTestUtils.waitForPersisted(origApp);
-            RebindOptions rebindOptions = RebindOptions.create();
-            // Use the original context with empty properties so the test doesn't depend
on the local properties file
-            rebindOptions.newManagementContext = origManagementContext;
-            rebind(rebindOptions);
+            rebind();
             Asserts.shouldHaveFailedPreviously();
         } catch (Throwable e) {
             Asserts.expectedFailureContainsIgnoreCase(e, "minRam=4", "keyWithMapValue");
@@ -54,39 +51,9 @@ public class RebindManagerExceptionHandlerTest extends RebindTestFixtureWithApp
 
     @Test
     public void testAddConfigContinue() throws Throwable {
-        ManagementContext m = createManagementContextWithAddConfigContinue();
-        // configured above to continue on error
-        
-        origApp = m.getEntityManager().createEntity(EntitySpec.create(TestApplication.class,
TestApplicationNoEnrichersImpl.class));
-        origApp.createAndManageChild(EntitySpec.create(TestEntity.class)
-                .configure(TestEntity.CONF_MAP_THING.getName(), 
-                    ImmutableMap.of("keyWithMapValue", ImmutableMap.of("minRam", 4))));
-
-        RebindTestUtils.waitForPersisted(origApp);
-        RebindOptions rebindOptions = RebindOptions.create();
-        rebindOptions.newManagementContext = m;
+        RebindOptions rebindOptions = RebindOptions.create().additionalProperties(ImmutableMap.of("rebind.failureMode.addConfig",
"continue"));
         TestApplication rebindedApp = rebind(rebindOptions);
         EntityAsserts.assertConfigEquals(rebindedApp, TestEntity.CONF_MAP_THING, null);
     }
 
-    private LocalManagementContext createManagementContextWithAddConfigContinue() {
-        BrooklynProperties bp = BrooklynProperties.Factory.newEmpty();
-        bp.putIfAbsent("rebind.failureMode.addConfig", "continue");
-        return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
-                .properties(bp)
-                .persistPeriodMillis(getPersistPeriodMillis())
-                .forLive(useLiveManagementContext())
-                .emptyCatalog(useEmptyCatalog())
-                .buildStarted();
-    }
-
-    @Override
-    protected LocalManagementContext createOrigManagementContext() {
-        return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
-                .properties(BrooklynProperties.Factory.newEmpty())
-                .persistPeriodMillis(getPersistPeriodMillis())
-                .forLive(useLiveManagementContext())
-                .emptyCatalog(useEmptyCatalog())
-                .buildStarted();
-    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/adb0173a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
index eab61cf..e3c32db 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
@@ -20,6 +20,7 @@ package org.apache.brooklyn.core.mgmt.rebind;
 
 import java.io.File;
 import java.util.Collection;
+import java.util.Map;
 
 import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
@@ -46,6 +47,7 @@ public class RebindOptions {
     public PersistenceObjectStore objectStore;
     public HighAvailabilityMode haMode;
     public Function<Collection<Application>, Application> applicationChooserOnRebind;
+    public Map<?, ?> additionalProperties;
     
     public static RebindOptions create() {
         return new RebindOptions();
@@ -64,6 +66,7 @@ public class RebindOptions {
         result.objectStore(options.objectStore);
         result.haMode(options.haMode);
         result.applicationChooserOnRebind(options.applicationChooserOnRebind);
+        result.additionalProperties(options.additionalProperties);
         return result;
     }
     public RebindOptions checkSerializable(boolean val) {
@@ -110,9 +113,12 @@ public class RebindOptions {
         this.haMode = val;
         return this;
     }
-    
     public RebindOptions applicationChooserOnRebind(Function<Collection<Application>,
Application> val) {
         this.applicationChooserOnRebind = val;
         return this;
     }
+    public RebindOptions additionalProperties(Map<?, ?> additionalProperties) {
+        this.additionalProperties = additionalProperties;
+        return this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/adb0173a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
index 5ed62c1..7109b02 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
@@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals;
 
 import java.io.File;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Callable;
 
@@ -121,21 +122,25 @@ public abstract class RebindTestFixture<T extends StartableApplication>
{
     
     /** As {@link #createNewManagementContext(File)} using the default memento dir */
     protected LocalManagementContext createNewManagementContext() {
-        return createNewManagementContext(mementoDir);
+        return createNewManagementContext(mementoDir, null);
     }
     
     /** @return An unstarted management context using the specified mementoDir (or default
if null) */
-    protected LocalManagementContext createNewManagementContext(File mementoDir) {
-        return createNewManagementContext(mementoDir, getHaMode());
+    protected LocalManagementContext createNewManagementContext(File mementoDir, Map<?,
?> additionalProperties) {
+        return createNewManagementContext(mementoDir, getHaMode(), additionalProperties);
     }
-    
-    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode
haMode) {
+
+    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode
haMode, Map<?, ?> additionalProperties) {
         if (mementoDir==null) mementoDir = this.mementoDir;
+        BrooklynProperties brooklynProperties = createBrooklynProperties();
+        if (additionalProperties != null) {
+            brooklynProperties.addFrom(additionalProperties);
+        }
         return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
                 .forLive(useLiveManagementContext())
                 .haMode(haMode)
                 .emptyCatalog(useEmptyCatalog())
-                .properties(createBrooklynProperties())
+                .properties(brooklynProperties)
                 .enableOsgi(useOsgi())
                 .buildUnstarted();
     }
@@ -287,7 +292,7 @@ public abstract class RebindTestFixture<T extends StartableApplication>
{
         if (options.classLoader == null) options.classLoader(classLoader);
         if (options.mementoDir == null) options.mementoDir(mementoDir);
         if (options.origManagementContext == null) options.origManagementContext(origManagementContext);
-        if (options.newManagementContext == null) options.newManagementContext(createNewManagementContext(options.mementoDir));
+        if (options.newManagementContext == null) options.newManagementContext(createNewManagementContext(options.mementoDir,
options.additionalProperties));
         
         RebindTestUtils.waitForPersisted(origApp);
         
@@ -318,9 +323,9 @@ public abstract class RebindTestFixture<T extends StartableApplication>
{
         if (options.classLoader == null) options.classLoader(classLoader);
         if (options.mementoDir == null) options.mementoDir(mementoDir);
         if (options.origManagementContext == null) options.origManagementContext(origManagementContext);
-        if (options.newManagementContext == null) options.newManagementContext(createNewManagementContext(options.mementoDir,
options.haMode));
+        if (options.newManagementContext == null) options.newManagementContext(createNewManagementContext(options.mementoDir,
options.haMode, options.additionalProperties));
         
-        RebindTestUtils.waitForPersisted(origApp);
+        RebindTestUtils.stopPersistence(origApp);
         
         newManagementContext = options.newManagementContext;
         newApp = (T) RebindTestUtils.rebind(options);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/adb0173a/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java
b/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java
index 288bd5e..b190f0c 100644
--- a/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java
@@ -57,8 +57,8 @@ public class ClockerDynamicLocationPatternRebindTest extends RebindTestFixtureWi
     }
     
     @Override
-    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode
haMode) {
-        LocalManagementContext result = super.createNewManagementContext(mementoDir, haMode);
+    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode
haMode, Map<?, ?> additionalProperties) {
+        LocalManagementContext result = super.createNewManagementContext(mementoDir, haMode,
additionalProperties);
         StubResolver stubResolver = new StubResolver();
         ((BasicLocationRegistry)result.getLocationRegistry()).registerResolver(stubResolver);
         return result;


Mime
View raw message