You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by aledsage <gi...@git.apache.org> on 2014/09/05 17:15:24 UTC

[GitHub] incubator-brooklyn pull request: Fix ServiceStateLogicTest

GitHub user aledsage opened a pull request:

    https://github.com/apache/incubator-brooklyn/pull/148

    Fix ServiceStateLogicTest

    Previously `testManuallySettingIndicatorsOnApplicationsIsMoreComplicated` failed non-deterministically. Though this test name suggested the failure was because it wasn't complicated enough, the actual cause was mostly down to using `assertAttributeEqualsEventually` instead of `assertAttributeEquals` or a couple of wrong assertions `:-)`.
    
    I added some `assertAttributeEqualsContinually` assertions for when we expect the state to remain the same after changing some other attribute or config. This is because the test failed non-deterministically (which could be made deterministic with some `sleep(1000)` added temporarily.
    
    I renamed the test to `testManuallySettingIndicatorsOnApplications`. Longer term, it might well be worth splitting this big test into multiple small tests that each test a smaller number of cases.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/aledsage/incubator-brooklyn fix/ServiceStateLogicTest

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-brooklyn/pull/148.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #148
    
----
commit eec69f3e44084bb5348ab5950b63a344e58bf895
Author: Aled Sage <al...@gmail.com>
Date:   2014-09-05T15:09:01Z

    Add javadoc to QuorumCheck

commit 6e0b31d8bb1cbee14a7ba5173e9850c76760df96
Author: Aled Sage <al...@gmail.com>
Date:   2014-09-05T15:09:16Z

    Fix testManuallySettingIndicatorsOnApplications

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Fix ServiceStateLogicTest

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/148#discussion_r17211779
  
    --- Diff: core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java ---
    @@ -185,54 +190,77 @@ public void testManuallySettingIndicatorsOnApplicationsIsMoreComplicated() {
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK, QuorumChecks.allAndAtLeastOne());
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
             
    -        // if entity is expected running, then it shows running, because service is up, and it's reflected at app and at entity
    +        // if entity is expected running, then it will show running because service is up; this is reflected at app and at entity
             ServiceStateLogic.setExpectedState(entity, Lifecycle.RUNNING);
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);
             assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
             
    -        // now, when the entity is unmanaged, the app is still running because children are empty
    +        // now, when the entity is unmanaged, the app goes on fire because don't have "at least one running"
             Entities.unmanage(entity);
    -        assertAttributeEquals(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    -        // but if we change its up quorum to atLeastOne then service up becomes false
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
    +        // but UP_QUORUM_CHECK is still the default atLeastOneUnlessEmpty; so serviceUp=true
    +        assertAttributeEqualsContinually(app, Attributes.SERVICE_UP, true);
    +        
    +        // if we change its up-quorum to atLeastOne then state becomes stopped (because there is no expected state; has not been started)
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.UP_QUORUM_CHECK, QuorumChecks.atLeastOne());
    -        assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false);
    -        // and state becomes stopped (because there is no expected state)
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED);
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false);
             
             // if we now start it will successfully start (because unlike entities it does not wait for service up) 
             // but will remain down and will go on fire
             app.start(ImmutableList.<Location>of());
             assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false);
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
    -        // restoring this to atLeastOneUnlessEmpty causes it to become RUNNING
    +        
    +        // restoring up-quorum to "atLeastOneUnlessEmpty" causes it to become RUNNING, because happy with empty
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.UP_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty());
             assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);
    -        appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK, QuorumChecks.all());
    -        assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        // but running-quorum is still allAndAtLeastOne, so remains on-fire
    +        assertAttributeEqualsContinually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
             
    -        // now add a child, it's still up and running because null values are ignored by default
    +        // now add a child, it's still up and running because null values are ignored by default (i.e. we're still "empty")
             entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    -        assertAttributeEquals(app, Attributes.SERVICE_UP, true);
    -        assertAttributeEquals(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        assertAttributeEqualsContinually(app, Attributes.SERVICE_UP, true);
    +        assertAttributeEqualsContinually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
    +        
             // tell it not to ignore null values for children states, and it will go onfire (but still be service up)
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.IGNORE_ENTITIES_WITH_THESE_SERVICE_STATES, 
                 ImmutableSet.<Lifecycle>of());
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
             assertAttributeEquals(app, Attributes.SERVICE_UP, true);
    +        
             // tell it not to ignore null values for service up and it will go service down
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.IGNORE_ENTITIES_WITH_SERVICE_UP_NULL, false);
             assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false);
    +        
    +        // set the entity to RUNNING and the app will be healthy again
    +        ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1);
    +        ServiceStateLogic.setExpectedState(entity, Lifecycle.RUNNING);
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        assertAttributeEquals(entity, Attributes.SERVICE_UP, true);
    +        assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
         }
             
         private static <T> void assertAttributeEqualsEventually(Entity x, AttributeSensor<T> sensor, T value) {
             try {
    -            EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", Duration.seconds(10)), x, sensor, value);
    +            EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", Duration.seconds(3)), x, sensor, value);
             } catch (Throwable e) {
                 log.warn("Expected "+x+" eventually to have "+sensor+" = "+value+"; instead:");
                 Entities.dumpInfo(x);
                 throw Exceptions.propagate(e);
             }
         }
    +    private static <T> void assertAttributeEqualsContinually(Entity x, AttributeSensor<T> sensor, T value) {
    --- End diff --
    
    Why not put this (and surrounding assertions not added in this PR) into `brooklyn.test.Asserts` as they all seem generic enough to be useful elsewhere?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Fix ServiceStateLogicTest

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/148#issuecomment-54731170
  
    :+1: Looks OK to merge


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Fix ServiceStateLogicTest

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/148#issuecomment-54949864
  
    LGTM +1, merging


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Fix ServiceStateLogicTest

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/148#discussion_r17211793
  
    --- Diff: core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java ---
    @@ -185,54 +190,77 @@ public void testManuallySettingIndicatorsOnApplicationsIsMoreComplicated() {
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK, QuorumChecks.allAndAtLeastOne());
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
             
    -        // if entity is expected running, then it shows running, because service is up, and it's reflected at app and at entity
    +        // if entity is expected running, then it will show running because service is up; this is reflected at app and at entity
             ServiceStateLogic.setExpectedState(entity, Lifecycle.RUNNING);
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);
             assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
             
    -        // now, when the entity is unmanaged, the app is still running because children are empty
    +        // now, when the entity is unmanaged, the app goes on fire because don't have "at least one running"
             Entities.unmanage(entity);
    -        assertAttributeEquals(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    -        // but if we change its up quorum to atLeastOne then service up becomes false
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
    +        // but UP_QUORUM_CHECK is still the default atLeastOneUnlessEmpty; so serviceUp=true
    +        assertAttributeEqualsContinually(app, Attributes.SERVICE_UP, true);
    +        
    +        // if we change its up-quorum to atLeastOne then state becomes stopped (because there is no expected state; has not been started)
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.UP_QUORUM_CHECK, QuorumChecks.atLeastOne());
    -        assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false);
    -        // and state becomes stopped (because there is no expected state)
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED);
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false);
             
             // if we now start it will successfully start (because unlike entities it does not wait for service up) 
             // but will remain down and will go on fire
             app.start(ImmutableList.<Location>of());
             assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false);
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
    -        // restoring this to atLeastOneUnlessEmpty causes it to become RUNNING
    +        
    +        // restoring up-quorum to "atLeastOneUnlessEmpty" causes it to become RUNNING, because happy with empty
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.UP_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty());
             assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);
    -        appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK, QuorumChecks.all());
    -        assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        // but running-quorum is still allAndAtLeastOne, so remains on-fire
    +        assertAttributeEqualsContinually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
             
    -        // now add a child, it's still up and running because null values are ignored by default
    +        // now add a child, it's still up and running because null values are ignored by default (i.e. we're still "empty")
             entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    -        assertAttributeEquals(app, Attributes.SERVICE_UP, true);
    -        assertAttributeEquals(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        assertAttributeEqualsContinually(app, Attributes.SERVICE_UP, true);
    +        assertAttributeEqualsContinually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
    +        
             // tell it not to ignore null values for children states, and it will go onfire (but still be service up)
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.IGNORE_ENTITIES_WITH_THESE_SERVICE_STATES, 
                 ImmutableSet.<Lifecycle>of());
             assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
             assertAttributeEquals(app, Attributes.SERVICE_UP, true);
    +        
             // tell it not to ignore null values for service up and it will go service down
             appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.IGNORE_ENTITIES_WITH_SERVICE_UP_NULL, false);
             assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false);
    +        
    +        // set the entity to RUNNING and the app will be healthy again
    +        ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1);
    +        ServiceStateLogic.setExpectedState(entity, Lifecycle.RUNNING);
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);
    +        assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        assertAttributeEquals(entity, Attributes.SERVICE_UP, true);
    +        assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
         }
             
         private static <T> void assertAttributeEqualsEventually(Entity x, AttributeSensor<T> sensor, T value) {
             try {
    -            EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", Duration.seconds(10)), x, sensor, value);
    +            EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", Duration.seconds(3)), x, sensor, value);
             } catch (Throwable e) {
                 log.warn("Expected "+x+" eventually to have "+sensor+" = "+value+"; instead:");
                 Entities.dumpInfo(x);
                 throw Exceptions.propagate(e);
             }
         }
    +    private static <T> void assertAttributeEqualsContinually(Entity x, AttributeSensor<T> sensor, T value) {
    --- End diff --
    
    Or `EntityTestUtils` I suppose. Perhaps we can enforce a convention that `Asserts` will have the base `assertSomethingHappensEventually(Entity entity, T thing)` sort of methods and `EntityTestUtils` has overloads that call the same-named method in `Asserts` but with _try_..._catch_ blocks that do tae `dumpInfo()` and rethrow, as here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Fix ServiceStateLogicTest

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-brooklyn/pull/148


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---