use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class EventDefinitionHandlerTest method schedule.
@Test
@MongoDBFixtures("event-processors-without-schedule.json")
public void schedule() {
assertThat(eventDefinitionService.get("54e3deadbeefdeadbeef0000")).isPresent();
assertThat(jobDefinitionService.streamAll().count()).isEqualTo(0);
assertThat(jobTriggerService.all()).isEmpty();
handler.schedule("54e3deadbeefdeadbeef0000");
assertThat(eventDefinitionService.get("54e3deadbeefdeadbeef0000")).isPresent();
assertThat(jobDefinitionService.getByConfigField("event_definition_id", "54e3deadbeefdeadbeef0000")).get().satisfies(definition -> {
assertThat(definition.title()).isEqualTo("Test");
assertThat(definition.description()).isEqualTo("A test event definition");
assertThat(definition.config()).isInstanceOf(EventProcessorExecutionJob.Config.class);
final EventProcessorExecutionJob.Config config = (EventProcessorExecutionJob.Config) definition.config();
assertThat(config.processingWindowSize()).isEqualTo(300000);
assertThat(config.processingHopSize()).isEqualTo(60000);
assertThat(jobTriggerService.nextRunnableTrigger()).get().satisfies(trigger -> {
assertThat(trigger.jobDefinitionId()).isEqualTo(definition.id());
assertThat(trigger.schedule()).isInstanceOf(IntervalJobSchedule.class);
final IntervalJobSchedule schedule = (IntervalJobSchedule) trigger.schedule();
assertThat(schedule.interval()).isEqualTo(60000);
assertThat(schedule.unit()).isEqualTo(TimeUnit.MILLISECONDS);
});
});
assertThat(jobDefinitionService.get("54e3deadbeefdeadbeef0001")).isNotPresent();
assertThat(jobTriggerService.get("54e3deadbeefdeadbeef0002")).isNotPresent();
}
use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class NotificationFacadeTest method loadNativeEntity.
@Test
@MongoDBFixtures("NotificationFacadeTest.json")
public void loadNativeEntity() {
final NativeEntityDescriptor nativeEntityDescriptor = NativeEntityDescriptor.create(ModelId.of("content-pack-id"), ModelId.of("5d4d33753d27460ad18e0c4d"), ModelTypes.NOTIFICATION_V1, "title");
final Optional<NativeEntity<NotificationDto>> optionalNativeEntity = facade.loadNativeEntity(nativeEntityDescriptor);
assertThat(optionalNativeEntity).isPresent();
final NativeEntity<NotificationDto> nativeEntity = optionalNativeEntity.get();
assertThat(nativeEntity.entity()).isNotNull();
final NotificationDto notificationDto = nativeEntity.entity();
assertThat(notificationDto.id()).isEqualTo("5d4d33753d27460ad18e0c4d");
}
use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class DBJobTriggerServiceTest method updateLockedJobTriggers.
@Test
@MongoDBFixtures("locked-job-triggers.json")
public void updateLockedJobTriggers() {
DateTime newLockTime = DateTime.parse("2019-01-01T02:00:00.000Z");
final JobSchedulerTestClock clock = new JobSchedulerTestClock(newLockTime);
final DBJobTriggerService service = new DBJobTriggerService(mongodb.mongoConnection(), mapperProvider, nodeId, clock, EXPIRATION_DURATION);
service.updateLockedJobTriggers();
List<String> updatedJobTriggerIds = service.all().stream().filter(jobTriggerDto -> newLockTime.equals(jobTriggerDto.lock().lastLockTime())).map(JobTriggerDto::id).collect(Collectors.toList());
assertThat(updatedJobTriggerIds).containsOnly("54e3deadbeefdeadbeef0001", "54e3deadbeefdeadbeef0002");
}
use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class DBJobTriggerServiceTest method nextRunnableTriggerWithEndTime.
@Test
@MongoDBFixtures("job-triggers.json")
public void nextRunnableTriggerWithEndTime() {
// Set clock to base date used in the fixture file
final JobSchedulerTestClock clock = new JobSchedulerTestClock(DateTime.parse("2019-01-01T00:00:00.000Z"));
final DBJobTriggerService service = new DBJobTriggerService(mongodb.mongoConnection(), mapperProvider, nodeId, clock, EXPIRATION_DURATION);
// No triggers yet because 54e3deadbeefdeadbeef0002 is already locked and RUNNING
assertThat(service.nextRunnableTrigger()).isEmpty();
// Advancing the clock a bit
clock.plus(2, TimeUnit.HOURS);
// Now we should get trigger 54e3deadbeefdeadbeef0000
assertThat(service.nextRunnableTrigger()).isNotEmpty().get().satisfies(trigger -> assertThat(trigger.id()).isEqualTo("54e3deadbeefdeadbeef0000"));
// No more runnable triggers now
assertThat(service.nextRunnableTrigger()).isEmpty();
// Advancing clock far into the future, past the endTime of trigger 54e3deadbeefdeadbeef0001
clock.plus(40, TimeUnit.DAYS);
// We shouldn't get trigger 54e3deadbeefdeadbeef0001 because of its endTime
assertThat(service.nextRunnableTrigger()).isEmpty();
}
use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class DBJobTriggerServiceTest method nextStaleTrigger.
@Test
@MongoDBFixtures("stale-job-triggers-with-expired-lock.json")
public void nextStaleTrigger() {
final JobSchedulerTestClock clock = new JobSchedulerTestClock(DateTime.parse("2019-01-01T02:00:00.000Z"));
final DBJobTriggerService service = new DBJobTriggerService(mongodb.mongoConnection(), mapperProvider, nodeId, clock, EXPIRATION_DURATION);
assertThat(service.nextRunnableTrigger()).isNotEmpty().get().satisfies(trigger -> assertThat(trigger.id()).isEqualTo("54e3deadbeefdeadbeef0002"));
}
Aggregations