Search in sources :

Example 21 with UsingDataSet

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

the class ClusterEventPeriodicalTest method testPublishClusterEvent.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testPublishClusterEvent() throws Exception {
    DBCollection collection = mongoConnection.getDatabase().getCollection(ClusterEventPeriodical.COLLECTION_NAME);
    SimpleEvent event = new SimpleEvent("test");
    assertThat(collection.count()).isEqualTo(0L);
    clusterEventPeriodical.publishClusterEvent(event);
    verify(clusterEventBus, never()).post(any());
    assertThat(collection.count()).isEqualTo(1L);
    DBObject dbObject = collection.findOne();
    assertThat((String) dbObject.get("producer")).isEqualTo(nodeId.toString());
    assertThat((String) dbObject.get("event_class")).isEqualTo(SimpleEvent.class.getCanonicalName());
    @SuppressWarnings("unchecked") Map<String, Object> payload = (Map<String, Object>) dbObject.get("payload");
    assertThat(payload).containsEntry("payload", "test");
}
Also used : DBCollection(com.mongodb.DBCollection) DBObject(com.mongodb.DBObject) DBObject(com.mongodb.DBObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 22 with UsingDataSet

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

the class ClusterEventPeriodicalTest method serverEventBusDispatchesTypedEvents.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void serverEventBusDispatchesTypedEvents() throws Exception {
    final SimpleEventHandler handler = new SimpleEventHandler();
    serverEventBus.register(handler);
    DBObject event = new BasicDBObjectBuilder().add("timestamp", TIME.getMillis()).add("producer", "TEST-PRODUCER").add("consumers", Collections.emptyList()).add("event_class", SimpleEvent.class.getCanonicalName()).add("payload", ImmutableMap.of("payload", "test")).get();
    final DBCollection collection = mongoConnection.getDatabase().getCollection(ClusterEventPeriodical.COLLECTION_NAME);
    assertThat(collection.save(event).getN()).isEqualTo(1);
    assertThat(collection.count()).isEqualTo(1L);
    assertThat(handler.invocations).isEqualTo(0);
    clusterEventPeriodical.run();
    assertThat(handler.invocations).isEqualTo(1);
    assertThat(collection.count()).isEqualTo(1L);
    @SuppressWarnings("unchecked") final List<String> consumers = (List<String>) collection.findOne().get("consumers");
    assertThat(consumers).containsExactly(nodeId.toString());
    verify(serverEventBus, times(1)).post(any(SimpleEvent.class));
    verify(clusterEventBus, never()).post(any());
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) List(java.util.List) DBObject(com.mongodb.DBObject) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 23 with UsingDataSet

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

the class FilterServiceImplTest method testProperDeserializationOfSubclasses.

@Test
@UsingDataSet(locations = "properDeserializationOfSubclasses.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testProperDeserializationOfSubclasses() throws Exception {
    final Set<FilterDescription> filterDescriptionSet = filterService.loadAll();
    assertThat(filterDescriptionSet).isNotNull().hasSize(1);
    final FilterDescription filterDescription = filterDescriptionSet.iterator().next();
    assertThat(filterDescription).isNotNull();
    assertThat(filterDescription).isInstanceOf(BlacklistPatternCondition.class);
}
Also used : FilterDescription(org.graylog2.filters.blacklist.FilterDescription) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 24 with UsingDataSet

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

the class MongoIndexRangeServiceTest method findReturnsIndexRangesWithinGivenRange.

/**
     * Test the following constellation:
     * <pre>
     *                        [-        index range       -]
     * [- graylog_1 -][- graylog_2 -][- graylog_3 -][- graylog_4 -][- graylog_5 -]
     * </pre>
     */
@Test
@UsingDataSet(locations = "MongoIndexRangeServiceTest-distinct.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void findReturnsIndexRangesWithinGivenRange() throws Exception {
    final DateTime begin = new DateTime(2015, 1, 2, 12, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2015, 1, 4, 12, 0, DateTimeZone.UTC);
    final SortedSet<IndexRange> indexRanges = indexRangeService.find(begin, end);
    assertThat(indexRanges).containsExactly(MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000002"), "graylog_2", new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 3, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 3, 0, 0, DateTimeZone.UTC), 42), MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000003"), "graylog_3", new DateTime(2015, 1, 3, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 4, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 4, 0, 0, DateTimeZone.UTC), 42), MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000004"), "graylog_4", new DateTime(2015, 1, 4, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 5, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 5, 0, 0, DateTimeZone.UTC), 42));
}
Also used : ObjectId(org.bson.types.ObjectId) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 25 with UsingDataSet

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

the class MongoIndexRangeServiceTest method savePersistsIndexRange.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void savePersistsIndexRange() throws Exception {
    final String indexName = "graylog";
    final DateTime begin = new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC);
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final IndexRange indexRange = MongoIndexRange.create(indexName, begin, end, now, 42);
    indexRangeService.save(indexRange);
    final IndexRange result = indexRangeService.get(indexName);
    assertThat(result.indexName()).isEqualTo(indexName);
    assertThat(result.begin()).isEqualTo(begin);
    assertThat(result.end()).isEqualTo(end);
    assertThat(result.calculatedAt()).isEqualTo(now);
    assertThat(result.calculationDuration()).isEqualTo(42);
}
Also used : DateTime(org.joda.time.DateTime) 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