Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/571#discussion_r27870258
  
    --- Diff: 
policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorTest.java ---
    @@ -312,6 +316,54 @@ public void 
testReportsFailureWhenAlreadyOnFireOnRegisteringPolicy() throws Exce
             assertHasEventEventually(HASensors.ENTITY_FAILED, 
Predicates.<Object>equalTo(e1), null);
         }
         
    +    @Test(groups="Integration") // Has a 1.5 second wait
    +    public void testRepublishedFailure() throws Exception {
    +        Duration republishPeriod = Duration.millis(100);
    +
    +        e1.addEnricher(EnricherSpec.create(ServiceFailureDetector.class)
    +                
.configure(ServiceFailureDetector.ENTITY_FAILED_REPUBLISH_TIME, 
republishPeriod));
    +            
    +        // Set the entity to healthy
    +        e1.setAttribute(TestEntity.SERVICE_UP, true);
    +        ServiceStateLogic.setExpectedState(e1, Lifecycle.RUNNING);
    +        EntityTestUtils.assertAttributeEqualsEventually(e1, 
Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        
    +        // Make the entity fail;
    +        ServiceStateLogic.ServiceProblemsLogic.updateProblemsIndicator(e1, 
"test", "foo");
    +        EntityTestUtils.assertAttributeEqualsEventually(e1, 
TestEntity.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
    +        assertHasEventEventually(HASensors.ENTITY_FAILED, 
Predicates.<Object>equalTo(e1), null);
    +
    +        TimeUnit.SECONDS.sleep(1);
    +        
    +        // Now recover
    +        ServiceStateLogic.ServiceProblemsLogic.clearProblemsIndicator(e1, 
"test");
    +        EntityTestUtils.assertAttributeEqualsEventually(e1, 
TestEntity.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    +        assertHasEventEventually(HASensors.ENTITY_RECOVERED, 
Predicates.<Object>equalTo(e1), null);
    +        
    +        TimeUnit.MILLISECONDS.sleep(500);
    +
    +        //can't assert number of republish events due to jitter, warn 
below if it deviates from expectation
    +        assertTrue(events.size() > 2, "events="+events);
    +
    +        SensorEvent<FailureDescriptor> prevEvent = null;
    +        for (SensorEvent<FailureDescriptor> event : events) {
    +            if (prevEvent != null) {
    +                long repeatOffset = event.getTimestamp() - 
prevEvent.getTimestamp();
    +                long deviation = Math.abs(repeatOffset - 
republishPeriod.toMilliseconds());
    +                if (deviation > republishPeriod.toMilliseconds()/10 &&
    +                        //warn only if recovered is too far away from the 
last failure
    +                        
(!event.getSensor().equals(HASensors.ENTITY_RECOVERED) ||
    +                        repeatOffset > republishPeriod.toMilliseconds())) {
    +                    log.error("The time between failure republish (" + 
repeatOffset + "ms) deviates too much from the expected " + republishPeriod + 
". prevEvent=" + prevEvent + ", event=" + event);
    --- End diff --
    
    Republish is already checked for above ` assertTrue(events.size() > 2, 
"events="+events);` - 1 event for initial FAIL, 1 event for RECOVERED, any 
additional events for republish. The updated code now waits for 10 events 
before continuing.
    
    The check here is to make sure we are really emitting republish FAILs at 
the requested frequency, but this is something that can't be asserted as it 
will vary even on idle systems.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to