Search in sources :

Example 21 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class ElasticsearchExportBackendITBase method usesTimeRangeTestLtEqualToTimestampofLastEntry.

// This method tests, that with LT (the upper interval excluded) instead of LTE the message with a TS same as the upper interval is excluded
@Test
public void usesTimeRangeTestLtEqualToTimestampofLastEntry() {
    importFixture("messages.json");
    ExportMessagesCommand command = commandBuilderWithAllStreams().timeRange(timerange("2015-01-01T00:00:00.000Z", "2015-01-01T01:59:59.999Z")).build();
    SimpleMessageChunk totalResult = collectTotalResult(command);
    assertThat(totalResult.messages().stream().map(msg -> msg.fields().get("timestamp")).anyMatch("2015-01-01T01:00:00.000Z"::equals)).isTrue();
    assertThat(totalResult.messages().stream().map(msg -> msg.fields().get("timestamp")).anyMatch("2015-01-01T01:59:59.999Z"::equals)).isFalse();
}
Also used : SimpleMessageChunk(org.graylog.plugins.views.search.export.SimpleMessageChunk) Arrays(java.util.Arrays) ImmutableSet(com.google.common.collect.ImmutableSet) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) SimpleMessage(org.graylog.plugins.views.search.export.SimpleMessage) TestData(org.graylog.plugins.views.search.export.TestData) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExportException(org.graylog.plugins.views.search.export.ExportException) ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) SimpleMessageChunk(org.graylog.plugins.views.search.export.SimpleMessageChunk) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) Sets(com.google.common.collect.Sets) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) LinkedHashSet(java.util.LinkedHashSet) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) Test(org.junit.Test) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest)

Example 22 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class ElasticsearchExportBackendITBase method usesFieldsInOrder.

@Test
public void usesFieldsInOrder() {
    importFixture("messages.json");
    ExportMessagesCommand command = commandBuilderWithAllStreams().fieldsInOrder("timestamp", "message").build();
    runWithExpectedResultIgnoringSort(command, "timestamp,message", "graylog_0, 2015-01-01T04:00:00.000Z, Ho", "graylog_0, 2015-01-01T03:00:00.000Z, Hi", "graylog_1, 2015-01-01T01:59:59.999Z, He", "graylog_0, 2015-01-01T01:00:00.000Z, Ha");
}
Also used : ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) Test(org.junit.Test) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest)

Example 23 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class ElasticsearchExportBackendTest method appliesRequestStrategyStreamFilter.

@Test
void appliesRequestStrategyStreamFilter() {
    ExportMessagesCommand command = ExportMessagesCommand.withDefaults().toBuilder().streams("stream-1", "stream-2").build();
    when(requestStrategy.removeUnsupportedStreams(command.streams())).thenReturn(ImmutableSet.of("stream-1"));
    sut.run(command, chunk -> {
    });
    String searchPayload = captureSearchPayload(command);
    assertThat(searchPayload).doesNotContain("stream-2");
}
Also used : ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) Test(org.junit.jupiter.api.Test)

Example 24 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class ElasticsearchExportBackendIT method deliversCompleteLastChunkIfLimitIsReached.

@Test
public void deliversCompleteLastChunkIfLimitIsReached() {
    importFixture("messages.json");
    ExportMessagesCommand command = commandBuilderWithAllStreams().chunkSize(2).limit(3).build();
    SimpleMessageChunk totalResult = collectTotalResult(command);
    assertThat(totalResult.messages()).hasSize(4);
}
Also used : SimpleMessageChunk(org.graylog.plugins.views.search.export.SimpleMessageChunk) ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 25 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class ElasticsearchExportBackendIT method usesFieldsInOrder.

@Test
public void usesFieldsInOrder() {
    importFixture("messages.json");
    ExportMessagesCommand command = commandBuilderWithAllStreams().fieldsInOrder("timestamp", "message").build();
    runWithExpectedResultIgnoringSort(command, "timestamp,message", "graylog_0, 2015-01-01T04:00:00.000Z, Ho", "graylog_0, 2015-01-01T03:00:00.000Z, Hi", "graylog_1, 2015-01-01T01:59:59.999Z, He", "graylog_0, 2015-01-01T01:00:00.000Z, Ha");
}
Also used : ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Aggregations

ExportMessagesCommand (org.graylog.plugins.views.search.export.ExportMessagesCommand)29 Test (org.junit.Test)23 ElasticsearchBaseTest (org.graylog.testing.elasticsearch.ElasticsearchBaseTest)21 SimpleMessageChunk (org.graylog.plugins.views.search.export.SimpleMessageChunk)9 ApiOperation (io.swagger.annotations.ApiOperation)3 POST (javax.ws.rs.POST)3 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3 Test (org.junit.jupiter.api.Test)3 Search (io.searchbox.core.Search)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Search (org.graylog.plugins.views.search.Search)2 ResultFormat (org.graylog.plugins.views.search.export.ResultFormat)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 BadRequestException (javax.ws.rs.BadRequestException)1