Update tests

This commit is contained in:
Lee Hinman 2016-04-25 12:25:06 -06:00
parent f4d688a2c4
commit 89c25c5882
4 changed files with 57 additions and 27 deletions

View File

@ -159,7 +159,9 @@ public final class ClusterAllocationExplanation implements ToXContent, Writeable
// If either we don't have allocation IDs, or they contain the store allocation id, show the allocation // If either we don't have allocation IDs, or they contain the store allocation id, show the allocation
// status // status
storeCopy = StoreCopy.AVAILABLE; storeCopy = StoreCopy.AVAILABLE;
finalExplanation = "the shard can be assigned and the node contains a valid copy of the shard data"; if (finalDecision != FinalDecision.NO) {
finalExplanation = "the shard can be assigned and the node contains a valid copy of the shard data";
}
} else { } else {
// Otherwise, this is a stale copy of the data (allocation ids don't match) // Otherwise, this is a stale copy of the data (allocation ids don't match)
storeCopy = StoreCopy.STALE; storeCopy = StoreCopy.STALE;

View File

@ -125,34 +125,46 @@ public final class ClusterAllocationExplainIT extends ESIntegTestCase {
assertThat(UnassignedInfo.Reason.INDEX_CREATED, equalTo(cae.getUnassignedInfo().getReason())); assertThat(UnassignedInfo.Reason.INDEX_CREATED, equalTo(cae.getUnassignedInfo().getReason()));
assertThat("expecting no remaining delay: " + cae.getRemainingDelayNanos(), cae.getRemainingDelayNanos(), equalTo(0L)); assertThat("expecting no remaining delay: " + cae.getRemainingDelayNanos(), cae.getRemainingDelayNanos(), equalTo(0L));
Map<DiscoveryNode, Decision> nodeToDecisions = cae.getNodeDecisions(); Map<DiscoveryNode, ClusterAllocationExplanation.NodeExplanation> explanations = cae.getNodeExplanations();
Map<DiscoveryNode, Float> nodeToWeight = cae.getNodeWeights();
Map<DiscoveryNode, IndicesShardStoresResponse.StoreStatus> nodeToStatus = cae.getNodeStoreStatus();
Float noAttrWeight = -1f; Float noAttrWeight = -1f;
Float barAttrWeight = -1f; Float barAttrWeight = -1f;
Float fooBarAttrWeight = -1f; Float fooBarAttrWeight = -1f;
for (Map.Entry<DiscoveryNode, Decision> entry : nodeToDecisions.entrySet()) { for (Map.Entry<DiscoveryNode, ClusterAllocationExplanation.NodeExplanation> entry : explanations.entrySet()) {
DiscoveryNode node = entry.getKey(); DiscoveryNode node = entry.getKey();
String nodeName = node.getName(); String nodeName = node.getName();
Decision d = entry.getValue(); ClusterAllocationExplanation.NodeExplanation explanation = entry.getValue();
float weight = nodeToWeight.get(node); ClusterAllocationExplanation.FinalDecision finalDecision = explanation.getFinalDecision();
IndicesShardStoresResponse.StoreStatus storeStatus = nodeToStatus.get(node); String finalExplanation = explanation.getFinalExplanation();
ClusterAllocationExplanation.StoreCopy storeCopy = explanation.getStoreCopy();
Decision d = explanation.getDecision();
float weight = explanation.getWeight();
IndicesShardStoresResponse.StoreStatus storeStatus = explanation.getStoreStatus();
assertEquals(d.type(), Decision.Type.NO); assertEquals(d.type(), Decision.Type.NO);
if (noAttrNode.equals(nodeName)) { if (noAttrNode.equals(nodeName)) {
assertThat(d.toString(), containsString("node does not match index include filters [foo:\"bar\"]")); assertThat(d.toString(), containsString("node does not match index include filters [foo:\"bar\"]"));
noAttrWeight = weight; noAttrWeight = weight;
assertNull(storeStatus); assertNull(storeStatus);
assertEquals("the shard cannot be assigned because one or more allocation decider returns a 'NO' decision",
explanation.getFinalExplanation());
assertEquals(ClusterAllocationExplanation.FinalDecision.NO, finalDecision);
} else if (barAttrNode.equals(nodeName)) { } else if (barAttrNode.equals(nodeName)) {
assertThat(d.toString(), containsString("node does not match index include filters [foo:\"bar\"]")); assertThat(d.toString(), containsString("node does not match index include filters [foo:\"bar\"]"));
barAttrWeight = weight; barAttrWeight = weight;
assertNull(storeStatus); assertNull(storeStatus);
assertEquals("the shard cannot be assigned because one or more allocation decider returns a 'NO' decision",
explanation.getFinalExplanation());
assertEquals(ClusterAllocationExplanation.FinalDecision.NO, finalDecision);
} else if (fooBarAttrNode.equals(nodeName)) { } else if (fooBarAttrNode.equals(nodeName)) {
assertThat(d.toString(), containsString("the shard cannot be allocated on the same node id")); assertThat(d.toString(), containsString("the shard cannot be allocated on the same node id"));
fooBarAttrWeight = weight; fooBarAttrWeight = weight;
assertEquals(storeStatus.getAllocationStatus(), assertEquals(storeStatus.getAllocationStatus(),
IndicesShardStoresResponse.StoreStatus.AllocationStatus.PRIMARY); IndicesShardStoresResponse.StoreStatus.AllocationStatus.PRIMARY);
assertEquals(ClusterAllocationExplanation.FinalDecision.NO, finalDecision);
assertEquals(ClusterAllocationExplanation.StoreCopy.AVAILABLE, storeCopy);
assertEquals("the shard cannot be assigned because one or more allocation decider returns a 'NO' decision",
explanation.getFinalExplanation());
} else { } else {
fail("unexpected node with name: " + nodeName + fail("unexpected node with name: " + nodeName +
", I have: " + noAttrNode + ", " + barAttrNode + ", " + fooBarAttrNode); ", I have: " + noAttrNode + ", " + barAttrNode + ", " + fooBarAttrNode);

View File

@ -43,16 +43,22 @@ public final class ClusterAllocationExplainTests extends ESSingleNodeTestCase {
assertEquals(false, cae.isPrimary()); assertEquals(false, cae.isPrimary());
assertNull(cae.getAssignedNodeId()); assertNull(cae.getAssignedNodeId());
assertNotNull(cae.getUnassignedInfo()); assertNotNull(cae.getUnassignedInfo());
Decision d = cae.getNodeDecisions().values().iterator().next(); ClusterAllocationExplanation.NodeExplanation explanation = cae.getNodeExplanations().values().iterator().next();
ClusterAllocationExplanation.FinalDecision fd = explanation.getFinalDecision();
ClusterAllocationExplanation.StoreCopy storeCopy = explanation.getStoreCopy();
String finalExplanation = explanation.getFinalExplanation();
Decision d = explanation.getDecision();
assertNotNull("should have a decision", d); assertNotNull("should have a decision", d);
assertEquals(Decision.Type.NO, d.type()); assertEquals(Decision.Type.NO, d.type());
assertEquals(ClusterAllocationExplanation.FinalDecision.NO, fd);
assertEquals(ClusterAllocationExplanation.StoreCopy.AVAILABLE, storeCopy);
assertTrue(d.toString(), d.toString().contains("NO(the shard cannot be allocated on the same node id")); assertTrue(d.toString(), d.toString().contains("NO(the shard cannot be allocated on the same node id"));
assertTrue(d instanceof Decision.Multi); assertTrue(d instanceof Decision.Multi);
Decision.Multi md = (Decision.Multi) d; Decision.Multi md = (Decision.Multi) d;
Decision ssd = md.getDecisions().get(0); Decision ssd = md.getDecisions().get(0);
assertEquals(Decision.Type.NO, ssd.type()); assertEquals(Decision.Type.NO, ssd.type());
assertTrue(ssd.toString(), ssd.toString().contains("NO(the shard cannot be allocated on the same node id")); assertTrue(ssd.toString(), ssd.toString().contains("NO(the shard cannot be allocated on the same node id"));
Float weight = cae.getNodeWeights().values().iterator().next(); Float weight = explanation.getWeight();
assertNotNull("should have a weight", weight); assertNotNull("should have a weight", weight);
resp = client().admin().cluster().prepareAllocationExplain().setIndex("test").setShard(0).setPrimary(true).get(); resp = client().admin().cluster().prepareAllocationExplain().setIndex("test").setShard(0).setPrimary(true).get();
@ -64,16 +70,22 @@ public final class ClusterAllocationExplainTests extends ESSingleNodeTestCase {
assertEquals(true, cae.isPrimary()); assertEquals(true, cae.isPrimary());
assertNotNull("shard should have assigned node id", cae.getAssignedNodeId()); assertNotNull("shard should have assigned node id", cae.getAssignedNodeId());
assertNull("assigned shard should not have unassigned info", cae.getUnassignedInfo()); assertNull("assigned shard should not have unassigned info", cae.getUnassignedInfo());
d = cae.getNodeDecisions().values().iterator().next(); explanation = cae.getNodeExplanations().values().iterator().next();
d = explanation.getDecision();
fd = explanation.getFinalDecision();
storeCopy = explanation.getStoreCopy();
finalExplanation = explanation.getFinalExplanation();
assertNotNull("should have a decision", d); assertNotNull("should have a decision", d);
assertEquals(Decision.Type.NO, d.type()); assertEquals(Decision.Type.NO, d.type());
assertEquals(ClusterAllocationExplanation.FinalDecision.ALREADY_ASSIGNED, fd);
assertEquals(ClusterAllocationExplanation.StoreCopy.AVAILABLE, storeCopy);
assertTrue(d.toString(), d.toString().contains("NO(the shard cannot be allocated on the same node id")); assertTrue(d.toString(), d.toString().contains("NO(the shard cannot be allocated on the same node id"));
assertTrue(d instanceof Decision.Multi); assertTrue(d instanceof Decision.Multi);
md = (Decision.Multi) d; md = (Decision.Multi) d;
ssd = md.getDecisions().get(0); ssd = md.getDecisions().get(0);
assertEquals(Decision.Type.NO, ssd.type()); assertEquals(Decision.Type.NO, ssd.type());
assertTrue(ssd.toString(), ssd.toString().contains("NO(the shard cannot be allocated on the same node id")); assertTrue(ssd.toString(), ssd.toString().contains("NO(the shard cannot be allocated on the same node id"));
weight = cae.getNodeWeights().values().iterator().next(); weight = explanation.getWeight();
assertNotNull("should have a weight", weight); assertNotNull("should have a weight", weight);
resp = client().admin().cluster().prepareAllocationExplain().useAnyUnassignedShard().get(); resp = client().admin().cluster().prepareAllocationExplain().useAnyUnassignedShard().get();

View File

@ -94,21 +94,24 @@ public final class ClusterAllocationExplanationTests extends ESTestCase {
assertTrue(cae2.isAssigned()); assertTrue(cae2.isAssigned());
assertEquals("assignedNode", cae2.getAssignedNodeId()); assertEquals("assignedNode", cae2.getAssignedNodeId());
assertNull(cae2.getUnassignedInfo()); assertNull(cae2.getUnassignedInfo());
for (Map.Entry<DiscoveryNode, Decision> entry : cae2.getNodeDecisions().entrySet()) {
assertEquals(nodeToDecisions.get(entry.getKey()), entry.getValue());
}
for (Map.Entry<DiscoveryNode, IndicesShardStoresResponse.StoreStatus> entry : cae2.getNodeStoreStatus().entrySet()) {
assertEquals(nodeWithStore, entry.getKey());
IndicesShardStoresResponse.StoreStatus status = entry.getValue();
assertEquals(storeStatus.getLegacyVersion(), status.getLegacyVersion());
assertEquals(storeStatus.getAllocationId(), status.getAllocationId());
assertEquals(storeStatus.getAllocationStatus(), status.getAllocationStatus());
assertEquals(ExceptionsHelper.detailedMessage(storeStatus.getStoreException()),
ExceptionsHelper.detailedMessage(status.getStoreException()));
}
assertEquals(nodeToWeight, cae2.getNodeWeights());
assertEquals(remainingDelay, cae2.getRemainingDelayNanos()); assertEquals(remainingDelay, cae2.getRemainingDelayNanos());
assertEquals(allocationIds, cae2.getActiveAllocationIds()); assertEquals(allocationIds, cae2.getActiveAllocationIds());
for (Map.Entry<DiscoveryNode, ClusterAllocationExplanation.NodeExplanation> entry : cae2.getNodeExplanations().entrySet()) {
DiscoveryNode node = entry.getKey();
ClusterAllocationExplanation.NodeExplanation explanation = entry.getValue();
IndicesShardStoresResponse.StoreStatus status = explanation.getStoreStatus();
if (status != null) {
assertEquals(nodeWithStore, node);
assertEquals(storeStatus.getLegacyVersion(), status.getLegacyVersion());
assertEquals(storeStatus.getAllocationId(), status.getAllocationId());
assertEquals(storeStatus.getAllocationStatus(), status.getAllocationStatus());
assertEquals(ExceptionsHelper.detailedMessage(storeStatus.getStoreException()),
ExceptionsHelper.detailedMessage(status.getStoreException()));
}
assertEquals(nodeToDecisions.get(node), explanation.getDecision());
assertEquals(nodeToWeight.get(node), explanation.getWeight());
}
} }
public void testStaleShardExplanation() throws Exception { public void testStaleShardExplanation() throws Exception {
@ -136,8 +139,9 @@ public final class ClusterAllocationExplanationTests extends ESTestCase {
cae.toXContent(builder, ToXContent.EMPTY_PARAMS); cae.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertEquals("{\"shard\":{\"index\":\"test\",\"index_uuid\":\"uuid\",\"id\":0,\"primary\":true}," + assertEquals("{\"shard\":{\"index\":\"test\",\"index_uuid\":\"uuid\",\"id\":0,\"primary\":true}," +
"\"assigned\":true,\"assigned_node_id\":\"assignedNode\"," + "\"assigned\":true,\"assigned_node_id\":\"assignedNode\"," +
"\"nodes\":{\"node1\":{\"node_name\":\"\",\"node_attributes\":{},\"store\":{\"shard_copy\":\"STALE_COPY\"}," + "\"nodes\":{\"node1\":{\"node_name\":\"\",\"node_attributes\":{},\"store\":{\"shard_copy\":\"STALE\"}," +
"\"final_decision\":\"STORE_STALE\",\"weight\":1.5,\"decisions\":[{\"decider\":\"no label\",\"decision\":\"NO\"," + "\"final_decision\":\"NO\",\"final_explanation\":\"the copy of the shard is stale, allocation ids do not match\"" +
",\"weight\":1.5,\"decisions\":[{\"decider\":\"no label\",\"decision\":\"NO\"," +
"\"explanation\":\"because I said no\"},{\"decider\":\"yes label\",\"decision\":\"YES\"," + "\"explanation\":\"because I said no\"},{\"decider\":\"yes label\",\"decision\":\"YES\"," +
"\"explanation\":\"yes please\"},{\"decider\":\"throttle label\",\"decision\":\"THROTTLE\"," + "\"explanation\":\"yes please\"},{\"decider\":\"throttle label\",\"decision\":\"THROTTLE\"," +
"\"explanation\":\"wait a sec\"}]}}}", "\"explanation\":\"wait a sec\"}]}}}",