5858import java .util .concurrent .atomic .AtomicReference ;
5959
6060import static org .hamcrest .Matchers .anyOf ;
61+ import static org .hamcrest .Matchers .both ;
6162import static org .hamcrest .Matchers .empty ;
6263import static org .hamcrest .Matchers .equalTo ;
6364import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
6465import static org .hamcrest .Matchers .lessThan ;
66+ import static org .hamcrest .Matchers .lessThanOrEqualTo ;
6567import static org .hamcrest .Matchers .not ;
6668
6769public class RecoveryDuringReplicationTests extends ESIndexLevelReplicationTestCase {
@@ -390,7 +392,8 @@ public long indexTranslogOperations(List<Translog.Operation> operations, int tot
390392 recoveryStart .await ();
391393
392394 // index some more
393- docs += shards .indexDocs (randomInt (5 ));
395+ final int indexedDuringRecovery = shards .indexDocs (randomInt (5 ));
396+ docs += indexedDuringRecovery ;
394397
395398 assertFalse ("recovery should wait on pending docs" , opsSent .get ());
396399
@@ -401,7 +404,9 @@ public long indexTranslogOperations(List<Translog.Operation> operations, int tot
401404 recoveryFuture .get ();
402405
403406 assertThat (newReplica .recoveryState ().getIndex ().fileDetails (), empty ());
404- assertThat (newReplica .recoveryState ().getTranslog ().recoveredOperations (), equalTo (docs ));
407+ assertThat (newReplica .recoveryState ().getTranslog ().recoveredOperations (),
408+ // we don't know which of the inflight operations made it into the translog range we re-play
409+ both (greaterThanOrEqualTo (docs -indexedDuringRecovery )).and (lessThanOrEqualTo (docs )));
405410
406411 shards .assertAllEqual (docs );
407412 } finally {
0 commit comments