use of com.microsoft.applicationinsights.alerting.alert.AlertBreach in project ApplicationInsights-Java by microsoft.
the class AlertingSubsystemTest method manualAlertWorks.
@Test
void manualAlertWorks() {
AtomicReference<AlertBreach> called = new AtomicReference<>();
Consumer<AlertBreach> consumer = called::set;
AlertingSubsystem service = AlertingSubsystem.create(consumer, Executors.newSingleThreadExecutor());
service.updateConfiguration(new AlertingConfiguration(new AlertConfiguration(AlertMetricType.CPU, true, 80, 30, 14400), new AlertConfiguration(AlertMetricType.MEMORY, true, 20, 120, 14400), new DefaultConfiguration(true, 5, 120), new CollectionPlanConfiguration(true, EngineMode.immediate, ZonedDateTime.now().plus(100, ChronoUnit.SECONDS), 120, "a-settings-moniker")));
assertThat(called.get().getType()).isEqualTo(AlertMetricType.MANUAL);
}
use of com.microsoft.applicationinsights.alerting.alert.AlertBreach in project ApplicationInsights-Java by microsoft.
the class GcEventMonitorTest method endToEndAlertIsTriggered.
@Test
void endToEndAlertIsTriggered() throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<AlertBreach> alertFuture = new CompletableFuture<>();
AlertingSubsystem alertingSubsystem = getAlertingSubsystem(alertFuture);
GcMonitorFactory factory = new GcMonitorFactory() {
@Override
public MemoryManagement monitorSelf(ExecutorService executorService, GcEventConsumer consumer) {
consumer.accept(mockGcEvent());
return null;
}
@Override
public MemoryManagement monitor(MBeanServerConnection connection, ExecutorService executorService, GcEventConsumer consumer) {
return null;
}
};
GcEventMonitor.init(alertingSubsystem, TelemetryClient.createForTest(), Executors.newSingleThreadExecutor(), new GcEventMonitor.GcEventMonitorConfiguration(GcReportingLevel.NONE), factory);
AlertBreach alert = alertFuture.get(10, TimeUnit.SECONDS);
assertThat(alert.getAlertValue()).isEqualTo(90.0);
}
Aggregations