Search in sources :

Example 6 with NotificationGracePeriodService

use of org.graylog.events.notifications.NotificationGracePeriodService in project graylog2-server by Graylog2.

the class NotificationGracePeriodServiceTest method insideOutsideInsideGracePeriod.

@Test
public void insideOutsideInsideGracePeriod() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(10L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent(DateTime.now(UTC), "testkey");
    final Event event2 = new TestEvent(event.getEventTimestamp().plus(5L), "testkey");
    final Event event3 = new TestEvent(event2.getEventTimestamp().plus(6L), "testkey");
    final Event event4 = new TestEvent(event3.getEventTimestamp().plus(6L), "testkey");
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event2)).isTrue();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event3)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event4)).isTrue();
}
Also used : NotificationGracePeriodService(org.graylog.events.notifications.NotificationGracePeriodService) TestEvent(org.graylog.events.event.TestEvent) TestEvent(org.graylog.events.event.TestEvent) Event(org.graylog.events.event.Event) Test(org.junit.Test)

Example 7 with NotificationGracePeriodService

use of org.graylog.events.notifications.NotificationGracePeriodService in project graylog2-server by Graylog2.

the class NotificationGracePeriodServiceTest method differentNotification.

@Test
public void differentNotification() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(10L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent();
    event.setKeyTuple(ImmutableList.of("testkey"));
    final Event event2 = new TestEvent();
    event2.setKeyTuple(ImmutableList.of("testkey"));
    event2.setEventTimestamp(event.getEventTimestamp().plus(1L));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "4242", event2)).isFalse();
}
Also used : NotificationGracePeriodService(org.graylog.events.notifications.NotificationGracePeriodService) TestEvent(org.graylog.events.event.TestEvent) TestEvent(org.graylog.events.event.TestEvent) Event(org.graylog.events.event.Event) Test(org.junit.Test)

Example 8 with NotificationGracePeriodService

use of org.graylog.events.notifications.NotificationGracePeriodService in project graylog2-server by Graylog2.

the class NotificationGracePeriodServiceTest method insideThenInsideGracePeriod.

@Test
public void insideThenInsideGracePeriod() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(10L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent(DateTime.now(UTC), "testkey");
    final Event event2 = new TestEvent(event.getEventTimestamp().plus(5L), "testkey");
    final Event event3 = new TestEvent(event2.getEventTimestamp().plus(4L), "testkey");
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event2)).isTrue();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event3)).isTrue();
}
Also used : NotificationGracePeriodService(org.graylog.events.notifications.NotificationGracePeriodService) TestEvent(org.graylog.events.event.TestEvent) TestEvent(org.graylog.events.event.TestEvent) Event(org.graylog.events.event.Event) Test(org.junit.Test)

Aggregations

Event (org.graylog.events.event.Event)8 TestEvent (org.graylog.events.event.TestEvent)8 NotificationGracePeriodService (org.graylog.events.notifications.NotificationGracePeriodService)8 Test (org.junit.Test)8