Search in sources :

Example 16 with TestEvent

use of org.graylog.events.event.TestEvent 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 17 with TestEvent

use of org.graylog.events.event.TestEvent 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 18 with TestEvent

use of org.graylog.events.event.TestEvent 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)

Example 19 with TestEvent

use of org.graylog.events.event.TestEvent 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 20 with TestEvent

use of org.graylog.events.event.TestEvent 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)

Aggregations

TestEvent (org.graylog.events.event.TestEvent)24 Test (org.junit.Test)23 EventWithContext (org.graylog.events.event.EventWithContext)15 Event (org.graylog.events.event.Event)12 FieldValue (org.graylog.events.fields.FieldValue)10 NotificationGracePeriodService (org.graylog.events.notifications.NotificationGracePeriodService)8 EventDefinitionDto (org.graylog.events.processor.EventDefinitionDto)5 Message (org.graylog2.plugin.Message)5 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)5 DateTime (org.joda.time.DateTime)5 StreamMock (org.graylog2.streams.StreamMock)1 Ignore (org.junit.Ignore)1