brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [22/25] git commit: persistence: expunge policies/enrichers on entity unmanaged
Date Sun, 01 Jun 2014 20:15:37 GMT
persistence: expunge policies/enrichers on entity unmanaged


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

Branch: refs/heads/master
Commit: 6c880a403a5b6db037027625b1ef7662526d1d36
Parents: b425cab
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu May 29 17:38:55 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Fri May 30 10:24:40 2014 +0100

----------------------------------------------------------------------
 .../rebind/PeriodicDeltaChangeListener.java     |  9 +++++++
 .../entity/rebind/RebindPolicyTest.java         | 28 ++++++++++++++++++++
 .../entity/rebind/RebindTestFixture.java        | 11 ++++++++
 3 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6c880a40/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java b/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
index 7e4d5f4..6715014 100644
--- a/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
+++ b/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
@@ -302,6 +302,15 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
         if (!isStopped()) {
             deltaCollector.removedEntityIds.add(entity.getId());
             deltaCollector.entities.remove(entity);
+            
+            for (Policy policy : entity.getPolicies()) {
+                deltaCollector.removedPolicyIds.add(policy.getId());
+                deltaCollector.policies.remove(policy);
+            }
+            for (Enricher enricher : entity.getEnrichers()) {
+                deltaCollector.removedEnricherIds.add(enricher.getId());
+                deltaCollector.enrichers.remove(enricher);
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6c880a40/core/src/test/java/brooklyn/entity/rebind/RebindPolicyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindPolicyTest.java b/core/src/test/java/brooklyn/entity/rebind/RebindPolicyTest.java
index 877437f..c86a9d8 100644
--- a/core/src/test/java/brooklyn/entity/rebind/RebindPolicyTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/RebindPolicyTest.java
@@ -10,9 +10,17 @@ import org.testng.annotations.Test;
 
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.basic.ConfigKeys;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.rebind.RebindEnricherTest.MyEnricher;
+import brooklyn.location.Location;
+import brooklyn.location.basic.Locations;
+import brooklyn.mementos.BrooklynMementoManifest;
+import brooklyn.policy.EnricherSpec;
 import brooklyn.policy.PolicySpec;
 import brooklyn.policy.basic.AbstractPolicy;
 import brooklyn.test.entity.TestApplication;
+import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.flags.SetFromFlag;
 
@@ -83,6 +91,26 @@ public class RebindPolicyTest extends RebindTestFixtureWithApp {
         assertEquals(newPolicy.getConfig(MyPolicy.MY_CONFIG_WITHOUT_SETFROMFLAG), "myVal
for witout setFromFlag");
     }
 
+    @Test
+    public void testExpungesOnEntityUnmanaged() throws Exception {
+        Location loc = origManagementContext.getLocationRegistry().resolve("localhost");
+        TestEntity entity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class));
+        MyPolicy policy = entity.addPolicy(PolicySpec.create(MyPolicy.class));
+        MyEnricher enricher = entity.addEnricher(EnricherSpec.create(MyEnricher.class));
+
+        RebindTestUtils.waitForPersisted(origApp);
+
+        Entities.unmanage(entity);
+        Locations.unmanage(loc);
+        RebindTestUtils.waitForPersisted(origApp);
+        
+        BrooklynMementoManifest manifest = loadMementoManifest();
+        assertFalse(manifest.getEntityIdToType().containsKey(entity.getId()));
+        assertFalse(manifest.getPolicyIdToType().containsKey(policy.getId()));
+        assertFalse(manifest.getEnricherIdToType().containsKey(enricher.getId()));
+        assertFalse(manifest.getLocationIdToType().containsKey(loc.getId()));
+    }
+
     public static class MyPolicy extends AbstractPolicy {
         public static final ConfigKey<String> MY_CONFIG = ConfigKeys.newStringConfigKey("myconfigkey");
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6c880a40/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java b/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
index fe61ffe..9099418 100644
--- a/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
+++ b/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
@@ -7,9 +7,12 @@ import org.testng.annotations.BeforeMethod;
 
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.StartableApplication;
+import brooklyn.entity.rebind.RebindExceptionHandlerImpl.RebindFailureMode;
+import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToMultiFile;
 import brooklyn.internal.BrooklynFeatureEnablement;
 import brooklyn.management.ManagementContext;
 import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.mementos.BrooklynMementoManifest;
 import brooklyn.util.time.Duration;
 
 import com.google.common.io.Files;
@@ -96,4 +99,12 @@ public abstract class RebindTestFixture<T extends StartableApplication>
{
         RebindTestUtils.waitForPersisted(origApp);
         return (T) RebindTestUtils.rebind(newManagementContext, mementoDir, getClass().getClassLoader(),
exceptionHandler);
     }
+    
+    protected BrooklynMementoManifest loadMementoManifest() throws Exception {
+        BrooklynMementoPersisterToMultiFile persister = new BrooklynMementoPersisterToMultiFile(mementoDir,
classLoader);
+        RebindExceptionHandler exceptionHandler = new RecordingRebindExceptionHandler(RebindFailureMode.FAIL_AT_END,
RebindFailureMode.FAIL_AT_END);
+        BrooklynMementoManifest mementoManifest = persister.loadMementoManifest(exceptionHandler);
+        persister.stop();
+        return mementoManifest;
+    }
 }


Mime
View raw message