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));
}
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);
}
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();
}
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));
}
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);
}
Aggregations