Search in sources :

Example 1 with AlertPipelineTrigger

use of com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger in project ApplicationInsights-Java by microsoft.

the class AlertTriggerTest method doesNotReTriggerAfterCooldown.

@Test
void doesNotReTriggerAfterCooldown() throws InterruptedException {
    AlertConfiguration config = new AlertConfiguration(AlertMetricType.CPU, true, 0.5f, 1, 1);
    AtomicBoolean called = new AtomicBoolean(false);
    AlertPipelineTrigger trigger = getAlertTrigger(config, called);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isTrue();
    called.set(false);
    Thread.sleep(2000);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.1);
    }
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AlertPipelineTrigger(com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with AlertPipelineTrigger

use of com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger in project ApplicationInsights-Java by microsoft.

the class AlertTriggerTest method overThresholdDataDoesTrigger.

@Test
void overThresholdDataDoesTrigger() {
    AlertConfiguration config = new AlertConfiguration(AlertMetricType.CPU, true, 0.5f, 1, 1);
    AtomicBoolean called = new AtomicBoolean(false);
    AlertPipelineTrigger trigger = getAlertTrigger(config, called);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AlertPipelineTrigger(com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with AlertPipelineTrigger

use of com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger in project ApplicationInsights-Java by microsoft.

the class AlertTriggerTest method doesNotReTriggerDueToCooldown.

@Test
void doesNotReTriggerDueToCooldown() {
    AlertConfiguration config = new AlertConfiguration(AlertMetricType.CPU, true, 0.5f, 1, 1000);
    AtomicBoolean called = new AtomicBoolean(false);
    AlertPipelineTrigger trigger = getAlertTrigger(config, called);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isTrue();
    called.set(false);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.1);
    }
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isFalse();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AlertPipelineTrigger(com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with AlertPipelineTrigger

use of com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger in project ApplicationInsights-Java by microsoft.

the class AlertTriggerTest method underThresholdDataDoesNotTrigger.

@Test
void underThresholdDataDoesNotTrigger() {
    AlertConfiguration config = new AlertConfiguration(AlertMetricType.CPU, true, 0.5f, 1, 1000);
    AtomicBoolean called = new AtomicBoolean(false);
    AlertPipelineTrigger trigger = getAlertTrigger(config, called);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.4);
    }
    assertThat(called.get()).isFalse();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AlertPipelineTrigger(com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

AlertPipelineTrigger (com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger)4 AlertConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Test (org.junit.jupiter.api.Test)4