Search in sources :

Example 1 with NotificationGracePeriodService

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

the class NotificationGracePeriodServiceTest method emptyKey.

@Test
public void emptyKey() {
    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());
    final Event event2 = new TestEvent();
    event.setKeyTuple(ImmutableList.of());
    event2.setEventTimestamp(event.getEventTimestamp().plus(1L));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event2)).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 2 with NotificationGracePeriodService

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

the class NotificationGracePeriodServiceTest method falseWithDisabledGracePeriod.

@Test
public void falseWithDisabledGracePeriod() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(0L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent();
    event.setKeyTuple(ImmutableList.of("testkey"));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).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 3 with NotificationGracePeriodService

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

the class NotificationGracePeriodServiceTest method differentKey.

@Test
public void differentKey() {
    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("otherkey"));
    event2.setEventTimestamp(event.getEventTimestamp().plus(1L));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", 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 4 with NotificationGracePeriodService

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

the class NotificationGracePeriodServiceTest method withinGracePeriod.

@Test
public void withinGracePeriod() {
    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(5L));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event2)).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 5 with NotificationGracePeriodService

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

the class NotificationGracePeriodServiceTest method outsideGracePeriod.

@Test
public void outsideGracePeriod() {
    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(11L));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", 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)

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