Fix randomization in testPerformActionAttrsRequestFails (#43304)

The randomization in this test would occasionally generate duplicate
node attribute keys, causing spurious test failures. This commit adjusts
the randomization to not generate duplicate keys and cleans up the data
structure used to hold the generated keys.
This commit is contained in:
Gordon Brown 2019-06-19 10:34:39 -06:00 committed by GitHub
parent 667bdcd3ce
commit 23a3471394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 8 deletions

View File

@ -39,7 +39,9 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -202,17 +204,18 @@ public class SetSingleNodeAllocateStepTests extends AbstractStepTestCase<SetSing
assertNoValidNode(indexMetaData, index, nodes); assertNoValidNode(indexMetaData, index, nodes);
} }
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/42932")
public void testPerformActionAttrsRequestFails() { public void testPerformActionAttrsRequestFails() {
int numAttrs = randomIntBetween(1, 10); int numAttrs = randomIntBetween(1, 10);
String[][] validAttrs = new String[numAttrs][2]; Map<String, String> validAttributes = new HashMap<>();
for (int i = 0; i < numAttrs; i++) { for (int i = 0; i < numAttrs; i++) {
validAttrs[i] = new String[] { randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20) }; validAttributes.put(randomValueOtherThanMany(validAttributes::containsKey,
() -> randomAlphaOfLengthBetween(1,20)), randomAlphaOfLengthBetween(1,20));
} }
Settings.Builder indexSettings = settings(Version.CURRENT); Settings.Builder indexSettings = settings(Version.CURRENT);
for (String[] attr : validAttrs) { validAttributes.forEach((k, v) -> {
indexSettings.put(IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + attr[0], attr[1]); indexSettings.put(IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + k, v);
}
});
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(indexSettings) IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(indexSettings)
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
Index index = indexMetaData.getIndex(); Index index = indexMetaData.getIndex();
@ -224,9 +227,9 @@ public class SetSingleNodeAllocateStepTests extends AbstractStepTestCase<SetSing
String nodeId = "node_id_" + i; String nodeId = "node_id_" + i;
String nodeName = "node_" + i; String nodeName = "node_" + i;
int nodePort = 9300 + i; int nodePort = 9300 + i;
String[] nodeAttr = randomFrom(validAttrs); Map.Entry<String, String> nodeAttr = randomFrom(validAttributes.entrySet());
Settings nodeSettings = Settings.builder().put(validNodeSettings).put(Node.NODE_NAME_SETTING.getKey(), nodeName) Settings nodeSettings = Settings.builder().put(validNodeSettings).put(Node.NODE_NAME_SETTING.getKey(), nodeName)
.put(Node.NODE_ATTRIBUTES.getKey() + nodeAttr[0], nodeAttr[1]).build(); .put(Node.NODE_ATTRIBUTES.getKey() + nodeAttr.getKey(), nodeAttr.getValue()).build();
nodes.add(DiscoveryNode.createLocal(nodeSettings, new TransportAddress(TransportAddress.META_ADDRESS, nodePort), nodeId)); nodes.add(DiscoveryNode.createLocal(nodeSettings, new TransportAddress(TransportAddress.META_ADDRESS, nodePort), nodeId));
validNodeIds.add(nodeId); validNodeIds.add(nodeId);
} }