Search in sources :

Example 1 with IndexFailureService

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

the class DefaultFailureHandlerTest method handle_allFailuresHandedOverToIndexFailureService.

@Test
public void handle_allFailuresHandedOverToIndexFailureService() {
    // given
    final DateTime ts = DateTime.now(DateTimeZone.UTC);
    final Indexable indexable1 = mock(Indexable.class);
    when(indexable1.getId()).thenReturn("msg-1");
    when(indexable1.getTimestamp()).thenReturn(ts);
    final Indexable indexable2 = mock(Indexable.class);
    when(indexable2.getId()).thenReturn("msg-2");
    when(indexable2.getTimestamp()).thenReturn(ts);
    final IndexingFailure indexingFailure1 = new IndexingFailure(IndexingFailureCause.MappingError, "indexingFailureMessage1", "indexingFailureDetails1", Tools.nowUTC(), indexable1, "index1");
    final IndexingFailure indexingFailure2 = new IndexingFailure(IndexingFailureCause.MappingError, "indexingFailureMessage2", "indexingFailureDetails2", Tools.nowUTC(), indexable2, "index2");
    final FailureBatch indexingFailureBatch = FailureBatch.indexingFailureBatch(ImmutableList.of(indexingFailure1, indexingFailure2));
    // when
    underTest.handle(indexingFailureBatch);
    // then
    verify(indexFailureService, times(2)).saveWithoutValidation(any());
    verify(indexFailureService, times(1)).saveWithoutValidation(argThat(arg -> arg.asMap().get("letter_id").equals("msg-1") && arg.asMap().get("index").equals("index1") && arg.asMap().get("type").equals("indexing") && arg.asMap().get("message").equals("indexingFailureDetails1") && arg.asMap().get("timestamp") != null));
    verify(indexFailureService, times(1)).saveWithoutValidation(argThat(arg -> arg.asMap().get("letter_id").equals("msg-2") && arg.asMap().get("index").equals("index2") && arg.asMap().get("type").equals("indexing") && arg.asMap().get("message").equals("indexingFailureDetails2") && arg.asMap().get("timestamp") != null));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DateTimeZone(org.joda.time.DateTimeZone) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Tools(org.graylog2.plugin.Tools) DateTime(org.joda.time.DateTime) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) IndexFailureService(org.graylog2.indexer.IndexFailureService) ImmutableList(com.google.common.collect.ImmutableList) Indexable(org.graylog2.indexer.messages.Indexable) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) Mockito.mock(org.mockito.Mockito.mock) Indexable(org.graylog2.indexer.messages.Indexable) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 AssertionsForClassTypes.assertThat (org.assertj.core.api.AssertionsForClassTypes.assertThat)1 IndexFailureService (org.graylog2.indexer.IndexFailureService)1 Indexable (org.graylog2.indexer.messages.Indexable)1 Tools (org.graylog2.plugin.Tools)1 DateTime (org.joda.time.DateTime)1 DateTimeZone (org.joda.time.DateTimeZone)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1