From 768e1c20120b921090a7e9bc439aa42c49999bbb Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sun, 26 Apr 2015 13:44:29 +0200 Subject: [PATCH] [TEST] Fix test to take care of refresh failures after successful commit --- .../index/engine/InternalEngineTests.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 5323e36b8c3..3673b7f889d 100644 --- a/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -19,6 +19,8 @@ package org.elasticsearch.index.engine; +import com.carrotsearch.randomizedtesting.annotations.Repeat; +import com.carrotsearch.randomizedtesting.annotations.Seed; import com.google.common.collect.ImmutableMap; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.Level; @@ -1760,6 +1762,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { assertThat(topDocs.totalHits, equalTo(numDocs)); } engine.close(); + boolean recoveredButFailed = false; final MockDirectoryWrapper directory = DirectoryUtils.getLeaf(store.directory(), MockDirectoryWrapper.class); if (directory != null) { // since we rollback the IW we are writing the same segment files again after starting IW but MDW prevents @@ -1777,7 +1780,16 @@ public class InternalEngineTests extends ElasticsearchTestCase { started = true; break; } catch (EngineCreationFailureException ex) { - // skip + // sometimes we fail after we committed the recovered docs during the finaly refresh call + // that means hte index is consistent and recovered so we can't assert on the num recovered ops below. + try (IndexReader reader = DirectoryReader.open(directory.getDelegate())) { + if (reader.numDocs() == numDocs) { + recoveredButFailed = true; + break; + } else { + // skip - we just failed + } + } } } @@ -1796,8 +1808,10 @@ public class InternalEngineTests extends ElasticsearchTestCase { TopDocs topDocs = searcher.searcher().search(new MatchAllDocsQuery(), randomIntBetween(numDocs, numDocs + 10)); assertThat(topDocs.totalHits, equalTo(numDocs)); } - TranslogHandler parser = (TranslogHandler) engine.config().getTranslogRecoveryPerformer(); - assertEquals(numDocs, parser.recoveredOps.get()); + if (recoveredButFailed == false) { + TranslogHandler parser = (TranslogHandler) engine.config().getTranslogRecoveryPerformer(); + assertEquals(numDocs, parser.recoveredOps.get()); + } } @Test