From 88d829ad7887062f7245957d0d8601e9c441f01c Mon Sep 17 00:00:00 2001 From: uboness Date: Sat, 30 Nov 2013 05:44:04 +0100 Subject: [PATCH] added more assertions to aggs tests --- .../search/aggregations/bucket/MissingTests.java | 1 + .../aggregations/metrics/ExtendedStatsTests.java | 13 +++++++++++++ .../search/aggregations/metrics/StatsTests.java | 5 +---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/MissingTests.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/MissingTests.java index c1fa4a28640..59e4e9644fb 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/MissingTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/MissingTests.java @@ -143,6 +143,7 @@ public class MissingTests extends ElasticsearchIntegrationTest { .execute().actionGet(); assertThat(response.getFailedShards(), equalTo(0)); + assertThat("Not all shards are initialized", response.getSuccessfulShards(), equalTo(response.getTotalShards())); Missing missing = response.getAggregations().get("missing_tag"); assertThat(missing, notNullValue()); diff --git a/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsTests.java b/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsTests.java index d45e9ec6e33..806bcc0f438 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; import org.junit.Test; @@ -347,6 +348,7 @@ public class ExtendedStatsTests extends AbstractNumericTests { .addAggregation(extendedStats("stats").script("doc['values'].values")) .execute().actionGet(); + assertShardExecutionState(searchResponse, 0); assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l)); ExtendedStats stats = searchResponse.getAggregations().get("stats"); @@ -385,4 +387,15 @@ public class ExtendedStatsTests extends AbstractNumericTests { assertThat(stats.getStdDeviation(), equalTo(stdDev(1, 2, 3, 4, 5, 6, 7, 8 ,9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9))); } + + private void assertShardExecutionState(SearchResponse response, int expectedFailures) throws Exception { + ShardSearchFailure[] failures = response.getShardFailures(); + if (failures.length != expectedFailures) { + for (ShardSearchFailure failure : failures) { + logger.error("Shard Failure: {}", failure.failure(), failure.toString()); + } + fail("Unexpected shard failures!"); + } + assertThat("Not all shards are initialized", response.getSuccessfulShards(), equalTo(response.getTotalShards())); + } } \ No newline at end of file diff --git a/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsTests.java b/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsTests.java index 2a488851be9..21989fbb60b 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsTests.java @@ -368,9 +368,6 @@ public class StatsTests extends AbstractNumericTests { } fail("Unexpected shard failures!"); } - int uninitializedShards = response.getTotalShards() - response.getSuccessfulShards(); - if (uninitializedShards > 0) { - logger.warn("Uninitialized shards: " + uninitializedShards); - } + assertThat("Not all shards are initialized", response.getSuccessfulShards(), equalTo(response.getTotalShards())); } } \ No newline at end of file