Search in sources :

Example 11 with MongoDBFixtures

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

Example 12 with MongoDBFixtures

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");
}
Also used : NotificationDto(org.graylog.events.notifications.NotificationDto) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 13 with MongoDBFixtures

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

Example 14 with MongoDBFixtures

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

Example 15 with MongoDBFixtures

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

Aggregations

MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)167 Test (org.junit.Test)167 Entity (org.graylog2.contentpacks.model.entities.Entity)47 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)47 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)42 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)24 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)23 DateTime (org.joda.time.DateTime)17 ObjectId (org.bson.types.ObjectId)15 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)15 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)11 AbstractMap (java.util.AbstractMap)10 MigrationCompleted (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.V20191203120602_MigrateSavedSearchesToViews.MigrationCompleted)10 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)10 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)10 MongoDBServiceTest (org.graylog2.database.MongoDBServiceTest)10 GRN (org.graylog.grn.GRN)9 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)9 Document (org.bson.Document)8