Search in sources :

Example 1 with TestIndexSet

use of org.graylog2.indexer.TestIndexSet 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);
}
Also used : TestIndexSet(org.graylog2.indexer.TestIndexSet) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) Stream(org.graylog2.plugin.streams.Stream) CountResult(org.graylog2.indexer.results.CountResult) IndexSet(org.graylog2.indexer.IndexSet) TestIndexSet(org.graylog2.indexer.TestIndexSet) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 2 with TestIndexSet

use of org.graylog2.indexer.TestIndexSet in project graylog2-server by Graylog2.

the class SearchesIT method determineAffectedIndicesWithRangesExcludeEvents.

@Test
public void determineAffectedIndicesWithRangesExcludeEvents() throws Exception {
    final Set<IndexSet> eventIndexSets = Arrays.asList("gl-events", "gl-system-events").stream().map(prefix -> new TestIndexSet(indexSet.getConfig().toBuilder().indexPrefix(prefix).indexTemplateType(EVENT_TEMPLATE_TYPE).build())).collect(Collectors.toSet());
    when(indexSetRegistry.getForIndices(anyCollection())).thenReturn(eventIndexSets);
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final MongoIndexRange indexRange0 = MongoIndexRange.create("gl-events_0", now, now.plusDays(1), now, 0);
    final MongoIndexRange indexRange1 = MongoIndexRange.create("gl-system-events_2", now.plusDays(1), now.plusDays(2), now, 0);
    final MongoIndexRange indexRange2 = MongoIndexRange.create("graylog_0", now, now.plusDays(1), now, 0);
    final SortedSet<IndexRange> indices = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR).add(indexRange0).add(indexRange1).add(indexRange2).build();
    when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(indices);
    final TimeRange absoluteRange = AbsoluteRange.create(now.minusDays(1), now.plusDays(1));
    assertThat(searches.determineAffectedIndicesWithRanges(absoluteRange, null)).containsExactly(indexRange2);
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) IndexRangeComparator(org.graylog2.indexer.ranges.IndexRangeComparator) SortedSet(java.util.SortedSet) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EVENT_TEMPLATE_TYPE(org.graylog2.indexer.EventIndexTemplateProvider.EVENT_TEMPLATE_TYPE) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) ResultMessage(org.graylog2.indexer.results.ResultMessage) DeletionRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig) Indices(org.graylog2.indexer.indices.Indices) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) IndexSet(org.graylog2.indexer.IndexSet) ZoneOffset(java.time.ZoneOffset) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) SearchResult(org.graylog2.indexer.results.SearchResult) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) ArgumentMatchers.startsWith(org.mockito.ArgumentMatchers.startsWith) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) CountResult(org.graylog2.indexer.results.CountResult) List(java.util.List) Stream(org.graylog2.plugin.streams.Stream) MongoIndexRange(org.graylog2.indexer.ranges.MongoIndexRange) StreamService(org.graylog2.streams.StreamService) Timer(com.codahale.metrics.Timer) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Histogram(com.codahale.metrics.Histogram) FieldStatsResult(org.graylog2.indexer.results.FieldStatsResult) Mock(org.mockito.Mock) ScrollResult(org.graylog2.indexer.results.ScrollResult) MessageCountRotationStrategyConfig(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig) HashSet(java.util.HashSet) MockitoJUnit(org.mockito.junit.MockitoJUnit) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Before(org.junit.Before) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) IndexRangeService(org.graylog2.indexer.ranges.IndexRangeService) MetricRegistry(com.codahale.metrics.MetricRegistry) NO_BATCHSIZE(org.graylog2.indexer.searches.ScrollCommand.NO_BATCHSIZE) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TestIndexSet(org.graylog2.indexer.TestIndexSet) UTC(org.joda.time.DateTimeZone.UTC) IndexRange(org.graylog2.indexer.ranges.IndexRange) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) Rule(org.junit.Rule) DeletionRetentionStrategy(org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy) MockitoRule(org.mockito.junit.MockitoRule) KeywordRange(org.graylog2.plugin.indexer.searches.timeranges.KeywordRange) Collections(java.util.Collections) TestIndexSet(org.graylog2.indexer.TestIndexSet) 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) IndexSet(org.graylog2.indexer.IndexSet) TestIndexSet(org.graylog2.indexer.TestIndexSet) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 3 with TestIndexSet

use of org.graylog2.indexer.TestIndexSet in project graylog2-server by Graylog2.

the class IndexFieldTypePollerIT method setUp.

@Before
public void setUp() throws Exception {
    final Node node = mock(Node.class);
    @SuppressWarnings("UnstableApiUsage") final Indices indices = new Indices(new IndexMappingFactory(node, ImmutableMap.of(MESSAGE_TEMPLATE_TYPE, new MessageIndexTemplateProvider())), mock(NodeId.class), new NullAuditEventSender(), mock(EventBus.class), createIndicesAdapter());
    poller = new IndexFieldTypePoller(indices, new MetricRegistry(), createIndexFieldTypePollerAdapter());
    indexSet = new TestIndexSet(indexSetConfig);
    importFixture("org/graylog2/indexer/fieldtypes/IndexFieldTypePollerIT.json");
}
Also used : NullAuditEventSender(org.graylog2.audit.NullAuditEventSender) TestIndexSet(org.graylog2.indexer.TestIndexSet) IndexMappingFactory(org.graylog2.indexer.IndexMappingFactory) Node(org.graylog2.indexer.cluster.Node) MetricRegistry(com.codahale.metrics.MetricRegistry) NodeId(org.graylog2.plugin.system.NodeId) Indices(org.graylog2.indexer.indices.Indices) MessageIndexTemplateProvider(org.graylog2.indexer.MessageIndexTemplateProvider) EventBus(com.google.common.eventbus.EventBus) Before(org.junit.Before)

Example 4 with TestIndexSet

use of org.graylog2.indexer.TestIndexSet in project graylog2-server by Graylog2.

the class IndicesIT method getIndices.

@ContainerMatrixTest
public void getIndices() {
    final IndexSet indexSet = new TestIndexSet(indexSetConfig.toBuilder().indexPrefix("indices_it").build());
    final String index1 = createRandomIndex("indices_it_");
    final String index2 = createRandomIndex("indices_it_");
    client().closeIndex(index2);
    assertThat(indices.getIndices(indexSet)).containsOnly(index1, index2);
    assertThat(indices.getIndices(indexSet, "open", "close")).containsOnly(index1, index2);
    assertThat(indices.getIndices(indexSet, "open")).containsOnly(index1);
    assertThat(indices.getIndices(indexSet, "close")).containsOnly(index2);
}
Also used : TestIndexSet(org.graylog2.indexer.TestIndexSet) IndexSet(org.graylog2.indexer.IndexSet) TestIndexSet(org.graylog2.indexer.TestIndexSet) ContainerMatrixTest(org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)

Aggregations

TestIndexSet (org.graylog2.indexer.TestIndexSet)4 IndexSet (org.graylog2.indexer.IndexSet)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 ZonedDateTime (java.time.ZonedDateTime)2 ElasticsearchBaseTest (org.graylog.testing.elasticsearch.ElasticsearchBaseTest)2 FakeStream (org.graylog2.buffers.processors.fakestreams.FakeStream)2 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)2 Indices (org.graylog2.indexer.indices.Indices)2 CountResult (org.graylog2.indexer.results.CountResult)2 Stream (org.graylog2.plugin.streams.Stream)2 DateTime (org.joda.time.DateTime)2 Test (org.junit.Test)2 Histogram (com.codahale.metrics.Histogram)1 Timer (com.codahale.metrics.Timer)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 EventBus (com.google.common.eventbus.EventBus)1 ZoneOffset (java.time.ZoneOffset)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1