From d43ae62829bd03991d773bc147249bc43dd651d4 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Wed, 24 Jan 2018 16:17:31 +0100 Subject: [PATCH] [Test] Fix DiscoveryNodesTests.testDeltas() The DiscoveryNodes.Delta was changed in #28197. Previous/Master nodes are now always set in the `Delta` (before the change they were set only if the master changed) and the `masterChanged()` method is now based on object equality and nodes ephemeral ids (before the change it was based on nodes id). This commit adapts the DiscoveryNodesTests.testDeltas() to reflect the changes. --- .../cluster/node/DiscoveryNodesTests.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java index 6bfb78a2ade9c..37cc11da8b7b6 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -21,6 +21,7 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks; import org.elasticsearch.Version; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; @@ -113,7 +114,9 @@ public void testDeltas() { // change an attribute Map attrs = new HashMap<>(node.getAttributes()); attrs.put("new", "new"); - node = new DiscoveryNode(node.getName(), node.getId(), node.getAddress(), attrs, node.getRoles(), node.getVersion()); + final TransportAddress nodeAddress = node.getAddress(); + node = new DiscoveryNode(node.getName(), node.getId(), node.getEphemeralId(), nodeAddress.address().getHostString(), + nodeAddress.getAddress(), nodeAddress, attrs, node.getRoles(), node.getVersion()); } nodesB.add(node); } @@ -140,14 +143,21 @@ public void testDeltas() { DiscoveryNodes.Delta delta = discoNodesB.delta(discoNodesA); - if (Objects.equals(masterAId, masterBId)) { - assertFalse(delta.masterNodeChanged()); + if (masterA == null) { assertThat(delta.previousMasterNode(), nullValue()); + } else { + assertThat(delta.previousMasterNode().getId(), equalTo(masterAId)); + } + if (masterB == null) { assertThat(delta.newMasterNode(), nullValue()); + } else { + assertThat(delta.newMasterNode().getId(), equalTo(masterBId)); + } + + if (Objects.equals(masterAId, masterBId)) { + assertFalse(delta.masterNodeChanged()); } else { assertTrue(delta.masterNodeChanged()); - assertThat(delta.newMasterNode() != null ? delta.newMasterNode().getId() : null, equalTo(masterBId)); - assertThat(delta.previousMasterNode() != null ? delta.previousMasterNode().getId() : null, equalTo(masterAId)); } Set newNodes = new HashSet<>(nodesB);