@Test public void recent_records_are_not_recovered() { EsQueueDto item = insertItem(FOO_TYPE, "f1"); SuccessfulFakeIndexer indexer = new SuccessfulFakeIndexer(FOO_TYPE); // do not advance in time underTest = newRecoveryIndexer(indexer); underTest.recover(); assertThatQueueHasSize(1); assertThat(indexer.called).isEmpty(); assertThatLogsDoNotContain(TRACE, "Elasticsearch recovery - processing 2 [foos/foo]"); assertThatLogsDoNotContain(INFO, "documents processed"); }
@Test public void successfully_recover_indexing_requests() { IndexType type1 = new IndexType("foos", "foo"); EsQueueDto item1a = insertItem(type1, "f1"); EsQueueDto item1b = insertItem(type1, "f2"); IndexType type2 = new IndexType("bars", "bar"); EsQueueDto item2 = insertItem(type2, "b1"); SuccessfulFakeIndexer indexer1 = new SuccessfulFakeIndexer(type1); SuccessfulFakeIndexer indexer2 = new SuccessfulFakeIndexer(type2); advanceInTime(); underTest = newRecoveryIndexer(indexer1, indexer2); underTest.recover(); assertThatQueueHasSize(0); assertThatLogsContain(INFO, "Elasticsearch recovery - 3 documents processed [0 failures]"); assertThat(indexer1.called).hasSize(1); assertThat(indexer1.called.get(0)) .extracting(EsQueueDto::getUuid) .containsExactlyInAnyOrder(item1a.getUuid(), item1b.getUuid()); assertThatLogsContain(TRACE, "Elasticsearch recovery - processing 2 [foos/foo]"); assertThat(indexer2.called).hasSize(1); assertThat(indexer2.called.get(0)) .extracting(EsQueueDto::getUuid) .containsExactlyInAnyOrder(item2.getUuid()); assertThatLogsContain(TRACE, "Elasticsearch recovery - processing 1 [bars/bar]"); }
@Test public void recover_multiple_times_the_same_document() { EsQueueDto item1 = insertItem(FOO_TYPE, "f1"); EsQueueDto item2 = insertItem(FOO_TYPE, item1.getDocId()); EsQueueDto item3 = insertItem(FOO_TYPE, item1.getDocId()); advanceInTime(); SuccessfulFakeIndexer indexer = new SuccessfulFakeIndexer(FOO_TYPE); underTest = newRecoveryIndexer(indexer); underTest.recover(); assertThatQueueHasSize(0); assertThat(indexer.called).hasSize(1); assertThat(indexer.called.get(0)).extracting(EsQueueDto::getUuid) .containsExactlyInAnyOrder(item1.getUuid(), item2.getUuid(), item3.getUuid()); assertThatLogsContain(TRACE, "Elasticsearch recovery - processing 3 [foos/foo]"); assertThatLogsContain(INFO, "Elasticsearch recovery - 3 documents processed [0 failures]"); }
@Test public void unsupported_types_are_kept_in_queue_for_manual_fix_operation() { insertItem(FOO_TYPE, "f1"); ResilientIndexer indexer = new SuccessfulFakeIndexer(new IndexType("bars", "bar")); advanceInTime(); underTest = newRecoveryIndexer(indexer); underTest.recover(); assertThatQueueHasSize(1); assertThatLogsContain(ERROR, "Elasticsearch recovery - ignore 1 items with unsupported type [foos/foo]"); }