Search in sources :

Example 91 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class MongoIndexRangeServiceTest method findReturnsNothingBeforeBegin.

@Test
@MongoDBFixtures("MongoIndexRangeServiceTest.json")
public void findReturnsNothingBeforeBegin() throws Exception {
    final DateTime begin = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2016, 1, 2, 0, 0, DateTimeZone.UTC);
    Set<IndexRange> indexRanges = indexRangeService.find(begin, end);
    assertThat(indexRanges).isEmpty();
}
Also used : DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 92 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class MongoIndexRangeServiceTest method testCalculateRangeWithEmptyIndex.

@Test
@MongoDBFixtures("MongoIndexRangeServiceTest-EmptyCollection.json")
public void testCalculateRangeWithEmptyIndex() throws Exception {
    final String index = "graylog";
    when(indices.indexRangeStatsOfIndex(index)).thenReturn(IndexRangeStats.EMPTY);
    when(indices.waitForRecovery(index)).thenReturn(HealthStatus.Green);
    final IndexRange range = indexRangeService.calculateRange(index);
    assertThat(range).isNotNull();
    assertThat(range.indexName()).isEqualTo(index);
    assertThat(range.begin()).isEqualTo(new DateTime(0L, DateTimeZone.UTC));
    assertThat(range.end()).isEqualTo(new DateTime(0L, DateTimeZone.UTC));
}
Also used : DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 93 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class MongoIndexRangeServiceTest method testHandleIndexReopeningWhenNotManaged.

@Test
@MongoDBFixtures("MongoIndexRangeServiceTest.json")
public void testHandleIndexReopeningWhenNotManaged() throws Exception {
    final DateTime begin = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2016, 1, 15, 0, 0, DateTimeZone.UTC);
    when(indexSetRegistry.isManagedIndex("graylog_3")).thenReturn(false);
    when(indices.indexRangeStatsOfIndex("graylog_3")).thenReturn(IndexRangeStats.EMPTY);
    localEventBus.post(IndicesReopenedEvent.create(Collections.singleton("graylog_3")));
    final SortedSet<IndexRange> indexRanges = indexRangeService.find(begin, end);
    assertThat(indexRanges).isEmpty();
}
Also used : DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 94 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class MongoIndexRangeServiceTest method testHandleIndexReopening.

@Test
@MongoDBFixtures("MongoIndexRangeServiceTest.json")
public void testHandleIndexReopening() throws Exception {
    final DateTime begin = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2016, 1, 15, 0, 0, DateTimeZone.UTC);
    when(indices.indexRangeStatsOfIndex("graylog_3")).thenReturn(IndexRangeStats.create(begin, end));
    when(indexSetRegistry.isManagedIndex("graylog_3")).thenReturn(true);
    when(indices.waitForRecovery("graylog_3")).thenReturn(HealthStatus.Green);
    localEventBus.post(IndicesReopenedEvent.create(Collections.singleton("graylog_3")));
    final SortedSet<IndexRange> indexRanges = indexRangeService.find(begin, end);
    assertThat(indexRanges).hasSize(1);
    assertThat(indexRanges.first().indexName()).isEqualTo("graylog_3");
    assertThat(indexRanges.first().begin()).isEqualTo(begin);
    assertThat(indexRanges.first().end()).isEqualTo(end);
}
Also used : DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 95 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class MongoInputStatusServiceTest method handleDeleteEvent_WhenStoppingInputDoesNothing.

@Test
@MongoDBFixtures("input-status.json")
public void handleDeleteEvent_WhenStoppingInputDoesNothing() throws Exception {
    final String deletedInput = "54e3deadbeefdeadbeef0001";
    final InputDeleted inputDeletedEvent = new InputDeleted() {

        @Override
        public String id() {
            return deletedInput;
        }
    };
    cut.handleInputDeleted(inputDeletedEvent);
    // The record should not be removed from the DB
    assertThat(cut.get(deletedInput).isPresent(), is(true));
}
Also used : InputDeleted(org.graylog2.rest.models.system.inputs.responses.InputDeleted) 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