Search in sources :

Example 1 with OffsetRange

use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.

the class OffsetRangeTest method returnsCorrectRangeForTimeRangeOfQuery.

@Test
public void returnsCorrectRangeForTimeRangeOfQuery() throws Exception {
    final OffsetRange offsetRange = constructRange("300", "query", "");
    final TimeRange sourceRange = mock(TimeRange.class);
    when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
    when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
    final Query query = queryWithTimeRange(sourceRange);
    final TimeRange result = offsetRange.deriveTimeRange(query, null);
    assertThat(result).isEqualTo(AbsoluteRange.create("2019-11-18T09:55:00.000Z", "2019-11-21T11:55:00.000Z"));
}
Also used : OffsetRange(org.graylog.plugins.views.search.timeranges.OffsetRange) DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Query(org.graylog.plugins.views.search.Query) Test(org.junit.Test)

Example 2 with OffsetRange

use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.

the class OffsetRangeTest method returnsCorrectRangeWithZeroUnitOffset.

@Test
public void returnsCorrectRangeWithZeroUnitOffset() throws Exception {
    final OffsetRange offsetRange = constructRange("0i", "search_type", "searchTypeId");
    final TimeRange sourceRange = mock(TimeRange.class);
    when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
    when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
    final Query query = queryWithSearchTypeTimeRange(sourceRange, "searchTypeId");
    final TimeRange result = offsetRange.deriveTimeRange(query, null);
    assertThat(result).isEqualTo(AbsoluteRange.create("2019-11-18T10:00:00.000Z", "2019-11-21T12:00:00.000Z"));
}
Also used : OffsetRange(org.graylog.plugins.views.search.timeranges.OffsetRange) DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Query(org.graylog.plugins.views.search.Query) Test(org.junit.Test)

Example 3 with OffsetRange

use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.

the class OffsetRangeTest method throwsExceptionIfInvalidSearchTypeIsReferenced.

@Test
public void throwsExceptionIfInvalidSearchTypeIsReferenced() throws Exception {
    final OffsetRange offsetRange = constructRange("300", "search_type", "invalidSearchType");
    final TimeRange sourceRange = mock(TimeRange.class);
    when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
    when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
    final Query query = mock(Query.class);
    final SearchType searchType = mock(SearchType.class);
    when(searchType.id()).thenReturn("searchTypeId");
    when(searchType.timerange()).thenReturn(Optional.of(DerivedTimeRange.of(sourceRange)));
    when(query.searchTypes()).thenReturn(ImmutableSet.of(searchType));
    when(query.effectiveTimeRange(searchType)).thenReturn(sourceRange);
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> offsetRange.deriveTimeRange(query, searchType)).withMessage("Search type searchTypeId has offset timerange referencing invalid search type: invalidSearchType");
}
Also used : OffsetRange(org.graylog.plugins.views.search.timeranges.OffsetRange) DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Query(org.graylog.plugins.views.search.Query) SearchType(org.graylog.plugins.views.search.SearchType) Test(org.junit.Test)

Example 4 with OffsetRange

use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.

the class OffsetRangeTest method returnsCorrectRangeForTimeRangeOfQueryWithOffsetInUnits.

@Test
public void returnsCorrectRangeForTimeRangeOfQueryWithOffsetInUnits() throws Exception {
    final OffsetRange offsetRange = constructRange("3i", "query", "");
    final TimeRange sourceRange = mock(TimeRange.class);
    when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
    when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
    final Query query = queryWithTimeRange(sourceRange);
    final TimeRange result = offsetRange.deriveTimeRange(query, null);
    assertThat(result).isEqualTo(AbsoluteRange.create("2019-11-09T04:00:00.000Z", "2019-11-12T06:00:00.000Z"));
}
Also used : OffsetRange(org.graylog.plugins.views.search.timeranges.OffsetRange) DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Query(org.graylog.plugins.views.search.Query) Test(org.junit.Test)

Example 5 with OffsetRange

use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.

the class OffsetRangeTest method throwsExceptionIfNoSearchTypeIsReferenced.

@Test
public void throwsExceptionIfNoSearchTypeIsReferenced() throws Exception {
    final OffsetRange offsetRange = constructRange("300", "search_type", null);
    final TimeRange sourceRange = mock(TimeRange.class);
    when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
    when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
    final Query query = mock(Query.class);
    final SearchType searchType = mock(SearchType.class);
    when(searchType.id()).thenReturn("searchTypeId");
    when(searchType.timerange()).thenReturn(Optional.of(DerivedTimeRange.of(sourceRange)));
    when(query.searchTypes()).thenReturn(ImmutableSet.of(searchType));
    when(query.effectiveTimeRange(searchType)).thenReturn(sourceRange);
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> offsetRange.deriveTimeRange(query, searchType)).withMessage("Search type searchTypeId has offset timerange referencing search type but id is missing!");
}
Also used : OffsetRange(org.graylog.plugins.views.search.timeranges.OffsetRange) DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Query(org.graylog.plugins.views.search.Query) SearchType(org.graylog.plugins.views.search.SearchType) Test(org.junit.Test)

Aggregations

Query (org.graylog.plugins.views.search.Query)7 DerivedTimeRange (org.graylog.plugins.views.search.timeranges.DerivedTimeRange)7 OffsetRange (org.graylog.plugins.views.search.timeranges.OffsetRange)7 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)7 Test (org.junit.Test)7 SearchType (org.graylog.plugins.views.search.SearchType)2