@Override public Status evaluate(double dsValue) { if (isThresholdExceeded(dsValue)) { if (isArmed()) { setExceededCount(getExceededCount() + 1); LOG.debug("evaluate: {} threshold exceeded, count={}", getType(), getExceededCount()); if (isTriggerCountExceeded()) { LOG.debug("evaluate: {} threshold triggered", getType()); setExceededCount(1); setArmed(false); return Status.TRIGGERED; } } } else if (isRearmExceeded(dsValue)) { if (!isArmed()) { LOG.debug("evaluate: {} threshold rearmed", getType()); setArmed(true); setExceededCount(0); return Status.RE_ARMED; } if (getExceededCount() > 0) { LOG.debug("evaluate: resetting {} threshold count to 0, because the current value indicates that the in-progress threshold has been rearmed, but it doesn't triggered yet.", getType()); setExceededCount(0); } } else { LOG.debug("evaluate: resetting {} threshold count to 0", getType()); setExceededCount(0); } return Status.NO_CHANGE; }
@Test public void testIsTriggerCountExceededNotAfterReArm() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(1); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorStateHighLow item = new ThresholdEvaluatorStateHighLow(wrapper); assertFalse("trigger count should not be exeeded before exceeding value", item.isTriggerCountExceeded()); Status status = item.evaluate(100.0); assertEquals("first threshold evaluation status", Status.TRIGGERED, status); assertTrue("trigger count should be exeeded after exceeding value", item.isTriggerCountExceeded()); status = item.evaluate(0.0); assertEquals("first threshold evaluation status", Status.RE_ARMED, status); assertFalse("trigger count should be reset after being rearmed", item.isTriggerCountExceeded()); }
@Test public void testIsTriggerCountExceededAtTriggerValueOne() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(1); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorStateHighLow item = new ThresholdEvaluatorStateHighLow(wrapper); assertFalse("trigger count should not be exeeded before exceeding value", item.isTriggerCountExceeded()); Status status = item.evaluate(100.0); assertEquals("first threshold evaluation status", Status.TRIGGERED, status); assertTrue("trigger count should be exeeded after exceeding value (and being triggered)", item.isTriggerCountExceeded()); }
@Test public void testIsTriggerCountExceededNotAtTriggerValueTwo() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.HIGH); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(2); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThresholdEvaluatorStateHighLow item = new ThresholdEvaluatorStateHighLow(wrapper); assertFalse("trigger count should not be exeeded before exceeding value", item.isTriggerCountExceeded()); Status status = item.evaluate(100.0); assertEquals("first threshold evaluation status", Status.NO_CHANGE, status); assertFalse("trigger count should not be exeeded after only exceeding value once", item.isTriggerCountExceeded()); }