From 11aa83011c429fc3efc18f455ebcc46d4c320ab1 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 29 Nov 2017 07:16:52 -0500 Subject: [PATCH] Fix get operations between test This test was broken by an upstream change that no longer guarantees we see the operations from the upstream translog in the order they appear in that translog. As such, the assertions in this test were too strong so this commit relaxes them. Relates #3153 --- .../ccr/action/ShardChangesActionTests.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/ccr/action/ShardChangesActionTests.java b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/ccr/action/ShardChangesActionTests.java index 7f5bc93fc75..67cc05de8b7 100644 --- a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/ccr/action/ShardChangesActionTests.java +++ b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/ccr/action/ShardChangesActionTests.java @@ -20,6 +20,9 @@ import org.elasticsearch.test.ESSingleNodeTestCase; import org.mockito.Mockito; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.LongStream; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -46,12 +49,14 @@ public class ShardChangesActionTests extends ESSingleNodeTestCase { int min = randomIntBetween(0, numWrites - 1); int max = randomIntBetween(min, numWrites - 1); - int index = 0; - List operations = ShardChangesAction.getOperationsBetween(indexShard, min, max); - for (long expectedSeqNo = min; expectedSeqNo < max; expectedSeqNo++) { - Translog.Operation operation = operations.get(index++); - assertThat(operation.seqNo(), equalTo(expectedSeqNo)); - } + final List operations = ShardChangesAction.getOperationsBetween(indexShard, min, max); + /* + * We are not guaranteed that operations are returned to us in order they are in the translog (if our read crosses multiple + * generations) so the best we can assert is that we see the expected operations. + */ + final Set seenSeqNos = operations.stream().map(Translog.Operation::seqNo).collect(Collectors.toSet()); + final Set expectedSeqNos = LongStream.range(min, max + 1).boxed().collect(Collectors.toSet()); + assertThat(seenSeqNos, equalTo(expectedSeqNos)); } // get operations for a range no operations exists: