From 5698f9d794be4dca01bb6c8e8f27a2aa30fe92bb Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Sun, 22 Dec 2013 10:21:07 +0100 Subject: [PATCH] Added asserts to test validation failures presence in ClusterHealthResponse response --- .../cluster/ClusterHealthResponsesTests.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/java/org/elasticsearch/cluster/ClusterHealthResponsesTests.java b/src/test/java/org/elasticsearch/cluster/ClusterHealthResponsesTests.java index 8f733c908a3..cc230daf89e 100644 --- a/src/test/java/org/elasticsearch/cluster/ClusterHealthResponsesTests.java +++ b/src/test/java/org/elasticsearch/cluster/ClusterHealthResponsesTests.java @@ -29,9 +29,11 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.*; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ElasticsearchTestCase; +import org.hamcrest.Matchers; import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.empty; public class ClusterHealthResponsesTests extends ElasticsearchTestCase { @@ -45,6 +47,7 @@ public class ClusterHealthResponsesTests extends ElasticsearchTestCase { assertThat(indexHealth.getInitializingShards(), equalTo(counter.initializing)); assertThat(indexHealth.getUnassignedShards(), equalTo(counter.unassigned)); assertThat(indexHealth.getShards().size(), equalTo(indexMetaData.getNumberOfShards())); + assertThat(indexHealth.getValidationFailures(), empty()); int totalShards = 0; for (ClusterShardHealth shardHealth : indexHealth.getShards().values()) { totalShards += shardHealth.getActiveShards() + shardHealth.getInitializingShards() + shardHealth.getUnassignedShards(); @@ -168,6 +171,7 @@ public class ClusterHealthResponsesTests extends ElasticsearchTestCase { assertThat(clusterHealth.getInitializingShards(), equalTo(counter.initializing)); assertThat(clusterHealth.getRelocatingShards(), equalTo(counter.relocating)); assertThat(clusterHealth.getUnassignedShards(), equalTo(counter.unassigned)); + assertThat(clusterHealth.getValidationFailures(), empty()); } @Test @@ -189,4 +193,24 @@ public class ClusterHealthResponsesTests extends ElasticsearchTestCase { assertClusterHealth(clusterHealth, counter); } + + @Test + public void testValidations() { + IndexMetaData indexMetaData = IndexMetaData.builder("test").numberOfShards(2).numberOfReplicas(2).build(); + ShardCounter counter = new ShardCounter(); + IndexRoutingTable indexRoutingTable = genIndexRoutingTable(indexMetaData, counter); + indexMetaData = IndexMetaData.builder("test").numberOfShards(2).numberOfReplicas(3).build(); + + ClusterIndexHealth indexHealth = new ClusterIndexHealth(indexMetaData, indexRoutingTable); + assertThat(indexHealth.getValidationFailures(), Matchers.hasSize(2)); + + RoutingTable.Builder routingTable = RoutingTable.builder(); + MetaData.Builder metaData = MetaData.builder(); + metaData.put(indexMetaData, true); + routingTable.add(indexRoutingTable); + ClusterState clusterState = ClusterState.builder().metaData(metaData).routingTable(routingTable).build(); + ClusterHealthResponse clusterHealth = new ClusterHealthResponse("bla", clusterState.metaData().concreteIndices(null), clusterState); + // currently we have no cluster level validation failures as index validation issues are reported per index. + assertThat(clusterHealth.getValidationFailures(), Matchers.hasSize(0)); + } }