@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 testIsRearmExceededBogusType() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.RELATIVE_CHANGE); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(1); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThrowableAnticipator ta = new ThrowableAnticipator(); ta.anticipate(new IllegalStateException("This thresholding strategy can only be used for thresholding types of 'high' and 'low'.")); try { ThresholdEvaluatorStateHighLow item = new ThresholdEvaluatorStateHighLow(wrapper); item.isThresholdExceeded(0.0); } catch (Throwable t) { ta.throwableReceived(t); } ta.verifyAnticipated(); }
@Test public void testIsThresholdExceededBogusType() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.RELATIVE_CHANGE); threshold.setDsName("ds-name"); threshold.setDsType("node"); threshold.setValue(99.0); threshold.setRearm(0.5); threshold.setTrigger(1); ThresholdConfigWrapper wrapper=new ThresholdConfigWrapper(threshold); ThrowableAnticipator ta = new ThrowableAnticipator(); ta.anticipate(new IllegalStateException("This thresholding strategy can only be used for thresholding types of 'high' and 'low'.")); try { ThresholdEvaluatorStateHighLow item = new ThresholdEvaluatorStateHighLow(wrapper); item.isThresholdExceeded(98.0); } catch (Throwable t) { ta.throwableReceived(t); } ta.verifyAnticipated(); }
@Test public void testIsThresholdExceededLowTriggeredEqual() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.LOW); 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); assertTrue("threshold should be exceeded", item.isThresholdExceeded(99.0)); }
@Test public void testIsThresholdExceededHighNotTriggeredBelow() { 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("threshold should not be exceeded", item.isThresholdExceeded(98.0)); }
@Test public void testIsThresholdExceededHighTriggeredAbove() { 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); assertTrue("threshold should be exceeded", item.isThresholdExceeded(100.0)); }
@Test public void testIsThresholdExceededLowTriggeredBelow() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.LOW); 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); assertTrue("threshold should be exceeded", item.isThresholdExceeded(98.0)); }
@Test public void testIsThresholdExceededHighTriggeredEqual() { 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); assertTrue("threshold should be exceeded", item.isThresholdExceeded(99.0)); }
@Test public void testIsThresholdExceededLowNotTriggeredAbove() { Threshold threshold = new Threshold(); threshold.setType(ThresholdType.LOW); 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("threshold should not be exceeded", item.isThresholdExceeded(100.0)); }