Search in sources :

Example 1 with GcEventConsumer

use of com.microsoft.gcmonitor.GcEventConsumer 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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) GcEventConsumer(com.microsoft.gcmonitor.GcEventConsumer) AlertBreach(com.microsoft.applicationinsights.alerting.alert.AlertBreach) ExecutorService(java.util.concurrent.ExecutorService) AlertingSubsystem(com.microsoft.applicationinsights.alerting.AlertingSubsystem) MBeanServerConnection(javax.management.MBeanServerConnection) GcMonitorFactory(com.microsoft.gcmonitor.GcMonitorFactory) Test(org.junit.jupiter.api.Test)

Aggregations

AlertingSubsystem (com.microsoft.applicationinsights.alerting.AlertingSubsystem)1 AlertBreach (com.microsoft.applicationinsights.alerting.alert.AlertBreach)1 GcEventConsumer (com.microsoft.gcmonitor.GcEventConsumer)1 GcMonitorFactory (com.microsoft.gcmonitor.GcMonitorFactory)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 Test (org.junit.jupiter.api.Test)1