Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/571#discussion_r27614624
--- 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 --
I see it's just a log rather than a failure. Is that because of the risk of
false negatives? Would be good if we can have a test that will genuinely fail
if the republish isn't working. For example, we could assert that we eventually
get 2 entity_failed events before we set the entity has recovered.
---
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.
---