Search in sources :

Example 1 with FieldTypesLookup

use of org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendQueryStringDecoratorsTest method setUp.

@BeforeEach
void setUp() {
    final QueryStringDecorator decorator = (queryString, job, query) -> "decorated";
    final Set<QueryStringDecorator> decorators = Collections.singleton(decorator);
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(Collections.emptyMap(), mock(ElasticsearchClient.class), mock(IndexLookup.class), new QueryStringDecorators(decorators), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), true);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Query(org.graylog.plugins.views.search.Query) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) SearchType(org.graylog.plugins.views.search.SearchType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Search(org.graylog.plugins.views.search.Search) Nonnull(javax.annotation.Nonnull) JsonPathAssert.assertThat(com.revinate.assertj.json.JsonPathAssert.assertThat) Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.jupiter.api.Test) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) DocumentContext(com.jayway.jsonpath.DocumentContext) Optional(java.util.Optional) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with FieldTypesLookup

use of org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendTest method setup.

@BeforeClass
public static void setup() {
    Map<String, Provider<ESSearchTypeHandler<? extends SearchType>>> handlers = Maps.newHashMap();
    handlers.put(MessageList.NAME, () -> new ESMessageList(new QueryStringDecorators.Fake()));
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    backend = new ElasticsearchBackend(handlers, null, mock(IndexLookup.class), new QueryStringDecorators.Fake(), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false);
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch7.views.searchtypes.ESSearchTypeHandler) Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) BeforeClass(org.junit.BeforeClass) Provider(javax.inject.Provider) Query(org.graylog.plugins.views.search.Query) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Maps(com.google.common.collect.Maps) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) SearchType(org.graylog.plugins.views.search.SearchType) ESMessageList(org.graylog.storage.elasticsearch7.views.searchtypes.ESMessageList) Map(java.util.Map) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Search(org.graylog.plugins.views.search.Search) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) QueryResult(org.graylog.plugins.views.search.QueryResult) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Mockito.mock(org.mockito.Mockito.mock) ESMessageList(org.graylog.storage.elasticsearch7.views.searchtypes.ESMessageList) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Provider(javax.inject.Provider) BeforeClass(org.junit.BeforeClass)

Example 3 with FieldTypesLookup

use of org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendTest method setup.

@BeforeClass
public static void setup() {
    Map<String, Provider<ESSearchTypeHandler<? extends SearchType>>> handlers = Maps.newHashMap();
    handlers.put(MessageList.NAME, () -> new ESMessageList(new QueryStringDecorators.Fake()));
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    final QueryStringParser queryStringParser = new QueryStringParser();
    backend = new ElasticsearchBackend(handlers, null, mock(IndexLookup.class), new QueryStringDecorators.Fake(), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false, new ObjectMapperProvider().get());
}
Also used : ESMessageList(org.graylog.storage.elasticsearch6.views.searchtypes.ESMessageList) ESSearchTypeHandler(org.graylog.storage.elasticsearch6.views.searchtypes.ESSearchTypeHandler) BeforeClass(org.junit.BeforeClass) Provider(javax.inject.Provider) Query(org.graylog.plugins.views.search.Query) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) SearchType(org.graylog.plugins.views.search.SearchType) Map(java.util.Map) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Search(org.graylog.plugins.views.search.Search) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) QueryResult(org.graylog.plugins.views.search.QueryResult) Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Test(org.junit.Test) Maps(com.google.common.collect.Maps) QueryStringParser(org.graylog.plugins.views.search.elasticsearch.QueryStringParser) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Mockito.mock(org.mockito.Mockito.mock) ESMessageList(org.graylog.storage.elasticsearch6.views.searchtypes.ESMessageList) QueryStringParser(org.graylog.plugins.views.search.elasticsearch.QueryStringParser) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Provider(javax.inject.Provider) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) BeforeClass(org.junit.BeforeClass)

Example 4 with FieldTypesLookup

use of org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendErrorHandlingTest method setUp.

@Before
public void setUp() throws Exception {
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(ImmutableMap.of("dummy", () -> mock(DummyHandler.class)), jestClient, indexLookup, new QueryStringDecorators(Collections.emptySet()), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false, objectMapper);
    when(indexLookup.indexNamesForStreamsInTimeRange(any(), any())).thenReturn(Collections.emptySet());
    final SearchType searchType1 = mock(SearchType.class);
    when(searchType1.id()).thenReturn("deadbeef");
    when(searchType1.type()).thenReturn("dummy");
    final SearchType searchType2 = mock(SearchType.class);
    when(searchType2.id()).thenReturn("cafeaffe");
    when(searchType2.type()).thenReturn("dummy");
    final Set<SearchType> searchTypes = ImmutableSet.of(searchType1, searchType2);
    this.query = Query.builder().id("query1").timerange(RelativeRange.create(300)).query(ElasticsearchQueryString.of("*")).searchTypes(searchTypes).build();
    final Search search = Search.builder().id("search1").queries(ImmutableSet.of(query)).build();
    this.searchJob = new SearchJob("job1", search, "admin");
    this.queryContext = new ESGeneratedQueryContext(this.backend, new SearchSourceBuilder(), searchJob, query, mock(FieldTypesLookup.class));
    searchTypes.forEach(queryContext::searchSourceBuilder);
    when(jestClient.execute(any())).thenReturn(result);
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch6.views.searchtypes.ESSearchTypeHandler) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Query(org.graylog.plugins.views.search.Query) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultiSearchResult(io.searchbox.core.MultiSearchResult) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) JestClient(io.searchbox.client.JestClient) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) SearchType(org.graylog.plugins.views.search.SearchType) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) MockitoJUnit(org.mockito.junit.MockitoJUnit) JsonNode(com.fasterxml.jackson.databind.JsonNode) Search(org.graylog.plugins.views.search.Search) QueryResult(org.graylog.plugins.views.search.QueryResult) Before(org.junit.Before) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Rule(org.junit.Rule) SearchError(org.graylog.plugins.views.search.errors.SearchError) MockitoRule(org.mockito.junit.MockitoRule) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) Mockito.mock(org.mockito.Mockito.mock) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Search(org.graylog.plugins.views.search.Search) SearchJob(org.graylog.plugins.views.search.SearchJob) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) SearchType(org.graylog.plugins.views.search.SearchType) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) Before(org.junit.Before)

Example 5 with FieldTypesLookup

use of org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendQueryStringDecoratorsTest method setUp.

@BeforeEach
void setUp() {
    final QueryStringDecorator decorator = (queryString, job, query) -> "decorated";
    final Set<QueryStringDecorator> decorators = Collections.singleton(decorator);
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(Collections.emptyMap(), mock(JestClient.class), mock(IndexLookup.class), new QueryStringDecorators(decorators), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), true, new ObjectMapperProvider().get());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Query(org.graylog.plugins.views.search.Query) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) JestClient(io.searchbox.client.JestClient) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) SearchType(org.graylog.plugins.views.search.SearchType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Search(org.graylog.plugins.views.search.Search) Nonnull(javax.annotation.Nonnull) JsonPathAssert.assertThat(com.revinate.assertj.json.JsonPathAssert.assertThat) Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.jupiter.api.Test) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) DocumentContext(com.jayway.jsonpath.DocumentContext) Optional(java.util.Optional) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)10 Query (org.graylog.plugins.views.search.Query)10 Search (org.graylog.plugins.views.search.Search)10 SearchJob (org.graylog.plugins.views.search.SearchJob)10 SearchType (org.graylog.plugins.views.search.SearchType)10 FieldTypesLookup (org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup)10 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)10 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)10 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)8 RelativeRange (org.graylog2.plugin.indexer.searches.timeranges.RelativeRange)8 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)8 Mockito.mock (org.mockito.Mockito.mock)8 Collections (java.util.Collections)6 Map (java.util.Map)6 Set (java.util.Set)6 Provider (javax.inject.Provider)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 QueryResult (org.graylog.plugins.views.search.QueryResult)6 Test (org.junit.Test)6 Mockito.when (org.mockito.Mockito.when)6