From 1de5bb8cd5a2e989398345241a338ee218420300 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 8 May 2017 15:50:52 -0400 Subject: [PATCH] Ensure test replicas have valid recovery state When starting a new replication group in an index level replication test case, a started replica would not have a valid recovery state. This violates simple assumptions as replicas always have to have recovered before being started. This commit causes this to be the case that this assumption is not violated too. --- .../index/replication/ESIndexLevelReplicationTestCase.java | 4 ++++ .../index/replication/IndexLevelReplicationTests.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java index 68373ce529a..0f61f4d02bf 100644 --- a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java @@ -209,6 +209,10 @@ public abstract class ESIndexLevelReplicationTestCase extends IndexShardTestCase primary.markAsRecovering("store", new RecoveryState(primary.routingEntry(), pNode, null)); primary.recoverFromStore(); primary.updateRoutingEntry(ShardRoutingHelper.moveToStarted(primary.routingEntry())); + for (final IndexShard replica : replicas) { + //replica.markAsRecovering("peer recovery", new RecoveryState(replica.routingEntry(), getDiscoveryNode(replica.routingEntry().currentNodeId()), pNode)); + recoverReplica(replica); + } updateAllocationIDsOnPrimary(); } diff --git a/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java b/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java index 6a347034a0c..3e037bc9c7b 100644 --- a/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java +++ b/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java @@ -77,7 +77,6 @@ public class IndexLevelReplicationTests extends ESIndexLevelReplicationTestCase public void testAppendWhileRecovering() throws Exception { try (ReplicationGroup shards = createGroup(0)) { shards.startAll(); - IndexShard replica = shards.addReplica(); CountDownLatch latch = new CountDownLatch(2); int numDocs = randomIntBetween(100, 200); shards.appendDocs(1);// just append one to the translog so we can assert below @@ -94,6 +93,7 @@ public class IndexLevelReplicationTests extends ESIndexLevelReplicationTestCase } }; thread.start(); + IndexShard replica = shards.addReplica(); Future future = shards.asyncRecoverReplica(replica, (indexShard, node) -> new RecoveryTarget(indexShard, node, recoveryListener, version -> { }) {