Skip to content

Commit

Permalink
Added asserts to test validation failures presence in ClusterHealthRe…
Browse files Browse the repository at this point in the history
…sponse response
  • Loading branch information
bleskes committed Dec 22, 2013
1 parent 0468956 commit 33103b8
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
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 {

Expand All @@ -45,6 +47,7 @@ private void assertIndexHealth(ClusterIndexHealth indexHealth, ShardCounter coun
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();
Expand Down Expand Up @@ -168,6 +171,7 @@ private void assertClusterHealth(ClusterHealthResponse clusterHealth, ShardCount
assertThat(clusterHealth.getInitializingShards(), equalTo(counter.initializing));
assertThat(clusterHealth.getRelocatingShards(), equalTo(counter.relocating));
assertThat(clusterHealth.getUnassignedShards(), equalTo(counter.unassigned));
assertThat(clusterHealth.getValidationFailures(), empty());
}

@Test
Expand All @@ -189,4 +193,24 @@ public void testClusterHealth() {

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));
}
}

0 comments on commit 33103b8

Please sign in to comment.