Search in sources :

Example 1 with INDEX_BLOCK_REASON

use of org.graylog.storage.elasticsearch6.MessagesAdapterES6.INDEX_BLOCK_REASON in project graylog2-server by Graylog2.

the class MessagesAdapterES6Test method parsesErrorTypesAndReturnsIndexingErrors.

@Test
public void parsesErrorTypesAndReturnsIndexingErrors() throws IOException {
    final BulkResult errorResult = mock(BulkResult.class);
    final BulkResult.BulkResultItem indexBlockedError = errorResultItem("blocked-id", INDEX_BLOCK_ERROR, INDEX_BLOCK_REASON);
    final BulkResult.BulkResultItem otherError = errorResultItem("other-error-id", "something else", "something else");
    when(errorResult.getFailedItems()).thenReturn(ImmutableList.of(indexBlockedError, otherError));
    when(jestClient.execute(any())).thenReturn(errorResult);
    final List<Messages.IndexingError> result = messagesAdapter.bulkIndex(messagesWithIds("blocked-id", "other-error-id"));
    verify(jestClient, times(1)).execute(any());
    assertThat(result).extracting(indexingError -> indexingError.message().getId(), Messages.IndexingError::errorType, Messages.IndexingError::errorMessage).containsExactlyInAnyOrder(tuple("blocked-id", Messages.IndexingError.ErrorType.IndexBlocked, INDEX_BLOCK_REASON), tuple("other-error-id", Messages.IndexingError.ErrorType.Unknown, "something else"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) INDEX_BLOCK_ERROR(org.graylog.storage.elasticsearch6.MessagesAdapterES6.INDEX_BLOCK_ERROR) JestClient(io.searchbox.client.JestClient) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Messages(org.graylog2.indexer.messages.Messages) IndexSet(org.graylog2.indexer.IndexSet) MetricRegistry(com.codahale.metrics.MetricRegistry) IndexingRequest(org.graylog2.indexer.messages.IndexingRequest) Assertions.tuple(org.assertj.core.api.Assertions.tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) INDEX_BLOCK_REASON(org.graylog.storage.elasticsearch6.MessagesAdapterES6.INDEX_BLOCK_REASON) Mockito.verify(org.mockito.Mockito.verify) BulkResult(io.searchbox.core.BulkResult) Test(org.junit.jupiter.api.Test) List(java.util.List) Mockito.never(org.mockito.Mockito.never) ChunkedBulkIndexer(org.graylog2.indexer.messages.ChunkedBulkIndexer) Message(org.graylog2.plugin.Message) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Messages(org.graylog2.indexer.messages.Messages) BulkResult(io.searchbox.core.BulkResult) Test(org.junit.jupiter.api.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 JestClient (io.searchbox.client.JestClient)1 BulkResult (io.searchbox.core.BulkResult)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 INDEX_BLOCK_ERROR (org.graylog.storage.elasticsearch6.MessagesAdapterES6.INDEX_BLOCK_ERROR)1 INDEX_BLOCK_REASON (org.graylog.storage.elasticsearch6.MessagesAdapterES6.INDEX_BLOCK_REASON)1 IndexSet (org.graylog2.indexer.IndexSet)1 ChunkedBulkIndexer (org.graylog2.indexer.messages.ChunkedBulkIndexer)1 IndexingRequest (org.graylog2.indexer.messages.IndexingRequest)1 Messages (org.graylog2.indexer.messages.Messages)1 Message (org.graylog2.plugin.Message)1