use of org.graylog.events.TestEventProcessorConfig in project graylog2-server by Graylog2.
the class EventDefinitionHandlerTest method updateWithSchedulingDisabled.
@Test
@MongoDBFixtures("event-processors.json")
public void updateWithSchedulingDisabled() {
final String newTitle = "A NEW TITLE " + DateTime.now(DateTimeZone.UTC).toString();
final String newDescription = "A NEW DESCRIPTION " + DateTime.now(DateTimeZone.UTC).toString();
final EventDefinitionDto existingDto = eventDefinitionService.get("54e3deadbeefdeadbeef0000").orElse(null);
final JobDefinitionDto existingJobDefinition = jobDefinitionService.get("54e3deadbeefdeadbeef0001").orElse(null);
final JobTriggerDto existingTrigger = jobTriggerService.get("54e3deadbeefdeadbeef0002").orElse(null);
final TestEventProcessorConfig existingConfig = (TestEventProcessorConfig) existingDto.config();
final TestEventProcessorConfig newConfig = existingConfig.toBuilder().executeEveryMs(550000).searchWithinMs(800000).build();
assertThat(existingDto).isNotNull();
assertThat(existingJobDefinition).isNotNull();
assertThat(existingTrigger).isNotNull();
final EventDefinitionDto updatedDto = existingDto.toBuilder().title(newTitle).description(newDescription).config(newConfig).build();
assertThat(handler.update(updatedDto, false)).isNotEqualTo(existingDto);
assertThat(eventDefinitionService.get(existingDto.id())).isPresent().get().satisfies(dto -> {
assertThat(dto.id()).isEqualTo(existingDto.id());
assertThat(dto.title()).isEqualTo(newTitle);
assertThat(dto.description()).isEqualTo(newDescription);
});
assertThat(jobDefinitionService.get("54e3deadbeefdeadbeef0001")).isNotPresent();
assertThat(jobTriggerService.get("54e3deadbeefdeadbeef0002")).isNotPresent();
}
use of org.graylog.events.TestEventProcessorConfig in project graylog2-server by Graylog2.
the class EventDefinitionHandlerTest method update.
@Test
@MongoDBFixtures("event-processors.json")
public void update() {
final String newTitle = "A NEW TITLE " + DateTime.now(DateTimeZone.UTC).toString();
final String newDescription = "A NEW DESCRIPTION " + DateTime.now(DateTimeZone.UTC).toString();
final EventDefinitionDto existingDto = eventDefinitionService.get("54e3deadbeefdeadbeef0000").orElse(null);
final JobDefinitionDto existingJobDefinition = jobDefinitionService.get("54e3deadbeefdeadbeef0001").orElse(null);
final JobTriggerDto existingTrigger = jobTriggerService.get("54e3deadbeefdeadbeef0002").orElse(null);
final TestEventProcessorConfig existingConfig = (TestEventProcessorConfig) existingDto.config();
final TestEventProcessorConfig newConfig = existingConfig.toBuilder().executeEveryMs(550000).searchWithinMs(800000).build();
final EventProcessorExecutionJob.Data existingTriggerData = (EventProcessorExecutionJob.Data) existingTrigger.data().orElseThrow(AssertionError::new);
assertThat(existingDto).isNotNull();
assertThat(existingJobDefinition).isNotNull();
assertThat(existingTrigger).isNotNull();
final EventDefinitionDto updatedDto = existingDto.toBuilder().title(newTitle).description(newDescription).config(newConfig).build();
assertThat(handler.update(updatedDto, true)).isNotEqualTo(existingDto);
assertThat(eventDefinitionService.get(existingDto.id())).isPresent().get().satisfies(dto -> {
assertThat(dto.id()).isEqualTo(existingDto.id());
assertThat(dto.title()).isEqualTo(newTitle);
assertThat(dto.description()).isEqualTo(newDescription);
});
// Test that the schedule is updated to the new config
final JobDefinitionDto newJobDefinition = jobDefinitionService.get("54e3deadbeefdeadbeef0001").orElseThrow(AssertionError::new);
assertThat(newJobDefinition.title()).isEqualTo(newTitle);
assertThat(newJobDefinition.description()).isEqualTo(newDescription);
assertThat(((EventProcessorExecutionJob.Config) newJobDefinition.config()).processingHopSize()).isEqualTo(550000);
assertThat(((EventProcessorExecutionJob.Config) newJobDefinition.config()).processingWindowSize()).isEqualTo(800000);
// Test if the EventDefinition update removed the old trigger data
// and reset the job definition timerange to the new parameters
final EventProcessorExecutionJob.Config newJobConfig = (EventProcessorExecutionJob.Config) newJobDefinition.config();
final TimeRange newTimeRange = newJobConfig.parameters().timerange();
assertThat(newTimeRange.getFrom()).isEqualTo(clock.nowUTC().minus(newConfig.searchWithinMs()));
assertThat(newTimeRange.getTo()).isEqualTo(clock.nowUTC());
assertThat(jobTriggerService.get("54e3deadbeefdeadbeef0002")).isPresent().get().satisfies(trigger -> {
assertThat(trigger.data()).isEmpty();
assertThat(trigger.nextTime()).isEqualTo(clock.nowUTC());
});
}
use of org.graylog.events.TestEventProcessorConfig in project graylog2-server by Graylog2.
the class EventDefinitionHandlerTest method updateWithSchedulingReEnabled.
@Test
@MongoDBFixtures("event-processors-without-schedule.json")
public void updateWithSchedulingReEnabled() {
final String newTitle = "A NEW TITLE " + DateTime.now(DateTimeZone.UTC).toString();
final String newDescription = "A NEW DESCRIPTION " + DateTime.now(DateTimeZone.UTC).toString();
final EventDefinitionDto existingDto = eventDefinitionService.get("54e3deadbeefdeadbeef0000").orElse(null);
final TestEventProcessorConfig existingConfig = (TestEventProcessorConfig) existingDto.config();
final TestEventProcessorConfig newConfig = existingConfig.toBuilder().executeEveryMs(550000).searchWithinMs(800000).build();
assertThat(existingDto).isNotNull();
final EventDefinitionDto updatedDto = existingDto.toBuilder().title(newTitle).description(newDescription).config(newConfig).build();
assertThat(handler.update(updatedDto, true)).isNotEqualTo(existingDto);
assertThat(eventDefinitionService.get(existingDto.id())).isPresent().get().satisfies(dto -> {
assertThat(dto.id()).isEqualTo(existingDto.id());
assertThat(dto.title()).isEqualTo(newTitle);
assertThat(dto.description()).isEqualTo(newDescription);
});
final JobDefinitionDto newJobDefinition = jobDefinitionService.getByConfigField("event_definition_id", existingDto.id()).orElseThrow(AssertionError::new);
assertThat(newJobDefinition.title()).isEqualTo(newTitle);
assertThat(newJobDefinition.description()).isEqualTo(newDescription);
assertThat(((EventProcessorExecutionJob.Config) newJobDefinition.config()).processingHopSize()).isEqualTo(550000);
assertThat(jobTriggerService.getForJob(newJobDefinition.id()).get(0)).satisfies(trigger -> {
final IntervalJobSchedule schedule = (IntervalJobSchedule) trigger.schedule();
assertThat(schedule.interval()).isEqualTo(550000);
});
}
use of org.graylog.events.TestEventProcessorConfig in project graylog2-server by Graylog2.
the class DBEventProcessorServiceTest method loadPersisted.
@Test
@MongoDBFixtures("event-processors.json")
public void loadPersisted() {
final List<EventDefinitionDto> dtos = dbService.streamAll().collect(Collectors.toList());
assertThat(dtos).hasSize(1);
assertThat(dtos.get(0)).satisfies(dto -> {
assertThat(dto.id()).isNotBlank();
assertThat(dto.title()).isEqualTo("Test");
assertThat(dto.description()).isEqualTo("A test event definition");
assertThat(dto.priority()).isEqualTo(2);
assertThat(dto.keySpec()).isEqualTo(ImmutableList.of("username"));
assertThat(dto.fieldSpec()).isEmpty();
assertThat(dto.notifications()).isEmpty();
assertThat(dto.storage()).hasSize(1);
assertThat(dto.config()).isInstanceOf(TestEventProcessorConfig.class);
assertThat(dto.config()).satisfies(abstractConfig -> {
final TestEventProcessorConfig config = (TestEventProcessorConfig) abstractConfig;
assertThat(config.type()).isEqualTo("__test_event_processor_config__");
assertThat(config.message()).isEqualTo("This is a test event processor");
});
});
}
Aggregations