浏览代码

[TEST] fix node allocation result check in explain API test

Ali Beyad 8 年之前
父节点
当前提交
6f2222f8fb

+ 14 - 12
core/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainIT.java

@@ -1038,6 +1038,7 @@ public final class ClusterAllocationExplainIT extends ESIntegTestCase {
         assertBusy(() -> {
             ClusterAllocationExplanation explanation = client().admin().cluster().prepareAllocationExplain()
                 .setIndex("idx").setShard(0).setPrimary(true).get().getExplanation();
+            assertTrue(explanation.getShardAllocationDecision().getAllocateDecision().isDecisionTaken());
             assertEquals(AllocationDecision.NO_VALID_SHARD_COPY,
                 explanation.getShardAllocationDecision().getAllocateDecision().getAllocationDecision());
         });
@@ -1069,18 +1070,19 @@ public final class ClusterAllocationExplainIT extends ESIntegTestCase {
         assertFalse(moveDecision.isDecisionTaken());
         assertEquals(AllocationDecision.NO_VALID_SHARD_COPY, allocateDecision.getAllocationDecision());
         assertEquals(2, allocateDecision.getNodeDecisions().size());
-        NodeAllocationResult nodeAllocationResult = allocateDecision.getNodeDecisions().get(0);
-        assertEquals(restartedNode, nodeAllocationResult.getNode().getName());
-        assertNotNull(nodeAllocationResult.getShardStoreInfo());
-        assertNotNull(nodeAllocationResult.getShardStoreInfo().getAllocationId());
-        assertFalse(nodeAllocationResult.getShardStoreInfo().isInSync());
-        assertNull(nodeAllocationResult.getShardStoreInfo().getStoreException());
-        nodeAllocationResult = allocateDecision.getNodeDecisions().get(1);
-        assertEquals(masterNode, nodeAllocationResult.getNode().getName());
-        assertNotNull(nodeAllocationResult.getShardStoreInfo());
-        assertNull(nodeAllocationResult.getShardStoreInfo().getAllocationId());
-        assertFalse(nodeAllocationResult.getShardStoreInfo().isInSync());
-        assertNull(nodeAllocationResult.getShardStoreInfo().getStoreException());
+        for (NodeAllocationResult nodeAllocationResult : allocateDecision.getNodeDecisions()) {
+            if (nodeAllocationResult.getNode().getName().equals(restartedNode)) {
+                assertNotNull(nodeAllocationResult.getShardStoreInfo());
+                assertNotNull(nodeAllocationResult.getShardStoreInfo().getAllocationId());
+                assertFalse(nodeAllocationResult.getShardStoreInfo().isInSync());
+                assertNull(nodeAllocationResult.getShardStoreInfo().getStoreException());
+            } else {
+                assertNotNull(nodeAllocationResult.getShardStoreInfo());
+                assertNull(nodeAllocationResult.getShardStoreInfo().getAllocationId());
+                assertFalse(nodeAllocationResult.getShardStoreInfo().isInSync());
+                assertNull(nodeAllocationResult.getShardStoreInfo().getStoreException());
+            }
+        }
 
         // verify JSON output
         try (XContentParser parser = getParser(explanation)) {