Search in sources :

Example 11 with AbsoluteRange

use of org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange in project graylog2-server by Graylog2.

the class SearchesTest method testHistogramWithNonExistingIndex.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
@SuppressWarnings("unchecked")
public void testHistogramWithNonExistingIndex() throws Exception {
    final SortedSet<IndexRange> indexRanges = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR).add(MongoIndexRange.create(INDEX_NAME, new DateTime(0L, UTC), new DateTime(2015, 1, 1, 0, 0, UTC), DateTime.now(UTC), 0, null)).add(MongoIndexRange.create("does-not-exist", new DateTime(0L, UTC), new DateTime(2015, 1, 1, 0, 0, UTC), DateTime.now(UTC), 0, null)).build();
    when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(indexRanges);
    final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC).withZone(UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC).withZone(UTC));
    HistogramResult h = searches.histogram("*", Searches.DateHistogramInterval.HOUR, range);
    assertThat(h.getInterval()).isEqualTo(Searches.DateHistogramInterval.HOUR);
    assertThat(h.getHistogramBoundaries()).isEqualTo(range);
    assertThat(h.getResults()).hasSize(5).containsEntry(new DateTime(2015, 1, 1, 1, 0, UTC).getMillis() / 1000L, 2L).containsEntry(new DateTime(2015, 1, 1, 2, 0, UTC).getMillis() / 1000L, 2L).containsEntry(new DateTime(2015, 1, 1, 3, 0, UTC).getMillis() / 1000L, 2L).containsEntry(new DateTime(2015, 1, 1, 4, 0, UTC).getMillis() / 1000L, 2L).containsEntry(new DateTime(2015, 1, 1, 5, 0, UTC).getMillis() / 1000L, 2L);
}
Also used : MongoIndexRange(org.graylog2.indexer.ranges.MongoIndexRange) IndexRange(org.graylog2.indexer.ranges.IndexRange) HistogramResult(org.graylog2.indexer.results.HistogramResult) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 12 with AbsoluteRange

use of org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange in project graylog2-server by Graylog2.

the class SearchesTest method determineAffectedIndicesIncludesDeflectorTarget.

@Test
public void determineAffectedIndicesIncludesDeflectorTarget() throws Exception {
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final MongoIndexRange indexRange0 = MongoIndexRange.create("graylog_0", now, now.plusDays(1), now, 0);
    final MongoIndexRange indexRange1 = MongoIndexRange.create("graylog_1", now.plusDays(1), now.plusDays(2), now, 0);
    final MongoIndexRange indexRangeLatest = MongoIndexRange.create("graylog_2", new DateTime(0L, DateTimeZone.UTC), new DateTime(0L, DateTimeZone.UTC), now, 0);
    final SortedSet<IndexRange> indices = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR).add(indexRange0).add(indexRange1).add(indexRangeLatest).build();
    when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(indices);
    final TimeRange absoluteRange = AbsoluteRange.create(now.minusDays(1), now.plusDays(1));
    final TimeRange keywordRange = KeywordRange.create("1 day ago");
    final TimeRange relativeRange = RelativeRange.create(3600);
    assertThat(searches.determineAffectedIndices(absoluteRange, null)).containsExactlyInAnyOrder(indexRangeLatest.indexName(), indexRange0.indexName(), indexRange1.indexName());
    assertThat(searches.determineAffectedIndices(keywordRange, null)).containsExactlyInAnyOrder(indexRangeLatest.indexName(), indexRange0.indexName(), indexRange1.indexName());
    assertThat(searches.determineAffectedIndices(relativeRange, null)).containsExactlyInAnyOrder(indexRangeLatest.indexName(), indexRange0.indexName(), indexRange1.indexName());
}
Also used : MongoIndexRange(org.graylog2.indexer.ranges.MongoIndexRange) IndexRange(org.graylog2.indexer.ranges.IndexRange) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) MongoIndexRange(org.graylog2.indexer.ranges.MongoIndexRange) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DateTime (org.joda.time.DateTime)11 ZonedDateTime (java.time.ZonedDateTime)10 Test (org.junit.Test)10 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)7 IndexRange (org.graylog2.indexer.ranges.IndexRange)6 MongoIndexRange (org.graylog2.indexer.ranges.MongoIndexRange)6 HistogramResult (org.graylog2.indexer.results.HistogramResult)6 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)5 Histogram (com.codahale.metrics.Histogram)2 Timer (com.codahale.metrics.Timer)2 Map (java.util.Map)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 IndexSet (org.graylog2.indexer.IndexSet)1 InvalidRangeFormatException (org.graylog2.indexer.InvalidRangeFormatException)1 TestIndexSet (org.graylog2.indexer.TestIndexSet)1 CountResult (org.graylog2.indexer.results.CountResult)1 ResultMessage (org.graylog2.indexer.results.ResultMessage)1 SearchResult (org.graylog2.indexer.results.SearchResult)1