You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2016/01/07 17:10:50 UTC

[4/8] incubator-brooklyn git commit: Test AWR value is not leaked in the persistent state

Test AWR value is not leaked in the persistent state

- set test-cluster sensor `sensor` e.g. to `foo` and then ensure that
  `foo` is not being written


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

Branch: refs/heads/master
Commit: 3746503c292c307ce28b56389fa508966503d1b4
Parents: 9d65a61
Author: Guglielmo Nigri <gu...@cloudsoftcorp.com>
Authored: Tue Dec 29 16:34:26 2015 +0100
Committer: Guglielmo Nigri <gu...@cloudsoftcorp.com>
Committed: Tue Dec 29 16:34:26 2015 +0100

----------------------------------------------------------------------
 .../camp/brooklyn/DslAndRebindYamlTest.java     | 61 ++++++++++++++++++++
 1 file changed, 61 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3746503c/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
index 522d609..0a9f778 100644
--- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
+++ b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
@@ -246,6 +246,67 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
     }
 
     @Test
+    public void testDslAttributeWhenReadyPersistedWithoutLeaks() throws Exception {
+        String yaml = "location: localhost\n" +
+                "name: Test Cluster\n" +
+                "services:\n" +
+                "- type: org.apache.brooklyn.entity.group.DynamicCluster\n" +
+                "  id: test-cluster\n" +
+                "  initialSize: 1\n" +
+                "  memberSpec:\n" +
+                "    $brooklyn:entitySpec:\n" +
+                "      type: org.apache.brooklyn.core.test.entity.TestEntity\n" +
+                "      brooklyn.config:\n" +
+                "        test.confName: $brooklyn:component(\"test-cluster\").attributeWhenReady(\"sensor\")";
+
+        final Entity testEntity = createAndStartApplication(yaml);
+
+        DynamicCluster clusterEntity1 = (DynamicCluster) Iterables.getOnlyElement(testEntity.getApplication().getChildren());
+
+        TestEntity testEntity1 = null;
+        for (Entity entity : clusterEntity1.getChildren()) {
+            if (entity instanceof TestEntity) {
+                testEntity1 = (TestEntity) entity;
+                break;
+            }
+        }
+        Assert.assertNotNull(testEntity1, "TestEntity not found in DynamicCluster");
+
+        final TestEntity childTestEntity = testEntity1;
+
+        // Now set sensor value
+        ((EntityInternal) clusterEntity1).sensors().set(Sensors.newStringSensor("sensor"), "bar");
+
+        String s1 = getConfigInTask(childTestEntity, TestEntity.CONF_NAME);
+        Assert.assertEquals(s1, "bar");
+
+        // Persist and rebind
+        Application app2 = rebind(testEntity.getApplication());
+
+        DynamicCluster clusterEntity2 = (DynamicCluster) Iterables.getOnlyElement(app2.getApplication().getChildren());
+
+        TestEntity testEntity2 = null;
+        for (Entity entity : clusterEntity2.getChildren()) {
+            if (entity instanceof TestEntity) {
+                testEntity2 = (TestEntity) entity;
+                break;
+            }
+        }
+        Assert.assertNotNull(testEntity2, "TestEntity not found in DynamicCluster");
+
+        // Assert the persisted state itself is as expected, and does not contain the value "bar"
+        BrooklynMementoRawData raw = BrooklynPersistenceUtils.newStateMemento(app2.getManagementContext(), MementoCopyMode.LOCAL);
+        String persistedState = raw.getEntities().get(testEntity2.getId());
+        Matcher matcher = Pattern.compile(".*\\<test.confName\\>(.*)\\<\\/test.confName\\>.*", Pattern.DOTALL)
+                .matcher(persistedState);
+        Assert.assertTrue(matcher.find());
+        String testConfNamePersistedState = matcher.group(1);
+
+        Assert.assertNotNull(testConfNamePersistedState);
+        Assert.assertFalse(testConfNamePersistedState.contains("bar"), "value leaked in persisted state");
+    }
+
+    @Test
     public void testDslAttributeWhenReadyRebind() throws Exception {
         Entity testEntity = entityWithAttributeWhenReady();
         ((EntityInternal) testEntity).sensors().set(Sensors.newStringSensor("foo"), "bar");