use of org.graylog.events.JobSchedulerTestClock in project graylog2-server by Graylog2.
the class LegacyAlertConditionMigratorTest method setUp.
@Before
public void setUp() throws Exception {
final ObjectMapper objectMapper = new ObjectMapperProvider().get();
objectMapper.registerSubtypes(new NamedType(AggregationEventProcessorConfig.class, AggregationEventProcessorConfig.TYPE_NAME));
objectMapper.registerSubtypes(new NamedType(AggregationEventProcessorParameters.class, AggregationEventProcessorConfig.TYPE_NAME));
objectMapper.registerSubtypes(new NamedType(EventProcessorExecutionJob.Config.class, EventProcessorExecutionJob.TYPE_NAME));
objectMapper.registerSubtypes(new NamedType(EventProcessorExecutionJob.Data.class, EventProcessorExecutionJob.TYPE_NAME));
objectMapper.registerSubtypes(new NamedType(IntervalJobSchedule.class, IntervalJobSchedule.TYPE_NAME));
objectMapper.registerSubtypes(new NamedType(PersistToStreamsStorageHandler.Config.class, PersistToStreamsStorageHandler.Config.TYPE_NAME));
objectMapper.registerSubtypes(new NamedType(PersistToStreamsStorageHandler.Config.class, PersistToStreamsStorageHandler.Config.TYPE_NAME));
objectMapper.registerSubtypes(new NamedType(LegacyAlarmCallbackEventNotificationConfig.class, LegacyAlarmCallbackEventNotificationConfig.TYPE_NAME));
objectMapper.registerSubtypes(new NamedType(EventNotificationExecutionJob.Config.class, EventNotificationExecutionJob.TYPE_NAME));
final MongoJackObjectMapperProvider mongoJackObjectMapperProvider = new MongoJackObjectMapperProvider(objectMapper);
final MongoConnection mongoConnection = mongodb.mongoConnection();
final JobSchedulerTestClock clock = new JobSchedulerTestClock(DateTime.now(DateTimeZone.UTC));
final DBJobDefinitionService jobDefinitionService = new DBJobDefinitionService(mongoConnection, mongoJackObjectMapperProvider);
final DBJobTriggerService jobTriggerService = new DBJobTriggerService(mongoConnection, mongoJackObjectMapperProvider, mock(NodeId.class), clock, Duration.minutes(5));
notificationService = new DBNotificationService(mongoConnection, mongoJackObjectMapperProvider, mock(EntityOwnershipService.class));
this.eventDefinitionService = new DBEventDefinitionService(mongoConnection, mongoJackObjectMapperProvider, mock(DBEventProcessorStateService.class), mock(EntityOwnershipService.class));
this.eventDefinitionHandler = spy(new EventDefinitionHandler(eventDefinitionService, jobDefinitionService, jobTriggerService, clock));
this.notificationResourceHandler = spy(new NotificationResourceHandler(notificationService, jobDefinitionService, eventDefinitionService, eventNotificationFactories));
this.userService = mock(UserService.class);
when(userService.getRootUser()).thenReturn(Optional.empty());
this.migrator = new LegacyAlertConditionMigrator(mongoConnection, eventDefinitionHandler, notificationResourceHandler, notificationService, userService, CHECK_INTERVAL);
}
use of org.graylog.events.JobSchedulerTestClock 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.events.JobSchedulerTestClock 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.events.JobSchedulerTestClock 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"));
}
use of org.graylog.events.JobSchedulerTestClock in project graylog2-server by Graylog2.
the class JobScheduleStrategiesTest method setUp.
@Before
public void setUp() throws Exception {
this.clock = new JobSchedulerTestClock(DateTime.now(DateTimeZone.UTC));
this.strategies = new JobScheduleStrategies(clock);
}
Aggregations