use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchesIT method testCountWithFilter.
@Test
public void testCountWithFilter() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
final IndexSetConfig indexSetConfig = IndexSetConfig.builder().id("id").title("title").indexPrefix("prefix").shards(1).replicas(0).rotationStrategy(MessageCountRotationStrategyConfig.createDefault()).retentionStrategyClass(DeletionRetentionStrategy.class.getCanonicalName()).retentionStrategy(DeletionRetentionStrategyConfig.createDefault()).creationDate(ZonedDateTime.of(2017, 5, 24, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
final IndexSet indexSet = new TestIndexSet(indexSetConfig);
final Stream stream = new FakeStream("test") {
@Override
public IndexSet getIndexSet() {
return indexSet;
}
};
when(streamService.load(STREAM_ID)).thenReturn(stream);
CountResult result = searches.count("*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)), "streams:" + STREAM_ID);
assertThat(result.count()).isEqualTo(5L);
}
use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchesIT method testCountWithInvalidFilter.
@Test
public void testCountWithInvalidFilter() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
CountResult result = searches.count("*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)), "foobar-not-a-filter");
assertThat(result.count()).isEqualTo(0L);
}
use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchesIT method testCountWithoutFilter.
@Test
public void testCountWithoutFilter() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
CountResult result = searches.count("*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
assertThat(result.count()).isEqualTo(10L);
}
use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchesIT method scrollReturnsMultipleChunksRespectingBatchSize.
@Test
public void scrollReturnsMultipleChunksRespectingBatchSize() 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, -1, 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()) {
assertThat(scrollChunk.getMessages()).hasSize(2);
assertThat(scrollChunk.getFields()).containsExactly("source");
resultMessages.addAll(scrollChunk.getMessages());
scrollChunk = scrollResult.nextChunk();
}
assertThat(resultMessages).hasSize(10);
}
use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.
the class SearchesIT method countRecordsMetrics.
@Test
public void countRecordsMetrics() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
CountResult result = searches.count("*", 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);
}
Aggregations