Repository: brooklyn-server
Updated Branches:
  refs/heads/master 636851100 -> e1c310f5f


code tidy: SoftwareProcess tests


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

Branch: refs/heads/master
Commit: 9d32882badebe9fe5f3002c33a91d088c7161c91
Parents: 6368511
Author: Aled Sage <aled.s...@gmail.com>
Authored: Wed Aug 3 14:26:06 2016 +0100
Committer: Aled Sage <aled.s...@gmail.com>
Committed: Wed Aug 3 16:08:28 2016 +0100

----------------------------------------------------------------------
 .../org/apache/brooklyn/core/feed/Poller.java   |  2 +-
 .../core/mgmt/rebind/RebindTestFixture.java     |  8 +++
 .../core/mgmt/rebind/RebindTestUtils.java       | 10 +++
 .../base/SoftwareProcessEntityRebindTest.java   | 68 ++++++--------------
 4 files changed, 39 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9d32882b/core/src/main/java/org/apache/brooklyn/core/feed/Poller.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/feed/Poller.java 
b/core/src/main/java/org/apache/brooklyn/core/feed/Poller.java
index a9a34d9..eed8f63 100644
--- a/core/src/main/java/org/apache/brooklyn/core/feed/Poller.java
+++ b/core/src/main/java/org/apache/brooklyn/core/feed/Poller.java
@@ -148,7 +148,7 @@ public class Poller<V> {
                         DynamicSequentialTask<Void> task = new 
DynamicSequentialTask<Void>(MutableMap.of("displayName", scheduleName, 
"entity", entity), 
                             new Callable<Void>() { public Void call() {
                                 if (onlyIfServiceUp && 
!Boolean.TRUE.equals(entity.getAttribute(Attributes.SERVICE_UP))) {
-                                        return null;
+                                    return null;
                                 }
                                 pollJob.wrappedJob.run();
                                 return null; 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9d32882b/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 4744708..819b8f0 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
@@ -45,6 +45,7 @@ import 
org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import 
org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore;
 import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
 import org.apache.brooklyn.core.mgmt.persist.PersistMode;
+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.util.core.task.BasicExecutionManager;
 import org.apache.brooklyn.util.os.Os;
 import org.apache.brooklyn.util.repeat.Repeater;
@@ -97,15 +98,22 @@ public abstract class RebindTestFixture<T extends 
StartableApplication> {
 
     /** @return A started management context */
     protected LocalManagementContext createOrigManagementContext() {
+        LocalManagementContextForTests.newInstance();
+
         return RebindTestUtils.managementContextBuilder(mementoDir, 
classLoader)
                 .persistPeriodMillis(getPersistPeriodMillis())
                 .forLive(useLiveManagementContext())
+                .enablePersistenceBackups(enablePersistenceBackups())
                 .emptyCatalog(useEmptyCatalog())
                 .properties(createBrooklynProperties())
                 .enableOsgi(useOsgi())
                 .buildStarted();
     }
 
+    protected boolean enablePersistenceBackups() {
+        return true;
+    }
+    
     /** As {@link #createNewManagementContext(File)} using the default memento 
dir */
     protected LocalManagementContext createNewManagementContext() {
         return createNewManagementContext(mementoDir);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9d32882b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
index 24c8024..ad2bdf8 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
@@ -153,6 +153,7 @@ public class RebindTestUtils {
         boolean forLive;
         boolean enableOsgi = false;
         boolean emptyCatalog;
+        private boolean enablePersistenceBackups = true;
         
         ManagementContextBuilder(File mementoDir, ClassLoader classLoader) {
             this(classLoader, new FileBasedObjectStore(mementoDir));
@@ -185,6 +186,10 @@ public class RebindTestUtils {
             return this;
         }
 
+        public ManagementContextBuilder enablePersistenceBackups(boolean val) {
+            this.enablePersistenceBackups  = val;
+            return this;
+        }
         public ManagementContextBuilder enableOsgi(boolean val) {
             this.enableOsgi = val;
             return this;
@@ -208,6 +213,11 @@ public class RebindTestUtils {
             if (this.emptyCatalog) {
                 
properties.putIfAbsent(BrooklynServerConfig.BROOKLYN_CATALOG_URL, 
ManagementContextInternal.EMPTY_CATALOG_URL);
             }
+            if (!enablePersistenceBackups) {
+                
properties.putIfAbsent(BrooklynServerConfig.PERSISTENCE_BACKUPS_REQUIRED_ON_DEMOTION,
 false);
+                
properties.putIfAbsent(BrooklynServerConfig.PERSISTENCE_BACKUPS_REQUIRED_ON_PROMOTION,
 false);
+                
properties.putIfAbsent(BrooklynServerConfig.PERSISTENCE_BACKUPS_REQUIRED, 
false);
+            }
             if (forLive) {
                 unstarted = new LocalManagementContext(properties);
             } else {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9d32882b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityRebindTest.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityRebindTest.java
 
b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityRebindTest.java
index 3592e3c..8c568c3 100644
--- 
a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityRebindTest.java
+++ 
b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityRebindTest.java
@@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
-import java.io.File;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
@@ -33,60 +32,38 @@ import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.location.MachineProvisioningLocation;
 import org.apache.brooklyn.api.location.NoMachinesAvailableException;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.entity.Attributes;
-import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
 import 
org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceProblemsLogic;
 import org.apache.brooklyn.core.location.AbstractLocation;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
-import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import 
org.apache.brooklyn.entity.software.base.SoftwareProcessEntityTest.MyService;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
-import org.apache.brooklyn.location.ssh.SshMachineLocation;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
-import com.google.common.io.Files;
 
-public class SoftwareProcessEntityRebindTest extends 
BrooklynAppUnitTestSupport {
+public class SoftwareProcessEntityRebindTest extends RebindTestFixtureWithApp {
 
-    private ClassLoader classLoader = getClass().getClassLoader();
-    private TestApplication newApp;
-    private ManagementContext newManagementContext;
-    private MyService origE;
-    private File mementoDir;
-    
-    @BeforeMethod(alwaysRun=true)
     @Override
-    public void setUp() throws Exception {
-        mementoDir = Files.createTempDir();
-        mgmt = RebindTestUtils.newPersistingManagementContext(mementoDir, 
classLoader);
-        super.setUp();
+    protected boolean enablePersistenceBackups() {
+        return false;
     }
 
-    @AfterMethod(alwaysRun=true)
-    @Override
-    public void tearDown() throws Exception {
-        super.tearDown();
-        if (newApp != null) Entities.destroyAll(newApp.getManagementContext());
-        if (newManagementContext != null) 
Entities.destroyAll(newManagementContext);
-        if (mementoDir != null) RebindTestUtils.deleteMementoDir(mementoDir);
-    }
-    
     @Test
     public void testReleasesLocationOnStopAfterRebinding() throws Exception {
-        origE = app.createAndManageChild(EntitySpec.create(MyService.class));
+        MyService origE = 
origApp.createAndManageChild(EntitySpec.create(MyService.class)
+                .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, 
true));
         
-        MyProvisioningLocation origLoc = 
mgmt.getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
+        MyProvisioningLocation origLoc = 
mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
                 .displayName("mylocname"));
-        app.start(ImmutableList.of(origLoc));
+        origApp.start(ImmutableList.of(origLoc));
         assertEquals(origLoc.inUseCount.get(), 1);
         
         newApp = (TestApplication) rebind();
@@ -99,13 +76,14 @@ public class SoftwareProcessEntityRebindTest extends 
BrooklynAppUnitTestSupport
 
     @Test
     public void testCreatesDriverAfterRebind() throws Exception {
-        origE = app.createAndManageChild(EntitySpec.create(MyService.class));
-        //the entity skips enricher initialization, do it explicitly
+        MyService origE = 
origApp.createAndManageChild(EntitySpec.create(MyService.class)
+                .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, 
true));
+                //the entity skips enricher initialization, do it explicitly
         
origE.enrichers().add(ServiceStateLogic.newEnricherForServiceStateFromProblemsAndUp());
 
-        MyProvisioningLocation origLoc = 
mgmt.getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
+        MyProvisioningLocation origLoc = 
mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
                 .displayName("mylocname"));
-        app.start(ImmutableList.of(origLoc));
+        origApp.start(ImmutableList.of(origLoc));
         
assertEquals(origE.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), 
Lifecycle.RUNNING);
         EntityAsserts.assertAttributeEqualsEventually(origE, 
Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
 
@@ -119,13 +97,14 @@ public class SoftwareProcessEntityRebindTest extends 
BrooklynAppUnitTestSupport
 
     @Test
     public void testDoesNotCreateDriverAfterRebind() throws Exception {
-        origE = app.createAndManageChild(EntitySpec.create(MyService.class));
-        //the entity skips enricher initialization, do it explicitly
+        MyService origE = 
origApp.createAndManageChild(EntitySpec.create(MyService.class)
+                .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, 
true));
+                //the entity skips enricher initialization, do it explicitly
         
origE.enrichers().add(ServiceStateLogic.newEnricherForServiceStateFromProblemsAndUp());
         
-        MyProvisioningLocation origLoc = 
mgmt.getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
+        MyProvisioningLocation origLoc = 
mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
                 .displayName("mylocname"));
-        app.start(ImmutableList.of(origLoc));
+        origApp.start(ImmutableList.of(origLoc));
         
assertEquals(origE.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), 
Lifecycle.RUNNING);
         EntityAsserts.assertAttributeEqualsEventually(origE, 
Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
 
@@ -136,13 +115,6 @@ public class SoftwareProcessEntityRebindTest extends 
BrooklynAppUnitTestSupport
         MyService newE = (MyService) 
Iterables.getOnlyElement(newApp.getChildren());
         assertNull(newE.getDriver(), "driver should not be initialized because 
entity is in a permanent failure");
     }
-
-    private TestApplication rebind() throws Exception {
-        RebindTestUtils.waitForPersisted(app);
-        TestApplication result = (TestApplication) 
RebindTestUtils.rebind(mementoDir, getClass().getClassLoader());
-        newManagementContext = result.getManagementContext();
-        return result;
-    }
     
     public static class MyProvisioningLocation extends AbstractLocation 
implements MachineProvisioningLocation<SshMachineLocation> {
         @SetFromFlag(defaultVal="0")

Reply via email to