mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-09 22:45:04 +00:00
added assertions for shard failures in stats agg tests
This commit is contained in:
parent
ed01d53506
commit
efea1298cd
@ -20,6 +20,7 @@
|
|||||||
package org.elasticsearch.search.aggregations.metrics;
|
package org.elasticsearch.search.aggregations.metrics;
|
||||||
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
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.bucket.histogram.Histogram;
|
||||||
import org.elasticsearch.search.aggregations.metrics.stats.Stats;
|
import org.elasticsearch.search.aggregations.metrics.stats.Stats;
|
||||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||||
@ -43,6 +44,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(histogram("histo").field("value").interval(1l).emptyBuckets(true).subAggregation(stats("stats")))
|
.addAggregation(histogram("histo").field("value").interval(1l).emptyBuckets(true).subAggregation(stats("stats")))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2l));
|
||||||
Histogram histo = searchResponse.getAggregations().get("histo");
|
Histogram histo = searchResponse.getAggregations().get("histo");
|
||||||
assertThat(histo, notNullValue());
|
assertThat(histo, notNullValue());
|
||||||
@ -68,6 +71,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").field("value"))
|
.addAggregation(stats("stats").field("value"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(0l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(0l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -87,6 +92,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").field("value"))
|
.addAggregation(stats("stats").field("value"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -106,6 +113,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").field("value"))
|
.addAggregation(stats("stats").field("value"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -125,6 +134,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").field("value").script("_value + 1"))
|
.addAggregation(stats("stats").field("value").script("_value + 1"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -144,6 +155,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").field("value").script("_value + inc").param("inc", 1))
|
.addAggregation(stats("stats").field("value").script("_value + inc").param("inc", 1))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -163,6 +176,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").field("values"))
|
.addAggregation(stats("stats").field("values"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -182,6 +197,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").field("values").script("_value - 1"))
|
.addAggregation(stats("stats").field("values").script("_value - 1"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -201,6 +218,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").field("values").script("_value - dec").param("dec", 1))
|
.addAggregation(stats("stats").field("values").script("_value - dec").param("dec", 1))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -220,6 +239,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").script("doc['value'].value"))
|
.addAggregation(stats("stats").script("doc['value'].value"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -239,6 +260,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").script("doc['value'].value + inc").param("inc", 1))
|
.addAggregation(stats("stats").script("doc['value'].value + inc").param("inc", 1))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -259,6 +282,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").script("doc['value'].value + inc").param("inc", 1))
|
.addAggregation(stats("stats").script("doc['value'].value + inc").param("inc", 1))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -278,6 +303,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").script("doc['values'].values"))
|
.addAggregation(stats("stats").script("doc['values'].values"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -297,6 +324,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").script("doc['values'].values"))
|
.addAggregation(stats("stats").script("doc['values'].values"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -316,6 +345,8 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
.addAggregation(stats("stats").script("new double[] { doc['value'].value, doc['value'].value - dec }").param("dec", 1))
|
.addAggregation(stats("stats").script("new double[] { doc['value'].value, doc['value'].value - dec }").param("dec", 1))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertShardExecutionState(searchResponse, 0);
|
||||||
|
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(10l));
|
||||||
|
|
||||||
Stats stats = searchResponse.getAggregations().get("stats");
|
Stats stats = searchResponse.getAggregations().get("stats");
|
||||||
@ -328,4 +359,18 @@ public class StatsTests extends AbstractNumericTests {
|
|||||||
assertThat(stats.getCount(), equalTo(20l));
|
assertThat(stats.getCount(), equalTo(20l));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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!");
|
||||||
|
}
|
||||||
|
int uninitializedShards = response.getTotalShards() - response.getSuccessfulShards();
|
||||||
|
if (uninitializedShards > 0) {
|
||||||
|
logger.warn("Uninitialized shards: " + uninitializedShards);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user