diff --git a/core/src/test/java/org/elasticsearch/action/support/replication/ReplicationResponseTests.java b/core/src/test/java/org/elasticsearch/action/support/replication/ReplicationResponseTests.java index ca8f0a4c6b2..d3b8975ac78 100644 --- a/core/src/test/java/org/elasticsearch/action/support/replication/ReplicationResponseTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/replication/ReplicationResponseTests.java @@ -34,8 +34,11 @@ import org.elasticsearch.test.EqualsHashCodeTestUtils; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Set; import java.util.function.Supplier; import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode; @@ -81,11 +84,15 @@ public class ReplicationResponseTests extends ESTestCase { List> mutations = new ArrayList<>(); final Index index = failure.fullShardId().getIndex(); - final ShardId randomIndex = new ShardId(randomUnicodeOfCodepointLength(5), index.getUUID(), failure.shardId()); + final Set indexNamePool = new HashSet<>(Arrays.asList(randomUnicodeOfCodepointLength(5), randomUnicodeOfCodepointLength(6))); + indexNamePool.remove(index.getName()); + final ShardId randomIndex = new ShardId(randomFrom(indexNamePool), index.getUUID(), failure.shardId()); mutations.add(() -> new ReplicationResponse.ShardInfo.Failure(randomIndex, failure.nodeId(), (Exception) failure.getCause(), failure.status(), failure.primary())); - final ShardId randomUUID = new ShardId(index.getName(), randomUnicodeOfCodepointLength(5), failure.shardId()); + final Set uuidPool = new HashSet<>(Arrays.asList(randomUnicodeOfCodepointLength(5), randomUnicodeOfCodepointLength(6))); + uuidPool.remove(index.getUUID()); + final ShardId randomUUID = new ShardId(index.getName(), randomFrom(uuidPool), failure.shardId()); mutations.add(() -> new ReplicationResponse.ShardInfo.Failure(randomUUID, failure.nodeId(), (Exception) failure.getCause(), failure.status(), failure.primary())); @@ -93,15 +100,21 @@ public class ReplicationResponseTests extends ESTestCase { mutations.add(() -> new ReplicationResponse.ShardInfo.Failure(randomShardId, failure.nodeId(), (Exception) failure.getCause(), failure.status(), failure.primary())); - final String randomNode = randomUnicodeOfLength(3); + final Set nodeIdPool = new HashSet<>(Arrays.asList(randomUnicodeOfLength(3), randomUnicodeOfLength(4))); + nodeIdPool.remove(failure.nodeId()); + final String randomNode = randomFrom(nodeIdPool); mutations.add(() -> new ReplicationResponse.ShardInfo.Failure(failure.fullShardId(), randomNode, (Exception) failure.getCause(), failure.status(), failure.primary())); - final Exception randomException = randomFrom(new IllegalStateException("a"), new IllegalArgumentException("b")); + final Set exceptionPool = new HashSet<>(Arrays.asList(new IllegalStateException("a"), new IllegalArgumentException("b"))); + exceptionPool.remove(failure.getCause()); + final Exception randomException = randomFrom(exceptionPool); mutations.add(() -> new ReplicationResponse.ShardInfo.Failure(failure.fullShardId(), failure.nodeId(), randomException, failure.status(), failure.primary())); - final RestStatus randomStatus = randomFrom(RestStatus.values()); + final Set otherStatuses = new HashSet<>(Arrays.asList(RestStatus.values())); + otherStatuses.remove(failure.status()); + final RestStatus randomStatus = randomFrom(otherStatuses); mutations.add(() -> new ReplicationResponse.ShardInfo.Failure(failure.fullShardId(), failure.nodeId(), (Exception) failure.getCause(), randomStatus, failure.primary())); diff --git a/test/framework/src/main/java/org/elasticsearch/test/EqualsHashCodeTestUtils.java b/test/framework/src/main/java/org/elasticsearch/test/EqualsHashCodeTestUtils.java index bf1cd8132da..76cfcce033b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/EqualsHashCodeTestUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/EqualsHashCodeTestUtils.java @@ -78,7 +78,8 @@ public class EqualsHashCodeTestUtils { assertThat(objectName + " hashcode returns different values if called multiple times", original.hashCode(), equalTo(original.hashCode())); if (mutationFunction != null) { - assertThat(objectName + " mutation should not be equal to original", mutationFunction.mutate(original), + T mutation = mutationFunction.mutate(original); + assertThat(objectName + " mutation should not be equal to original", mutation, not(equalTo(original))); }