use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchesIT method scrollReturnsMultipleChunksRespectingLimit.
@Test
public void scrollReturnsMultipleChunksRespectingLimit() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
when(indexSetRegistry.getForIndices(Collections.singleton("graylog_0"))).thenReturn(Collections.singleton(indexSet));
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));
final ScrollResult scrollResult = searches.scroll("*", range, 5, 0, Collections.singletonList("source"), null, 2);
assertThat(scrollResult).isNotNull();
assertThat(scrollResult.totalHits()).isEqualTo(10L);
ScrollResult.ScrollChunk scrollChunk = scrollResult.nextChunk();
assertThat(scrollChunk.isFirstChunk()).isTrue();
final Set<ResultMessage> resultMessages = new HashSet<>(5);
while (scrollChunk != null && !scrollChunk.getMessages().isEmpty()) {
resultMessages.addAll(scrollChunk.getMessages());
scrollChunk = scrollResult.nextChunk();
}
assertThat(resultMessages).hasSize(5);
}
use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchesIT method searchReturnsCorrectTotalHits.
@Test
public void searchReturnsCorrectTotalHits() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
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));
final SearchResult searchResult = searches.search("*", range, 5, 0, Sorting.DEFAULT);
assertThat(searchResult).isNotNull();
assertThat(searchResult.getResults()).hasSize(5);
assertThat(searchResult.getTotalResults()).isEqualTo(10L);
assertThat(searchResult.getFields()).doesNotContain("es_metadata_id", "es_metadata_version");
}
use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchResourceTest method restrictTimeRangeReturnsGivenTimeRangeIfNoLimitHasBeenSet.
@Test
public void restrictTimeRangeReturnsGivenTimeRangeIfNoLimitHasBeenSet() {
when(clusterConfigService.get(SearchesClusterConfig.class)).thenReturn(SearchesClusterConfig.createDefault().toBuilder().queryTimeRangeLimit(Period.ZERO).build());
final SearchResource resource = new SearchResource(searches, clusterConfigService, decoratorProcessor, searchExecutor) {
};
final DateTime from = new DateTime(2015, 1, 15, 12, 0, DateTimeZone.UTC);
final DateTime to = from.plusYears(1);
final TimeRange timeRange = AbsoluteRange.create(from, to);
final TimeRange restrictedTimeRange = resource.restrictTimeRange(timeRange);
assertThat(restrictedTimeRange).isNotNull();
assertThat(restrictedTimeRange.getFrom()).isEqualTo(from);
assertThat(restrictedTimeRange.getTo()).isEqualTo(to);
}
use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchesIT method fieldStatsRecordsMetrics.
@Test
public void fieldStatsRecordsMetrics() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
FieldStatsResult result = searches.fieldStats("n", "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
assertThat(timer.getCount()).isEqualTo(1L);
Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
assertThat(histogram.getCount()).isEqualTo(1L);
assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchesIT method scrollReturnsResultWithSelectiveFields.
@Test
public void scrollReturnsResultWithSelectiveFields() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
when(indexSetRegistry.getForIndices(Collections.singleton("graylog_0"))).thenReturn(Collections.singleton(indexSet));
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));
final ScrollResult scrollResult = searches.scroll("*", range, 5, 0, Collections.singletonList("source"), null, NO_BATCHSIZE);
assertThat(scrollResult).isNotNull();
assertThat(scrollResult.getQueryHash()).isNotEmpty();
assertThat(scrollResult.totalHits()).isEqualTo(10L);
final ScrollResult.ScrollChunk firstChunk = scrollResult.nextChunk();
assertThat(firstChunk).isNotNull();
assertThat(firstChunk.getMessages()).hasSize(5);
assertThat(firstChunk.isFirstChunk()).isTrue();
assertThat(firstChunk.getFields()).containsExactly("source");
}
Aggregations