Search in sources :

Example 6 with JobSchedulerTestClock

use of org.graylog.events.JobSchedulerTestClock in project graylog2-server by Graylog2.

the class AggregationEventProcessorConfigTest 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(TemplateFieldValueProvider.Config.class, TemplateFieldValueProvider.Config.TYPE_NAME));
    objectMapper.registerSubtypes(new NamedType(PersistToStreamsStorageHandler.Config.class, PersistToStreamsStorageHandler.Config.TYPE_NAME));
    final MongoJackObjectMapperProvider mapperProvider = new MongoJackObjectMapperProvider(objectMapper);
    this.dbService = new DBEventDefinitionService(mongodb.mongoConnection(), mapperProvider, stateService, mock(EntityOwnershipService.class));
    this.clock = new JobSchedulerTestClock(DateTime.now(DateTimeZone.UTC));
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) DBEventDefinitionService(org.graylog.events.processor.DBEventDefinitionService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Before(org.junit.Before)

Example 7 with JobSchedulerTestClock

use of org.graylog.events.JobSchedulerTestClock in project graylog2-server by Graylog2.

the class DBProcessingStatusServiceTest method setUp.

@Before
public void setUp() throws Exception {
    when(nodeId.toString()).thenReturn(NODE_ID);
    final ObjectMapper objectMapper = new ObjectMapperProvider().get();
    final MongoJackObjectMapperProvider mapperProvider = new MongoJackObjectMapperProvider(objectMapper);
    clock = spy(new JobSchedulerTestClock(DateTime.parse("2019-01-01T00:00:00.000Z")));
    updateThreshold = spy(Duration.minutes(1));
    dbService = new DBProcessingStatusService(mongodb.mongoConnection(), nodeId, clock, updateThreshold, 1, mapperProvider, baseConfiguration);
    db = JacksonDBCollection.wrap(mongodb.mongoConnection().getDatabase().getCollection(DBProcessingStatusService.COLLECTION_NAME), ProcessingStatusDto.class, ObjectId.class, mapperProvider.get());
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) ObjectId(org.bson.types.ObjectId) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Before(org.junit.Before)

Example 8 with JobSchedulerTestClock

use of org.graylog.events.JobSchedulerTestClock in project graylog2-server by Graylog2.

the class EventProcessorExecutionJobTest method setUp.

@Before
public void setUp() {
    clock = new JobSchedulerTestClock(DateTime.parse("2019-01-01T00:00:00.000Z"));
    jobScheduleStrategies = new JobScheduleStrategies(clock);
    when(eventsConfigurationProvider.get()).thenReturn(EventsConfiguration.builder().build());
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) JobScheduleStrategies(org.graylog.scheduler.JobScheduleStrategies) Before(org.junit.Before)

Example 9 with JobSchedulerTestClock

use of org.graylog.events.JobSchedulerTestClock in project graylog2-server by Graylog2.

the class JobTriggerUpdatesTest 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)

Example 10 with JobSchedulerTestClock

use of org.graylog.events.JobSchedulerTestClock in project graylog2-server by Graylog2.

the class CreateJobTriggerRequestTest method toDto.

@Test
public void toDto() {
    final DateTime now = DateTime.now(UTC);
    final JobSchedulerTestClock clock = new JobSchedulerTestClock(now);
    final IntervalJobSchedule schedule = IntervalJobSchedule.builder().interval(1).unit(TimeUnit.SECONDS).build();
    final CreateJobTriggerRequest request = CreateJobTriggerRequest.builder().jobDefinitionId("abc-123").startTime(now).nextTime(now).schedule(schedule).build();
    final JobTriggerData.FallbackData data = new JobTriggerData.FallbackData();
    final CreateJobTriggerRequest requestWithDataAndEndTime = CreateJobTriggerRequest.builder().jobDefinitionId("abc-123").startTime(now).endTime(now.plusDays(1)).nextTime(now).schedule(schedule).data(data).build();
    assertThat(request.toDto(clock)).satisfies(dto -> {
        assertThat(dto.jobDefinitionId()).isEqualTo("abc-123");
        assertThat(dto.startTime()).isEqualTo(now);
        assertThat(dto.endTime()).isNotPresent();
        assertThat(dto.nextTime()).isEqualTo(now);
        assertThat(dto.createdAt()).isEqualTo(now);
        assertThat(dto.updatedAt()).isEqualTo(now);
        assertThat(dto.triggeredAt()).isNotPresent();
        assertThat(dto.status()).isEqualTo(JobTriggerStatus.RUNNABLE);
        assertThat(dto.lock()).isEqualTo(JobTriggerLock.empty());
        assertThat(dto.schedule()).isEqualTo(schedule);
        assertThat(dto.data()).isNotPresent();
    });
    assertThat(requestWithDataAndEndTime.toDto(clock)).satisfies(dto -> {
        assertThat(dto.jobDefinitionId()).isEqualTo("abc-123");
        assertThat(dto.startTime()).isEqualTo(now);
        assertThat(dto.endTime()).isPresent().get().isEqualTo(now.plusDays(1));
        assertThat(dto.nextTime()).isEqualTo(now);
        assertThat(dto.createdAt()).isEqualTo(now);
        assertThat(dto.updatedAt()).isEqualTo(now);
        assertThat(dto.triggeredAt()).isNotPresent();
        assertThat(dto.status()).isEqualTo(JobTriggerStatus.RUNNABLE);
        assertThat(dto.lock()).isEqualTo(JobTriggerLock.empty());
        assertThat(dto.schedule()).isEqualTo(schedule);
        assertThat(dto.data()).isPresent().get().isEqualTo(data);
    });
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) IntervalJobSchedule(org.graylog.scheduler.schedule.IntervalJobSchedule) JobTriggerData(org.graylog.scheduler.JobTriggerData) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

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