Search in sources :

Example 76 with UsingDataSet

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

the class MongoIndexRangeServiceTest method calculateRangeReturnsIndexRange.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void calculateRangeReturnsIndexRange() throws Exception {
    final String index = "graylog";
    final DateTime min = new DateTime(2015, 1, 1, 1, 0, DateTimeZone.UTC);
    final DateTime max = new DateTime(2015, 1, 1, 5, 0, DateTimeZone.UTC);
    when(indices.indexRangeStatsOfIndex(index)).thenReturn(IndexRangeStats.create(min, max));
    final IndexRange indexRange = indexRangeService.calculateRange(index);
    assertThat(indexRange.indexName()).isEqualTo(index);
    assertThat(indexRange.begin()).isEqualTo(min);
    assertThat(indexRange.end()).isEqualTo(max);
    Assertions.assertThat(indexRange.calculatedAt()).isEqualToIgnoringHours(DateTime.now(DateTimeZone.UTC));
}
Also used : DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 77 with UsingDataSet

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

the class MongoIndexRangeServiceTest method saveOverwritesExistingIndexRange.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void saveOverwritesExistingIndexRange() 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 indexRangeBefore = MongoIndexRange.create(indexName, begin, end, now, 1);
    final IndexRange indexRangeAfter = MongoIndexRange.create(indexName, begin, end, now, 2);
    indexRangeService.save(indexRangeBefore);
    final IndexRange before = indexRangeService.get(indexName);
    assertThat(before.calculationDuration()).isEqualTo(1);
    indexRangeService.save(indexRangeAfter);
    final IndexRange after = indexRangeService.get(indexName);
    assertThat(after.calculationDuration()).isEqualTo(2);
}
Also used : DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 78 with UsingDataSet

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

the class MongoIndexRangeServiceTest method testHandleIndexReopeningWhenNotManaged.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
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) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 79 with UsingDataSet

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

the class MongoIndexRangeServiceTest method testCalculateRangeWithEmptyIndex.

@Test
@UsingDataSet(locations = "MongoIndexRangeServiceTest-EmptyCollection.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testCalculateRangeWithEmptyIndex() throws Exception {
    final String index = "graylog";
    when(indices.indexRangeStatsOfIndex(index)).thenReturn(IndexRangeStats.EMPTY);
    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) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 80 with UsingDataSet

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

the class MongoIndexRangeServiceTest method getReturnsExistingIndexRange.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void getReturnsExistingIndexRange() throws Exception {
    IndexRange indexRange = indexRangeService.get("graylog_1");
    assertThat(indexRange.indexName()).isEqualTo("graylog_1");
    assertThat(indexRange.begin()).isEqualTo(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
    assertThat(indexRange.end()).isEqualTo(new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC));
    assertThat(indexRange.calculatedAt()).isEqualTo(new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC));
    assertThat(indexRange.calculationDuration()).isEqualTo(23);
}
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