Search in sources :

Example 66 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class LegacyMongoIndexRangeServiceTest method testGetIncompleteIndexRange.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testGetIncompleteIndexRange() throws Exception {
    final IndexRange indexRange = indexRangeService.get("graylog_99");
    final DateTime end = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
    final IndexRange expected = MongoIndexRange.create(new ObjectId("56250da2d400000000000099"), "graylog_99", EPOCH, end, EPOCH, 0);
    assertThat(indexRange).isEqualTo(expected);
}
Also used : ObjectId(org.bson.types.ObjectId) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 67 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class MongoIndexSetServiceTest method deleteWithAssignedStreams.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void deleteWithAssignedStreams() throws Exception {
    final IndexSetDeletedSubscriber subscriber = new IndexSetDeletedSubscriber();
    clusterEventBus.registerClusterEventSubscriber(subscriber);
    final FakeStream stream1 = new FakeStream("Test stream 1");
    final String streamId = "57f3d721a43c2d59cb750001";
    stream1.setIndexSetId(streamId);
    when(streamService.loadAllWithIndexSet(streamId)).thenReturn(Collections.singletonList(stream1));
    final int deletedEntries = indexSetService.delete(streamId);
    assertThat(deletedEntries).isEqualTo(0);
    assertThat(indexSetService.get(streamId)).isPresent();
    assertThat(indexSetService.findAll()).hasSize(2);
    assertThat(subscriber.getEvents()).isEmpty();
}
Also used : FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 68 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class MongoIndexSetServiceTest method getReturnsExistingIndexSetConfig.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void getReturnsExistingIndexSetConfig() throws Exception {
    final Optional<IndexSetConfig> indexSetConfig = indexSetService.get(new ObjectId("57f3d721a43c2d59cb750001"));
    assertThat(indexSetConfig).isPresent().contains(IndexSetConfig.create("57f3d721a43c2d59cb750001", "Test 1", "This is the index set configuration for Test 1", true, "test_1", 4, 1, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(10), ZonedDateTime.of(2016, 10, 4, 17, 0, 0, 0, ZoneOffset.UTC), "standard", "test_1", 1, false));
}
Also used : ObjectId(org.bson.types.ObjectId) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 69 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class ClusterEventCleanupPeriodicalTest method testDoRun.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testDoRun() throws Exception {
    final DBCollection collection = mongoConnection.getDatabase().getCollection(ClusterEventPeriodical.COLLECTION_NAME);
    assertThat(insertEvent(collection, 0L)).isTrue();
    assertThat(insertEvent(collection, TIME.getMillis())).isTrue();
    assertThat(insertEvent(collection, TIME.minus(ClusterEventCleanupPeriodical.DEFAULT_MAX_EVENT_AGE).getMillis())).isTrue();
    assertThat(insertEvent(collection, TIME.minus(2 * ClusterEventCleanupPeriodical.DEFAULT_MAX_EVENT_AGE).getMillis())).isTrue();
    assertThat(collection.count()).isEqualTo(4L);
    clusterEventCleanupPeriodical.run();
    assertThat(collection.count()).isEqualTo(2L);
}
Also used : DBCollection(com.mongodb.DBCollection) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 70 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class ClusterEventPeriodicalTest method publishClusterEventSkipsDeadEvent.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void publishClusterEventSkipsDeadEvent() throws Exception {
    DBCollection collection = mongoConnection.getDatabase().getCollection(ClusterEventPeriodical.COLLECTION_NAME);
    DeadEvent event = new DeadEvent(clusterEventBus, new SimpleEvent("test"));
    assertThat(collection.count()).isEqualTo(0L);
    clusterEventPeriodical.publishClusterEvent(event);
    verify(clusterEventBus, never()).post(any());
    assertThat(collection.count()).isEqualTo(0L);
}
Also used : DBCollection(com.mongodb.DBCollection) DeadEvent(com.google.common.eventbus.DeadEvent) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)94 Test (org.junit.Test)94 DateTime (org.joda.time.DateTime)40 DBCollection (com.mongodb.DBCollection)29 ZonedDateTime (java.time.ZonedDateTime)19 DBObject (com.mongodb.DBObject)15 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)13 ObjectId (org.bson.types.ObjectId)9 MongoDBServiceTest (org.graylog2.database.MongoDBServiceTest)9 Timer (com.codahale.metrics.Timer)6 Histogram (com.codahale.metrics.Histogram)5 JsonPath (com.jayway.restassured.path.json.JsonPath)5 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)5 HistogramResult (org.graylog2.indexer.results.HistogramResult)5 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)5 List (java.util.List)4 TermsResult (org.graylog2.indexer.results.TermsResult)4 User (org.graylog2.plugin.database.users.User)4 LdapSettings (org.graylog2.shared.security.ldap.LdapSettings)4 Map (java.util.Map)3