Browse Source

Remove hppc uses from AwarenessAllocationIT (#84736)

This commit cleanups up allocation awareness integration tests to not
use hppc.

relates #84735
Ryan Ernst 3 years ago
parent
commit
f0158e038e

+ 21 - 55
server/src/internalClusterTest/java/org/elasticsearch/cluster/allocation/AwarenessAllocationIT.java

@@ -8,8 +8,6 @@
 
 package org.elasticsearch.cluster.allocation;
 
-import com.carrotsearch.hppc.ObjectIntHashMap;
-
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
@@ -27,7 +25,9 @@ import org.elasticsearch.test.ESIntegTestCase;
 import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
 
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -95,14 +95,7 @@ public class AwarenessAllocationIT extends ESIntegTestCase {
             assertThat("Some indices not closed", notClosedIndices, empty());
 
             // verify that we have all the primaries on node3
-            ObjectIntHashMap<String> counts = new ObjectIntHashMap<>();
-            for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
-                for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
-                    for (ShardRouting shardRouting : indexShardRoutingTable) {
-                        counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
-                    }
-                }
-            }
+            Map<String, Integer> counts = computeShardCounts(clusterState);
             assertThat(counts.get(node3), equalTo(totalPrimaries));
         }, 10, TimeUnit.SECONDS);
     }
@@ -151,15 +144,8 @@ public class AwarenessAllocationIT extends ESIntegTestCase {
         assertThat(health.isTimedOut(), equalTo(false));
 
         ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
-        ObjectIntHashMap<String> counts = new ObjectIntHashMap<>();
+        Map<String, Integer> counts = computeShardCounts(clusterState);
 
-        for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
-            for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
-                for (ShardRouting shardRouting : indexShardRoutingTable) {
-                    counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
-                }
-            }
-        }
         assertThat(counts.get(A_1), anyOf(equalTo(2), equalTo(3)));
         assertThat(counts.get(B_1), anyOf(equalTo(2), equalTo(3)));
         assertThat(counts.get(A_0), anyOf(equalTo(2), equalTo(3)));
@@ -201,15 +187,8 @@ public class AwarenessAllocationIT extends ESIntegTestCase {
             .actionGet();
         assertThat(health.isTimedOut(), equalTo(false));
         ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
-        ObjectIntHashMap<String> counts = new ObjectIntHashMap<>();
+        Map<String, Integer> counts = computeShardCounts(clusterState);
 
-        for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
-            for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
-                for (ShardRouting shardRouting : indexShardRoutingTable) {
-                    counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
-                }
-            }
-        }
         assertThat(counts.get(A_0), equalTo(5));
         assertThat(counts.get(B_0), equalTo(5));
         logger.info("--> starting another node in zone 'b'");
@@ -240,16 +219,8 @@ public class AwarenessAllocationIT extends ESIntegTestCase {
 
         assertThat(health.isTimedOut(), equalTo(false));
         clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
+        counts = computeShardCounts(clusterState);
 
-        counts = new ObjectIntHashMap<>();
-
-        for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
-            for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
-                for (ShardRouting shardRouting : indexShardRoutingTable) {
-                    counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
-                }
-            }
-        }
         assertThat(counts.get(A_0), equalTo(5));
         assertThat(counts.get(B_0), equalTo(3));
         assertThat(counts.get(B_1), equalTo(2));
@@ -280,16 +251,7 @@ public class AwarenessAllocationIT extends ESIntegTestCase {
 
         assertThat(health.isTimedOut(), equalTo(false));
         clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
-
-        counts = new ObjectIntHashMap<>();
-
-        for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
-            for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
-                for (ShardRouting shardRouting : indexShardRoutingTable) {
-                    counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
-                }
-            }
-        }
+        counts = computeShardCounts(clusterState);
 
         assertThat(counts.get(A_0), equalTo(5));
         assertThat(counts.get(B_0), equalTo(3));
@@ -315,16 +277,7 @@ public class AwarenessAllocationIT extends ESIntegTestCase {
 
         assertThat(health.isTimedOut(), equalTo(false));
         clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
-
-        counts = new ObjectIntHashMap<>();
-
-        for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
-            for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
-                for (ShardRouting shardRouting : indexShardRoutingTable) {
-                    counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
-                }
-            }
-        }
+        counts = computeShardCounts(clusterState);
 
         assertThat(counts.get(A_0), equalTo(3));
         assertThat(counts.get(B_0), equalTo(3));
@@ -371,4 +324,17 @@ public class AwarenessAllocationIT extends ESIntegTestCase {
             containsString("[cluster.routing.allocation.awareness.force.attr.values.junk]")
         );
     }
+
+    Map<String, Integer> computeShardCounts(ClusterState clusterState) {
+        Map<String, Integer> counts = new HashMap<>();
+
+        for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
+            for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
+                for (ShardRouting shardRouting : indexShardRoutingTable) {
+                    counts.merge(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1, Integer::sum);
+                }
+            }
+        }
+        return counts;
+    }
 }