brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] brooklyn-server git commit: Revert #452: setExpectedState sets actualState synchronously
Date Wed, 23 Nov 2016 14:28:15 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 453eca411 -> acd8631eb


Revert #452: setExpectedState sets actualState synchronously

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

Branch: refs/heads/master
Commit: e7c3b2b07a09b0770cce1784e4b046a30e36b53b
Parents: 453eca4
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Nov 23 14:04:35 2016 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Nov 23 14:04:35 2016 +0000

----------------------------------------------------------------------
 .../entity/lifecycle/ServiceStateLogic.java     | 10 +++++---
 .../entity/ApplicationLifecycleStateTest.java   |  9 +++++++
 .../entity/lifecycle/ServiceStateLogicTest.java | 26 ++++++++++++++------
 3 files changed, 33 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e7c3b2b0/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
b/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
index 0839262..0eac195 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
@@ -46,6 +46,7 @@ import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.enricher.AbstractEnricher;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityAdjuncts;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.entity.EntityPredicates;
 import org.apache.brooklyn.core.entity.lifecycle.Lifecycle.Transition;
@@ -155,6 +156,11 @@ public class ServiceStateLogic {
     public static void setExpectedState(Entity entity, Lifecycle state) {
         waitBrieflyForServiceUpIfStateIsRunning(entity, state);
         ((EntityInternal)entity).sensors().set(Attributes.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(state,
new Date()));
+        
+        Maybe<Enricher> enricher = EntityAdjuncts.tryFindWithUniqueTag(entity.enrichers(),
ComputeServiceState.DEFAULT_ENRICHER_UNIQUE_TAG);
+        if (enricher.isPresent() && enricher.get() instanceof ComputeServiceState)
{
+            ((ComputeServiceState)enricher.get()).onEvent(null);
+        }
     }
     
     public static Lifecycle getExpectedState(Entity entity) {
@@ -284,10 +290,6 @@ public class ServiceStateLogic {
 
         @Override
         public void onEvent(@Nullable SensorEvent<Object> event) {
-            if (event == null && warnCounter.getAndIncrement() % 1000 == 0) {
-                log.warn("Deprecated since 0.10.0. Calling ServiceStateLogic.onEvent explicitly
is deprecated to guarantee event ordering.");
-            }
-//            Preconditions.checkNotNull(event, "Calling onEvent explicitly no longer supported.
Can only be called as an event handler to guarantee ordering.");
             Preconditions.checkNotNull(entity, "Cannot handle subscriptions or compute state
until associated with an entity");
             
             Map<String, Object> serviceProblems = entity.getAttribute(SERVICE_PROBLEMS);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e7c3b2b0/core/src/test/java/org/apache/brooklyn/core/entity/ApplicationLifecycleStateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/ApplicationLifecycleStateTest.java
b/core/src/test/java/org/apache/brooklyn/core/entity/ApplicationLifecycleStateTest.java
index 70057d4..d340d31 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/ApplicationLifecycleStateTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/ApplicationLifecycleStateTest.java
@@ -134,6 +134,15 @@ public class ApplicationLifecycleStateTest extends BrooklynMgmtUnitTestSupport
{
         assertHealthEventually(app, Lifecycle.ON_FIRE, false);
     }
 
+    // TODO Fails in a full `mvn clean install`, but I can't get it to fail in Eclipse running

+    // lots of times, or with `mvn test -Dtest=ApplicationLifecycleStateTest`. The failure
is:
+    //     java.lang.AssertionError: (Dumped entity info - see log); entity=Application[6q37l8cu];
state=on-fire; up=true; notUpIndicators={}; serviceProblems={service-lifecycle-indicators-from-children-and-members=Required
entity not healthy: FailingEntityImpl{id=exz9n1pti0}}
+    //     at org.apache.brooklyn.core.entity.ApplicationLifecycleStateTest.assertUpAndRunningEventually(ApplicationLifecycleStateTest.java:204)
+    //     at org.apache.brooklyn.core.entity.ApplicationLifecycleStateTest.testChildFailuresOnStartButWithQuorumCausesAppToSucceed(ApplicationLifecycleStateTest.java:146)
+    //
+    // See https://github.com/apache/brooklyn-server/pull/452 and https://github.com/apache/brooklyn-server/pull/454

+    // for further discussion of fix/issue.
+    @Test(groups="Broken")
     public void testChildFailuresOnStartButWithQuorumCausesAppToSucceed() throws Exception
{
         TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
                 .configure(StartableApplication.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne())

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e7c3b2b0/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
b/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
index 61fd147..cc240ea 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
@@ -36,7 +36,6 @@ import org.apache.brooklyn.core.entity.EntityAdjuncts;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers;
-import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembersSpec;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ComputeServiceState;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceNotUpLogic;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceProblemsLogic;
@@ -45,7 +44,6 @@ import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.core.test.entity.TestEntityImpl.TestEntityWithoutEnrichers;
 import org.apache.brooklyn.entity.group.DynamicCluster;
-import org.apache.brooklyn.util.collections.QuorumCheck;
 import org.apache.brooklyn.util.collections.QuorumCheck.QuorumChecks;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.time.Duration;
@@ -53,9 +51,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 
 @Test
 public class ServiceStateLogicTest extends BrooklynAppUnitTestSupport {
@@ -307,14 +307,24 @@ public class ServiceStateLogicTest extends BrooklynAppUnitTestSupport
{
         }
     }
 
-    @Test
+    // TODO Reverted part of the change in https://github.com/apache/brooklyn-server/pull/452
 
+    // (where this test was added), so this now fails.
+    @Test(groups={"WIP", "Broken"})
     public void testServiceStateNotCalledExplicitly() throws Exception {
-        EnricherSpec<CountingComputeServiceState> enricherSpec = EnricherSpec.create(CountingComputeServiceState.class);
-        CountingComputeServiceState enricher = mgmt.getEntityManager().createEnricher(enricherSpec);
-        app.enrichers().add(enricher);
+        ComputeServiceState oldEnricher = (ComputeServiceState) Iterables.find(app.enrichers(),
Predicates.instanceOf(ComputeServiceState.class));
+        String oldUniqueTag = oldEnricher.getUniqueTag();
+        
+        CountingComputeServiceState enricher = app.enrichers().add(EnricherSpec.create(CountingComputeServiceState.class)
+                .uniqueTag(oldUniqueTag));
+        
+        // Confirm that we only have one enricher now (i.e. we've replaced the original)
+        Iterable<Enricher> newEnrichers = Iterables.filter(app.enrichers(), Predicates.instanceOf(ComputeServiceState.class));
+        assertEquals(Iterables.size(newEnrichers), 1, "newEnrichers="+newEnrichers);
+        assertEquals(Iterables.getOnlyElement(newEnrichers), enricher, "newEnrichers="+newEnrichers);
 
-        ServiceStateLogic.setExpectedState(entity, Lifecycle.RUNNING);
-        assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        // When setting the expected state, previously that caused a onEvent(null) to be
triggered synchronously
+        ServiceStateLogic.setExpectedState(app, Lifecycle.RUNNING);
+        assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
 
         assertTrue(enricher.cntCalled.get() > 0);
         assertEquals(enricher.cntCalledWithNull.get(), 0);


Mime
View raw message