Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E67D81880A for ; Thu, 7 Jan 2016 16:10:47 +0000 (UTC) Received: (qmail 91590 invoked by uid 500); 7 Jan 2016 16:10:47 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 91556 invoked by uid 500); 7 Jan 2016 16:10:47 -0000 Mailing-List: contact commits-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list commits@brooklyn.apache.org Received: (qmail 91537 invoked by uid 99); 7 Jan 2016 16:10:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jan 2016 16:10:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3EA86E2C82; Thu, 7 Jan 2016 16:10:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.apache.org Date: Thu, 07 Jan 2016 16:10:48 -0000 Message-Id: In-Reply-To: <930ed7e3e8574077a2d1f50a708f984d@git.apache.org> References: <930ed7e3e8574077a2d1f50a708f984d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/8] incubator-brooklyn git commit: Address comments Address comments - sanity check on serialized value - set up test for attributeWhenReady in entity spec (not working ATM see FIXME comment) Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/3e57289e Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/3e57289e Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/3e57289e Branch: refs/heads/master Commit: 3e57289e481314aa12011b5fdc704370331cc852 Parents: 68d8018 Author: Guglielmo Nigri Authored: Tue Dec 22 22:38:32 2015 +0100 Committer: Guglielmo Nigri Committed: Tue Dec 29 12:27:22 2015 +0100 ---------------------------------------------------------------------- .../camp/brooklyn/DslAndRebindYamlTest.java | 65 +++++++++++++++++--- 1 file changed, 56 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3e57289e/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 8f0f560..2fda4a0 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 @@ -21,10 +21,14 @@ package org.apache.brooklyn.camp.brooklyn; import java.io.File; import java.util.Set; import java.util.concurrent.Callable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.brooklyn.api.entity.Application; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.api.mgmt.ha.MementoCopyMode; +import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoRawData; import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.api.sensor.Sensor; import org.apache.brooklyn.camp.brooklyn.spi.dsl.BrooklynDslDeferredSupplier; @@ -34,6 +38,7 @@ import org.apache.brooklyn.core.entity.Attributes; import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.entity.EntityInternal; import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; +import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils; import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils; import org.apache.brooklyn.core.sensor.Sensors; import org.apache.brooklyn.core.test.entity.TestEntity; @@ -68,7 +73,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest { mgmtContexts.add(mgmt); return mgmt; } - + @AfterMethod(alwaysRun = true) @Override public void tearDown() { @@ -101,11 +106,11 @@ public class DslAndRebindYamlTest extends AbstractYamlTest { log.info("App started:"); Entities.dumpInfo(app); - + Assert.assertTrue(app.getChildren().iterator().hasNext(), "Expected app to have child entity"); Entity entity = app.getChildren().iterator().next(); Assert.assertTrue(entity instanceof TestEntity, "Expected TestEntity, found " + entity.getClass()); - + return entity; } @@ -117,7 +122,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest { } }).build()).getUnchecked(); } - + @Test public void testDslAttributeWhenReady() throws Exception { Entity testEntity = entityWithAttributeWhenReady(); @@ -136,6 +141,48 @@ public class DslAndRebindYamlTest extends AbstractYamlTest { Assert.assertTrue(BrooklynDslDeferredSupplier.class.isInstance(maybe.get())); BrooklynDslDeferredSupplier deferredSupplier = (BrooklynDslDeferredSupplier) maybe.get(); Assert.assertEquals(deferredSupplier.toString(), "$brooklyn:entity(\"x\").attributeWhenReady(\"foo\")"); + + // assert the persisted state itself is as expected, and not too big + BrooklynMementoRawData raw = BrooklynPersistenceUtils.newStateMemento(app2.getManagementContext(), MementoCopyMode.LOCAL); + String persistedStateForE2 = raw.getEntities().get(e2.getId()); + Matcher matcher = Pattern.compile(".*\\(.*)\\<\\/test.confName\\>.*", Pattern.DOTALL) + .matcher(persistedStateForE2); + Assert.assertTrue(matcher.find()); + String testConfNamePersistedState = matcher.group(1); + + Assert.assertNotNull(testConfNamePersistedState); + // should be about 200 chars long, something like: + // + // + // + // + // x + // GLOBAL + // + // foo + // + // + + Assert.assertTrue(testConfNamePersistedState.length() < 400, "persisted state too long: "+testConfNamePersistedState); + } + + @Test public void testDslAttributeWhenReadyPersistedInEntitySpec() 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\")"; + + Entity testEntity = createAndStartApplication(yaml); + + // FIXME java.io.NotSerializableException: org.apache.brooklyn.entity.group.DynamicClusterImpl$NextClusterMemberIdSupplier + Application app2 = rebind(testEntity.getApplication()); } @Test @@ -144,12 +191,12 @@ public class DslAndRebindYamlTest extends AbstractYamlTest { ((EntityInternal)testEntity).sensors().set(Sensors.newStringSensor("foo"), "bar"); Application app2 = rebind(testEntity.getApplication()); Entity e2 = Iterables.getOnlyElement( app2.getChildren() ); - + Assert.assertEquals(getConfigInTask(e2, TestEntity.CONF_NAME), "bar"); } private Entity entityWithAttributeWhenReady() throws Exception { - return setupAndCheckTestEntityInBasicYamlWith( + return setupAndCheckTestEntityInBasicYamlWith( " id: x", " brooklyn.config:", " test.confName: $brooklyn:component(\"x\").attributeWhenReady(\"foo\")"); @@ -169,7 +216,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest { s = inTask ? getConfigInTask(te2, configKey) : te2.getConfig(configKey); Assert.assertEquals(s, expectedSensor); } - + @Test public void testDslSensorFromClass() throws Exception { doTestOnEntityWithSensor(entityWithSensorFromClass(), Attributes.SERVICE_UP); @@ -179,7 +226,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest { @Test public void testDslSensorLocal() throws Exception { doTestOnEntityWithSensor(entityWithSensorLocal(), TestEntity.SEQUENCE); - // here without context it makes one up, so type info (and description etc) not present; + // here without context it makes one up, so type info (and description etc) not present; // but context is needed to submit the DslDeferredSupplier object, so this would fail // doTestOnEntityWithSensor(entityWithSensorAdHoc(), Sensors.newSensor(Object.class, TestEntity.SEQUENCE.getName()), false); } @@ -189,7 +236,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest { // here context has no impact, but it is needed to submit the DslDeferredSupplier object so this would fail // doTestOnEntityWithSensor(entityWithSensorAdHoc(), Sensors.newSensor(Object.class, "sensor.foo"), false); } - + private Entity entityWithSensorFromClass() throws Exception { return setupAndCheckTestEntityInBasicYamlWith( " id: x",