Search in sources :

Example 1 with JobSchedulerTestClock

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);
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) UserService(org.graylog2.shared.users.UserService) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) AggregationEventProcessorConfig(org.graylog.events.processor.aggregation.AggregationEventProcessorConfig) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) DBEventDefinitionService(org.graylog.events.processor.DBEventDefinitionService) AggregationEventProcessorConfig(org.graylog.events.processor.aggregation.AggregationEventProcessorConfig) NotificationResourceHandler(org.graylog.events.notifications.NotificationResourceHandler) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) AggregationEventProcessorParameters(org.graylog.events.processor.aggregation.AggregationEventProcessorParameters) IntervalJobSchedule(org.graylog.scheduler.schedule.IntervalJobSchedule) DBNotificationService(org.graylog.events.notifications.DBNotificationService) DBJobTriggerService(org.graylog.scheduler.DBJobTriggerService) NodeId(org.graylog2.plugin.system.NodeId) DBJobDefinitionService(org.graylog.scheduler.DBJobDefinitionService) EventDefinitionHandler(org.graylog.events.processor.EventDefinitionHandler) MongoConnection(org.graylog2.database.MongoConnection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 2 with JobSchedulerTestClock

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");
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 3 with JobSchedulerTestClock

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();
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 4 with JobSchedulerTestClock

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"));
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 5 with JobSchedulerTestClock

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);
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) Before(org.junit.Before)

Aggregations

JobSchedulerTestClock (org.graylog.events.JobSchedulerTestClock)11 Before (org.junit.Before)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 MongoJackObjectMapperProvider (org.graylog2.bindings.providers.MongoJackObjectMapperProvider)4 ObjectMapperProvider (org.graylog2.shared.bindings.providers.ObjectMapperProvider)4 Test (org.junit.Test)4 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)3 IntervalJobSchedule (org.graylog.scheduler.schedule.IntervalJobSchedule)3 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)3 DBEventDefinitionService (org.graylog.events.processor.DBEventDefinitionService)2 DBJobDefinitionService (org.graylog.scheduler.DBJobDefinitionService)2 DBJobTriggerService (org.graylog.scheduler.DBJobTriggerService)2 DateTime (org.joda.time.DateTime)2 ObjectId (org.bson.types.ObjectId)1 TestEventProcessorConfig (org.graylog.events.TestEventProcessorConfig)1 TestEventProcessorParameters (org.graylog.events.TestEventProcessorParameters)1 DBNotificationService (org.graylog.events.notifications.DBNotificationService)1 NotificationResourceHandler (org.graylog.events.notifications.NotificationResourceHandler)1 EventDefinitionHandler (org.graylog.events.processor.EventDefinitionHandler)1 AggregationEventProcessorConfig (org.graylog.events.processor.aggregation.AggregationEventProcessorConfig)1